Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Jan 25, 2024
1 parent 731c947 commit 4bc49fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
23 changes: 7 additions & 16 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,40 @@ export const revalidate = false;
export const dynamic = 'force-static';

const Page = async ({params}: PageProps) => {
console.log('Page', 1);
const draftMode = isDraftMode();
const path = getPathFromContext({params})
console.log(2, path);

const valid = await pathIsValid(path);
// When in draft mode, the user may be on an unpublished page. Don't check validity.
if (!valid) notFound();
console.log('Page', 3);

const {redirect: redirectPath, entity} = await getEntityFromPath<NodeUnion>(path, draftMode)
console.log('Page', 4)

if (redirectPath?.url) redirect(redirectPath.url)
console.log('Page', 5);
if (!entity) notFound();
console.log('Page', 6);

return (
<NodePage node={entity}/>
)
}

export const generateMetadata = async ({params}: PageProps): Promise<Metadata> => {
console.log('generateMetadata1')
// If the user is in draft mode, there's no need to emit any customized metadata.
if (isDraftMode()) return {};
console.log('generateMetadata2')

const path = getPathFromContext({params})
const allPaths = await getAllDrupalPaths();
if (!allPaths.get('node')?.includes(path)) return {}
console.log('generateMetadata3')

const {entity} = await getEntityFromPath<NodeUnion>(path, isDraftMode())
return entity ? getNodeMetadata(entity) : {};
}

export const generateStaticParams = async (): Promise<Params[]> => {
console.log('generateStaticParams', 1);
if (process.env.BUILD_COMPLETE !== 'true') return []
console.log('generateStaticParams', 2);
const nodePaths = await getNodePaths();
if (nodePaths) {
return nodePaths.filter(path => path !== '/')
.map(path => ({slug: path.replace(/^\//, '').split('/')}))
}
console.log('generateStaticParams', 3);
if (nodePaths) return nodePaths.filter(path => path !== '/')
.map(path => ({slug: path.replace(/^\//, '').split('/')}))
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/drupal/get-paths.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const pathIsValid = async (path: string): Promise<boolean> => {
allPaths.forEach(typePaths => {
if (typePaths.includes(path)) isValid = true;
})
console.log(`valid path ${path}`, isValid);
return true;
return isValid;
}

Expand Down

0 comments on commit 4bc49fd

Please sign in to comment.