-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,53 @@ | ||
import pagePaths from "../../../../data/page_paths.json"; | ||
import { getGuide, getPageIdFromSlugs } from "../../../build-data"; | ||
import { compilePage } from "@component/page-compiler/compilePage"; | ||
import { ReactNode } from "react"; // Return a list of `params` to populate the [slug] dynamic segment | ||
import { ReactElement } from "react"; | ||
import { Metadata, ResolvingMetadata } from "next"; // Return a list of `params` to populate the [slug] dynamic segment | ||
|
||
// Return a list of `params` to populate the [slug] dynamic segment | ||
export async function generateStaticParams() { | ||
return pagePaths; | ||
} | ||
|
||
function getTextContent(elem: ReactElement | string): string { | ||
if (typeof elem === "string") { | ||
return elem; | ||
} else if (!elem.props) { | ||
return ""; | ||
} | ||
|
||
const { children } = elem.props; | ||
if (typeof children === "string") { | ||
return children; | ||
} else if (Array.isArray(children)) { | ||
return children.map(getTextContent).join(""); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
export async function generateMetadata({ | ||
params: { pagePath, versionSlug }, | ||
}: any): Promise<Metadata> { | ||
const guide = await getGuide(versionSlug); | ||
const pageId = await getPageIdFromSlugs(versionSlug, pagePath); | ||
const page = guide.getPage(pageId); | ||
const { title } = compilePage(guide, pageId, page); | ||
|
||
if (title) { | ||
return { | ||
title: | ||
getTextContent(title) + " - AE2 Players Guide for " + guide.gameVersion, | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
} | ||
|
||
export default async function Page({ params: { pagePath, versionSlug } }: any) { | ||
const guide = await getGuide(versionSlug); | ||
const pageId = await getPageIdFromSlugs(versionSlug, pagePath); | ||
const page = guide.getPage(pageId); | ||
const { title, content } = compilePage(guide, pageId, page); | ||
const { content } = compilePage(guide, pageId, page); | ||
return <>{content}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters