You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get content from several different mdsvex collections in my index page in a SvelteKit app. I only want to get certain content, not all content, as I am running into an issue where I am returning 2MB+ of content on the initial page load, when I only want the bare minimum for that page. Currently I'm using this function to return metadata:
exportfunctiongetMetadata(files){constslugs=getFileNames(files);constfolderslugs=getParentFolderNames(files);constposts=files;constlist=Object.values(posts);constmetadata=list.map((post,i)=>{post.metadata.titleslug=post.metadata.title.replace(/\s+/g,'-').toLowerCase();post.metadata.slug=slugs[i];post.metadata.folderslug=folderslugs[i];// if (post.metadata.status === `featured`) {// return post.metadata// }returnpost.metadata});// console.log(metadata)// if (metadata.status === `featured`) {// return metadata// }returnmetadata};
...I tried a couple of if statements in a couple places to try and return only the articles with the frontmatter field of status set to featured but that is not working...
...Is there any way I can do something like this to avoid returning too much data?
I end up getting the data in the +page.js file like so:
...where I'm grabbing stuff from a few different collections...
It was recommended to change +page.js to +page.server.js but this did not work for me as one of the metadata fields is actually populated by a Svelte component, so I cannot serialize that, if I understand correctly, as it cannot be converted into a JSON string.
Any thoughts are greatly appreciated...
I can partly mitigate the issue by not using export const prerender = true but it would be nice to be able to prerender only what is needed for the page, rather than ALL the content in every colleciton, instead of not being able to prerender it at all.
I AM able to filter in the +page.js file itself using a simple {#if} block, but I would rather not send the data in the first place if i do not have to, so as to keep page loads faaaaast...
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to get content from several different mdsvex collections in my index page in a SvelteKit app. I only want to get certain content, not all content, as I am running into an issue where I am returning 2MB+ of content on the initial page load, when I only want the bare minimum for that page. Currently I'm using this function to return metadata:
...I tried a couple of
if
statements in a couple places to try and return only the articles with the frontmatter field ofstatus
set tofeatured
but that is not working......Is there any way I can do something like this to avoid returning too much data?
I end up getting the data in the
+page.js
file like so:...where I'm grabbing stuff from a few different collections...
It was recommended to change
+page.js
to+page.server.js
but this did not work for me as one of the metadata fields is actually populated by a Svelte component, so I cannot serialize that, if I understand correctly, as it cannot be converted into a JSON string.Any thoughts are greatly appreciated...
I can partly mitigate the issue by not using
export const prerender = true
but it would be nice to be able to prerender only what is needed for the page, rather than ALL the content in every colleciton, instead of not being able to prerender it at all.I AM able to filter in the
+page.js
file itself using a simple{#if}
block, but I would rather not send the data in the first place if i do not have to, so as to keep page loads faaaaast...Beta Was this translation helpful? Give feedback.
All reactions