-
Notifications
You must be signed in to change notification settings - Fork 1
POC: put page metadata inside +page.ts
files
#1
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
base: main
Are you sure you want to change the base?
Conversation
Hi @josecelano I've implemented changes in 737337f I could set it up with a Summary
How It Works
Important
|
Hi @grmbyrn, in this function:
I would extract a global state to avoid loading the whole metadata file each time you load a blog post. Maybe you can cache metadata in memory instead of in a static file? I mean, you can continue using the static file but cache it in memory the first time you load from the backend. If that's not possible for some reason you can extract the a function to remove that duplicate code in all pages. |
Hi @josecelano in this commit 66449bd I updated the implementation to cache metadata in memory while still using the static file as the source. Now, the metadata is loaded once and stored globally, preventing unnecessary file reads on each request. Additionally, I’ve extracted the metadata loading logic into a separate function ( |
Relates to: torrust/torrust-website#141
Hi @grmbyrn as we discussed in the last weekly meeting @da2ce7 and I agreed on trying to put the metadata and the page together instead of having a global array for the metadata. That would make it easier to add new pages.
ChatGPT has implemented this proof of concept. The code is very bad (a lot of duplication and other things) but that the main idea.
This is a sample page
src/routes/blog/how-to-contribute-to-this-site/+page.ts
As you can see now the metadata is inside the
+page.ts
. We can use ametadata.ts
ormetadata.json
files if you prefer to keep it decoupled from Svelte.The code can be improved significantly. I guess the most obvious improvement is to use a cache for the
getAllPostsMetadata
. The content is static. We only need to do it once.We can only try to do it at build time for production. We can generate the global json and put it somewhere. And then we just need to load that file. I guess that can be a later improvement. We don't have many blog posts yet.