|
| 1 | +import { GetStaticPathsResult, GetStaticPropsContext, GetStaticPropsResult } from "next" |
| 2 | +import Head from "next/head" |
| 3 | +import ReactMarkdown from "react-markdown" |
| 4 | +import FormattedLink from "../../components/FormattedLink" |
| 5 | +import Guides from "../../components/Guides" |
| 6 | +import Icon from "../../components/Icon" |
| 7 | +import Main from "../../components/Main" |
| 8 | +import { getArtifacts } from "../../utils/data-cache" |
| 9 | +import { Arti, Artifact, Bonus } from "../../utils/types" |
| 10 | +import { getGuidesFor, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils" |
| 11 | + |
| 12 | +interface Props { |
| 13 | + artifact: Artifact, |
| 14 | + guides?: string[][], |
| 15 | +} |
| 16 | + |
| 17 | +export default function ArtifactWebpage({ artifact, location, guides }: Props & { location: string }) { |
| 18 | + const color = getStarColor(Math.max(...(artifact.levels ?? [1]))) |
| 19 | + |
| 20 | + return ( |
| 21 | + <Main> |
| 22 | + <Head> |
| 23 | + <title>{artifact.name} | Hu Tao</title> |
| 24 | + <meta name="twitter:card" content="summary" /> |
| 25 | + <meta property="og:title" content={`${artifact.name} | Hu Tao`} /> |
| 26 | + <meta property="og:description" content={`View ${artifact.name} information`} /> |
| 27 | + </Head> |
| 28 | + <h2 className="font-semibold"> |
| 29 | + <FormattedLink href="/artifacts/" location={location} className="font-semibold text-lg"> |
| 30 | + Artifacts |
| 31 | + </FormattedLink> |
| 32 | + </h2> |
| 33 | + |
| 34 | + <h1 className="text-4xl font-bold pb-2 sm:sr-only not-sr-only"> |
| 35 | + <Icon icon={{ name: artifact.name, icon: artifact.artis?.[0]?.icon }} className={`${color} rounded-xl sm:w-0 mr-2 w-12 inline-block`} /> |
| 36 | + {artifact.name} |
| 37 | + </h1> |
| 38 | + |
| 39 | + <div className="grid grid-flow-col justify-start"> |
| 40 | + <div className="sm:w-36 mr-2 w-0 "> |
| 41 | + <Icon icon={{ name: artifact.name, icon: artifact.artis?.[0]?.icon }} className={`${color} rounded-xl`} /> |
| 42 | + </div> |
| 43 | + |
| 44 | + <div id="description" className="w-full"> |
| 45 | + <h1 className="text-4xl font-bold pb-2 sm:not-sr-only sr-only"> |
| 46 | + {artifact.name} |
| 47 | + </h1> |
| 48 | + |
| 49 | + {artifact.levels && <div className="inline-block pr-2"> |
| 50 | + Available in {joinMulti(artifact.levels.map(l => `${l}★`))} |
| 51 | + </div>} |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div id="details"> |
| 56 | + {guides && guides.length > 0 && <Guides guides={guides} />} |
| 57 | + {artifact.bonuses && artifact.bonuses.length > 0 && <Bonuses bonuses={artifact.bonuses} />} |
| 58 | + {artifact.artis && artifact.artis.length > 0 && <Artis artis={artifact.artis} />} |
| 59 | + |
| 60 | + </div> |
| 61 | + </Main> |
| 62 | + ) |
| 63 | +} |
| 64 | + |
| 65 | +function Bonuses({ bonuses }: { bonuses: Bonus[] }) { |
| 66 | + return <> |
| 67 | + <h3 className="text-lg font-bold pt-1" id="bonuses">Bonuses:</h3> |
| 68 | + {bonuses.map(bonus => <div key={bonus.count} className="py-2"> |
| 69 | + <div className="font-semibold">{bonus.count}-Piece Set Bonus</div> |
| 70 | + {bonus.desc} |
| 71 | + </div>)} |
| 72 | + </> |
| 73 | +} |
| 74 | + |
| 75 | +function Artis({ artis }: { artis: Arti[] }) { |
| 76 | + return <> |
| 77 | + <h3 className="text-lg font-bold pt-1" id="artis">Pieces:</h3> |
| 78 | + {artis.map(arti => |
| 79 | + <div key={arti.type} className="border p-1 rounded-xl mb-2 border-opacity-75"> |
| 80 | + <div className="flex flex-row items-center" id={urlify(arti.name, false)}> |
| 81 | + {arti.icon && <Icon icon={arti} className="rounded-full w-16 h-16 mr-2 " />} |
| 82 | + <div className="font-bold">{arti.name}</div> |
| 83 | + </div> |
| 84 | + <div className="flex flex-col pb-1 pl-1"> |
| 85 | + <ReactMarkdown>{(arti.desc?.replace(/ ?\$\{.*?\}/g, "").replace(/\n/g, "\n\n") ?? "")}</ReactMarkdown> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + )} |
| 89 | + </> |
| 90 | +} |
| 91 | + |
| 92 | +export async function getStaticProps(context: GetStaticPropsContext): Promise<GetStaticPropsResult<Props>> { |
| 93 | + const artifactName = context.params?.artifact |
| 94 | + const data = await getArtifacts() |
| 95 | + |
| 96 | + const artifact = Object.values(data ?? {}).find(g => urlify(g.name, false) == artifactName) |
| 97 | + if (!data || !artifact) { |
| 98 | + return { |
| 99 | + notFound: true, |
| 100 | + revalidate: 5 * 60 |
| 101 | + } |
| 102 | + } |
| 103 | + |
| 104 | + const guides = (await getGuidesFor("artifact", artifact.name))?.map(({ guide, page }) => [page.name, getLinkToGuide(guide, page)]) |
| 105 | + |
| 106 | + return { |
| 107 | + props: { |
| 108 | + artifact, |
| 109 | + guides, |
| 110 | + }, |
| 111 | + revalidate: 60 * 60 |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +export async function getStaticPaths(): Promise<GetStaticPathsResult> { |
| 116 | + const data = await getArtifacts() |
| 117 | + return { |
| 118 | + paths: Object.values(data ?? {}).map(a => ({ |
| 119 | + params: { artifact: urlify(a.name, false) } |
| 120 | + })) ?? [], |
| 121 | + fallback: "blocking" |
| 122 | + } |
| 123 | +} |
0 commit comments