Skip to content

Commit

Permalink
Add all extra pages slugs to static builds
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Dec 27, 2024
1 parent 460c7e9 commit 88ca2bf
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions functions/ssr/src/pages/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ try {
}
export async function getStaticPaths() {
const paths: Array<{ params: { slug?: string } }> = [{
params: { slug: undefined },
}];
const paths: Array<{ params: { slug?: string } }> = [
{ params: { slug: undefined } },
];
const pageSlugs = await getConfig().getContent('extra-pages/');
pageSlugs.forEach((_slug) => {
paths.push({ params: { slug: `p/${_slug}` } });
});
if (!import.meta.env.BUILD_MINIMAL) {
paths.push({ params: { slug: 's/' } });
const {
data: { result: products },
} = await api.get('products?fields=slug&sort=-sales&limit=2');
} = await api.get('products?fields=slug&sort=-sales&limit=1');
products.forEach(({ slug }) => {
if (slug) paths.push({ params: { slug } });
});
Expand All @@ -51,13 +56,10 @@ export async function getStaticPaths() {
categories.forEach(({ slug }) => {
if (slug) paths.push({ params: { slug } });
});
const pageSlugs = await getConfig().getContent('extra-pages/');
const postSlugs = await getConfig().getContent('blog/');
pageSlugs.slice(0, 2).map((slug) => `p/${slug}`)
.concat(postSlugs.slice(0, 2).map((slug) => `posts/${slug}`))
.forEach((slug) => {
paths.push({ params: { slug } });
});
postSlugs.forEach((_slug) => {
paths.push({ params: { slug: `posts/${_slug}` } });
});
}
return paths;
}
Expand Down

0 comments on commit 88ca2bf

Please sign in to comment.