Skip to content

Commit

Permalink
fix generateStaticParams
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Sep 29, 2023
1 parent ca3bc27 commit 2435c66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
16 changes: 7 additions & 9 deletions app/[domain]/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,20 @@ export async function generateStaticParams() {
},
});

return allPosts
const allPaths = allPosts
.flatMap(({ site, slug }) => [
site?.subdomain && {
params: {
domain: site.subdomain,
slug,
},
domain: site.subdomain,
slug,
},
site?.customDomain && {
params: {
domain: site.customDomain,
slug,
},
domain: site.customDomain,
slug,
},
])
.filter(Boolean);

return allPaths;
}

export default async function SitePostPage({
Expand Down
41 changes: 16 additions & 25 deletions app/[domain]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@ import { getPostsForSite, getSiteData } from "@/lib/fetchers";
import Image from "next/image";

export async function generateStaticParams() {
const [subdomains, customDomains] = await Promise.all([
prisma.site.findMany({
select: {
subdomain: true,
},
}),
prisma.site.findMany({
where: {
NOT: {
customDomain: null,
},
const allSites = await prisma.site.findMany({
select: {
subdomain: true,
customDomain: true,
},
});

const allPaths = allSites
.flatMap(({ subdomain, customDomain }) => [
subdomain && {
domain: subdomain,
},
select: {
customDomain: true,
customDomain && {
domain: customDomain,
},
}),
]);

const allPaths = [
...subdomains.map(({ subdomain }) => subdomain),
...customDomains.map(({ customDomain }) => customDomain),
].filter((path) => path);
])
.filter(Boolean);

return allPaths.map((domain) => ({
params: {
domain,
},
}));
return allPaths;
}

export default async function SiteHomePage({
Expand Down

0 comments on commit 2435c66

Please sign in to comment.