-
Notifications
You must be signed in to change notification settings - Fork 592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added API support for i18n, subpages and static field values #372
Conversation
A little backstory: I was tired of updating the category or widget components whenever adding a new product or article. Using the the following component I can load all the blog posts from the blog posts pages via the API. It does slow down deployment, probably hangs when having too many posts but it's ok for me atm. The data is fetched during deployment, not on client-side. There's no reason to spam requests to the primo server when the data change only during deployment. I am applying a 5 post pagination, ideally this should be implemented in the API. Known Bug: If you hit deploy too fast after adding a post it might not be included in the component above, give it a few seconds to be written in the database first. P.S. Yeah I know I am abusing the Javascript tab by adding a module script in there, but it works :D |
Okay I went ahead and exported the languages from primo builder and imported them
Fixed the parent url matching for sections. looks like you might have been selecting
Agreed. I don't have more bandwidth atm so we might want to merge it in as in unless you can keep working on it.
Any particular reason you want to remove them? I figured they'd be useful to target specific pages/sections by their ID (for example, to select particular sections on a page without worrying about them being moved around). |
Damn, how did I miss that...
Yes, I'll keep working on this.
Just to save bandwidth I guess as I don't use them, but they can stay if they're useful. How about sort and limit? I think I should add those as well. |
Okay, let's leave them then since they're the only way to absolutely select a page/section.
For sure! What about pagination? Love the use of the module in the JS tab lol. Does that not run again in the client though? |
Limit start,end should take care of pagination and we only need to add a total_pages value somewhere in the response. I'll do a commit tomorrow.
OMG you are right, I just assumed I worked around that using Got any trick for that? |
I think '$app/environment' only works in SvelteKit.
Yeah it looks like when it runs again in production it overwrites the statically rendered content. So I figured that we could output that data as raw json into a hidden div and then pull that instead of fetching data from the API.
Here's the full Block |
wow, you are hackier than me! some minor improvements: let blog = []
if (typeof window === 'undefined' || window.location.host === server_host || window.location.ancestorOrigins[0] === `https://${server_host}`) {
blog = await fetchPosts().catch(error => console.error('Error fetching posts:', error));
} else {
const blog_json = document.querySelector('#blog-json')
blog = JSON.parse(blog_json.innerHTML)
document.querySelector('#blog-json').remove()
} P.S. When this PR is merged I'll write a guide on this and call it "Don't Repeat Yourself", it really saves a lot of time and copy-paste errors. I wonder how I didn't try this sooner tbh... |
This isn't extensively tested, but it works. I also moved the sections sorting to the supabase query. Breaking changes for people already using the API
P.S. The API is not strictly typed. Expect errors when you pass bad parameters. |
Thanks @rallisf1! Looks great |
This is safe to merge but not final yet. I could use your help @mateomorris !
Known bugs:
Features under consideration
?format=
URL query parametersort
andlimit
URL query parameter for pagination