Skip to content

Commit 4bfe44b

Browse files
committed
Add images
1 parent 2b6d1e0 commit 4bfe44b

757 files changed

Lines changed: 325 additions & 78 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/NavBar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useState } from "react"
22
import FormattedLink from "./FormattedLink"
33

4-
const pages = ["Guides", "Reminders"]
4+
const pages = ["Guides", /* "Characters",*/ "Reminders"]
55

66
export default function NavBar({ location }: {location: string}) {
77
const [menuOpen, setMenuOpen] = useState(false)

components/YouTube.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default function YouTube({ vidID }: { vidID: string }) {
2+
return <div style={{
3+
position: "relative",
4+
paddingBottom: "56.25%" /* 16:9 */,
5+
paddingTop: 25,
6+
height: 0
7+
}}>
8+
<iframe
9+
style={{
10+
position: "absolute",
11+
top: 0,
12+
left: 0,
13+
width: "100%",
14+
height: "100%"
15+
}}
16+
src={`https://www.youtube.com/embed/${vidID}`}
17+
frameBorder="0"
18+
/>
19+
</div>
20+
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"react": "17.0.2",
1616
"react-dom": "17.0.2",
1717
"react-markdown": "^7.1.1",
18-
"react-youtube": "^7.14.0",
1918
"sharp": "^0.29.3"
2019
},
2120
"devDependencies": {

pages/characters/index.tsx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { GetStaticPropsContext, GetStaticPropsResult } from "next"
2+
import Head from "next/head"
3+
import Image from "next/image"
4+
import FormattedLink from "../../components/FormattedLink"
5+
import Main from "../../components/Main"
6+
import { getCharacters, urlify } from "../../utils/data-cache"
7+
import { Character, CharacterFull } from "../../utils/types"
8+
9+
import Cryo from "../../public/img/element/Cryo.png"
10+
import Anemo from "../../public/img/element/Anemo.png"
11+
import Dendro from "../../public/img/element/Dendro.png"
12+
import Geo from "../../public/img/element/Geo.png"
13+
import Electro from "../../public/img/element/Electro.png"
14+
import Hydro from "../../public/img/element/Hydro.png"
15+
import Pyro from "../../public/img/element/Pyro.png"
16+
17+
const elements = {
18+
Anemo, Cryo, Dendro, Geo, Electro, Hydro, Pyro
19+
}
20+
21+
type Element = "Anemo"
22+
23+
interface SmallChar {
24+
name: string
25+
stars?: number
26+
element?: (keyof (typeof elements))[]
27+
weapon?: string
28+
icon?: string
29+
}
30+
31+
interface Props {
32+
characters: SmallChar[]
33+
}
34+
35+
export default function Characters(props: Props & { location: string }) {
36+
return (
37+
<Main>
38+
<Head>
39+
<title>Characters | Hu Tao</title>
40+
<meta name="twitter:card" content="summary" />
41+
<meta property="og:title" content="Characters | Hu Tao" />
42+
<meta property="og:description" content="View information about different Genshin Impact characters!" />
43+
</Head>
44+
45+
<h1 className="text-5xl font-bold pb-2">
46+
Characters
47+
</h1>
48+
49+
<div className="flex flex-wrap justify-around text-center">
50+
{props.characters.map(char => (
51+
<FormattedLink key={char.name} font="semibold" size="xl" location={props.location} href={`/characters/${urlify(char.name, false)}`} >
52+
<div className="bg-slate-600 w-24 h-24 m-2">
53+
<div className="absolute w-6 m-1">
54+
{char.element && char.element.map(e => <Image src={elements[e]} key={e} alt={`${e} Element`}/>)}
55+
<Image alt={char.name} src={char.icon ?? "/img/unknown.png"} className="w-24" width={256} height={256} onError={(e) => (e.target as HTMLImageElement).src = "/img/unknown.png"}/>
56+
</div>
57+
{char.name}
58+
</div>
59+
</FormattedLink>
60+
))}
61+
</div>
62+
</Main>
63+
)
64+
}
65+
66+
function isFullCharacter(char: Character): char is CharacterFull {
67+
return typeof (char as CharacterFull).releasedOn == "string"
68+
}
69+
70+
export async function getStaticProps(context: GetStaticPropsContext): Promise<GetStaticPropsResult<Props>> {
71+
const data = await getCharacters()
72+
73+
if (!data) {
74+
return {
75+
notFound: true,
76+
revalidate: 5 * 60
77+
}
78+
}
79+
80+
return {
81+
props: {
82+
characters: Object
83+
.values(data)
84+
.sort((a, b) => {
85+
if (isFullCharacter(a) && isFullCharacter(b))
86+
return b.releasedOn.localeCompare(a.releasedOn) || b.star - a.star || a.name.localeCompare(b.name)
87+
else if (!isFullCharacter(b))
88+
return 1
89+
else if (!isFullCharacter(a))
90+
return -1
91+
else return a.name.localeCompare(b.name)
92+
})
93+
.map(c => {
94+
const char: SmallChar = { name: c.name }
95+
if (c.star) char.stars = c.star
96+
if (c.skills) char.element = c.skills.map(skill => skill.ult?.type).filter(x => x) as Element[]
97+
if (c.weaponType) char.weapon = c.weaponType
98+
if (c.icon) char.icon = c.icon
99+
return char
100+
})
101+
},
102+
revalidate: 60 * 60
103+
}
104+
}

pages/guides/[category]/[guide].tsx

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import Head from "next/head"
33
import ReactMarkdown from "react-markdown"
44
import FormattedLink from "../../../components/FormattedLink"
55
import Main from "../../../components/Main"
6+
import YouTube from "../../../components/YouTube"
67
import { getGuides, urlify, yeetBrackets } from "../../../utils/data-cache"
78
import { Guide } from "../../../utils/types"
8-
import YouTube from "react-youtube"
99
import styles from "../../style.module.css"
1010

1111
interface Props {
@@ -54,26 +54,10 @@ export default function GuideWebpage({ guide, pageNumber, location }: Props & {
5454
<div>
5555
<ReactMarkdown>{(page.desc?.replace(/ ?\$\{.*?\}/g, "") ?? "")}</ReactMarkdown>
5656
{page.img && <ExternalImg src={page.img} />}
57+
<div className="float-right text-sm">By {page.credits}</div>
5758
{page.url && page.url.startsWith("https://youtu.be/") && <div>
5859
<h2 className="text-xl font-semibold py-1">Video:</h2>
59-
<div style={{
60-
position: "relative",
61-
paddingBottom: "56.25%" /* 16:9 */,
62-
paddingTop: 25,
63-
height: 0
64-
}}>
65-
<iframe
66-
style={{
67-
position: "absolute",
68-
top: 0,
69-
left: 0,
70-
width: "100%",
71-
height: "100%"
72-
}}
73-
src={`https://www.youtube.com/embed/${page.url.replace("https://youtu.be/", "")}`}
74-
frameBorder="0"
75-
/>
76-
</div>
60+
<YouTube vidID={page.url.replace("https://youtu.be/", "")} />
7761
</div>
7862
}
7963
</div>

pnpm-lock.yaml

Lines changed: 1 addition & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
50.5 KB
37.7 KB
34.9 KB
40.7 KB

0 commit comments

Comments
 (0)