Skip to content

Commit e162ca4

Browse files
committed
Try fix images
1 parent 065a112 commit e162ca4

File tree

8 files changed

+30
-26
lines changed

8 files changed

+30
-26
lines changed

components/Icon.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/* eslint-disable @next/next/no-img-element */
22
import Image from "next/image"
3-
import { SmallArtifact, SmallChar, SmallEnemy, SmallThing, SmallWeapon } from "../utils/types"
4-
import { elements, getStarColor, image, urlify, weapons } from "../utils/utils"
5-
import FormattedLink from "./FormattedLink"
63
import styles from "../pages/style.module.css"
4+
import { SmallArtifact, SmallChar, SmallThing, SmallWeapon } from "../utils/types"
5+
import { elements, getIconPath, getStarColor, image, urlify, weapons } from "../utils/utils"
6+
import FormattedLink from "./FormattedLink"
77

88
export default function Icon({ icon, className, loading = "lazy" }: { icon: { name: string, icon?: string }, className?: string, loading?: "eager" | "lazy" }) {
9-
const src = (icon.icon?.startsWith("img/") ? ("/" + icon.icon) : icon.icon) ?? "img/unknown.png"
9+
const src = getIconPath(icon.icon)
1010

1111
// if (src.startsWith("img"))
1212
// eslint-disable-next-line @next/next/no-img-element

pages/artifacts/[artifact].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Icon from "../../components/Icon"
77
import Main from "../../components/Main"
88
import { getArtifacts } from "../../utils/data-cache"
99
import { Arti, Artifact, Bonus } from "../../utils/types"
10-
import { clean, getGuidesFor, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils"
10+
import { clean, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils"
1111

1212
interface Props {
1313
artifact: Artifact,
@@ -24,9 +24,9 @@ export default function ArtifactWebpage({ artifact, location, guides }: Props &
2424
<meta name="twitter:card" content="summary" />
2525
<meta property="og:title" content={`${artifact.name} | Hu Tao`} />
2626
<meta property="og:description" content={`The ${artifact.name} artifact set${artifact.artis?.length ?? 0 > 0 ?
27-
` consists of ${artifact.artis?.length} pieces and is available in ${joinMulti(artifact.levels?.map(l => `${l} star`) ?? [])} variants. It also has` :
27+
` consists of ${artifact.artis?.length} pieces and is available in ${joinMulti(artifact.levels?.map(l => `${l} star`) ?? [])} variants. \nIt also has` :
2828
" has"} ${joinMulti(artifact.bonuses?.map(b => `a ${b.count} piece set bonus: "${clean(b.desc)}"`) ?? [])}.`} />
29-
{artifact.artis?.[0]?.icon && <meta property="og:image" content={artifact.artis?.[0]?.icon} />}
29+
{artifact.artis?.[0]?.icon && <meta property="og:image" content={getIconPath(artifact.artis[0].icon)} />}
3030
</Head>
3131
<h2 className="font-semibold">
3232
<FormattedLink href="/artifacts/" location={location} className="font-semibold text-lg">

pages/characters/[char].tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FullAscensionCosts } from "../../components/Tables"
1313
import YouTube from "../../components/YouTube"
1414
import { CharacterCurves, CostTemplates, getCharacterCurves, getCharacters, getCostTemplates } from "../../utils/data-cache"
1515
import { Character, CharacterFull, Constellation, CostTemplate, CurveEnum, Meta, Passive, Skill, Skills, TalentTable, TalentValue } from "../../utils/types"
16-
import { clean, elements, ElementType, getCharStatsAt, getCostsFromTemplate, getGuidesFor, getLinkToGuide, getStarColor, isFullCharacter, isValueTable, joinMulti, stat, urlify, weapons } from "../../utils/utils"
16+
import { clean, elements, ElementType, getCharStatsAt, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, image, isFullCharacter, isValueTable, joinMulti, stat, urlify, weapons } from "../../utils/utils"
1717
import styles from "../style.module.css"
1818

1919
interface Props {
@@ -35,7 +35,7 @@ export default function CharacterWebpage({ char, location, characterCurves, cost
3535
<meta name="twitter:card" content="summary" />
3636
<meta property="og:title" content={`${char.name} | Hu Tao`} />
3737
<meta property="og:description" content={getDescription(char, charElems)} />
38-
{char.icon && <meta property="og:image" content={char.icon} />}
38+
{char.icon && <meta property="og:image" content={getIconPath(char.icon)} />}
3939
</Head>
4040
<h2 className="font-semibold">
4141
<FormattedLink href="/characters/" location={location} className="font-semibold text-lg">
@@ -110,7 +110,7 @@ export default function CharacterWebpage({ char, location, characterCurves, cost
110110
}
111111

112112
function getDescription(char: Character, charElems: ("Pyro" | "Electro" | "Cryo" | "Hydro" | "Anemo" | "Geo" | "Dendro")[]): string | undefined {
113-
return `${char.name} is a ${char.star ? `${char.star} star ` : ""}${joinMulti(charElems)} ${getWeaponLine()}. ${getAscensionLine()}${getTalentLine()}${clean(char.desc)}`
113+
return `${char.name} is a ${char.star ? `${char.star} star ` : ""}${joinMulti(charElems)} ${getWeaponLine()}.\n${getAscensionLine()}${getTalentLine()}${clean(char.desc)}`.trim()
114114

115115
function getWeaponLine() {
116116
if (char.weaponType)
@@ -120,13 +120,13 @@ function getDescription(char: Character, charElems: ("Pyro" | "Electro" | "Cryo"
120120

121121
function getTalentLine() {
122122
if (char.skills && getTalentCosts(char.skills).length > 0)
123-
return `Uses ${joinMulti(getTalentCosts(char.skills))} for talents. `
123+
return `Uses ${joinMulti(getTalentCosts(char.skills))} for talents. \n`
124124
return ""
125125
}
126126

127127
function getAscensionLine() {
128128
if (char.ascensionCosts)
129-
return `Uses ${joinMulti(getAscensionCosts(char.ascensionCosts))} for ascensions. `
129+
return `Uses ${joinMulti(getAscensionCosts(char.ascensionCosts))} for ascensions. \n`
130130
return ""
131131
}
132132
}

pages/enemies/[enemy].tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Icon from "../../components/Icon"
88
import Main from "../../components/Main"
99
import { getEnemies } from "../../utils/data-cache"
1010
import { Enemy } from "../../utils/types"
11-
import { elements, getGuidesFor, getLinkToGuide, getStarColor, urlify } from "../../utils/utils"
11+
import { elements, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, urlify } from "../../utils/utils"
1212
import styles from "../style.module.css"
1313

1414
interface Props {
@@ -26,7 +26,7 @@ export default function EnemyWebpage({ enemy, location, guides }: Props & { loca
2626
<meta name="twitter:card" content="summary" />
2727
<meta property="og:title" content={`${enemy.name} | Hu Tao`} />
2828
<meta property="og:description" content={`${enemy.name}${enemy.type ? ` (${enemy.type})` : ""}${enemy.kind ? ` is a ${enemy.kind}` : " is an enemy"} in Genshin Impact.${enemy.resistance ? " Click to find out their resistances!" : ""}`} />
29-
{enemy.icon && <meta property="og:image" content={enemy.icon} />}
29+
{enemy.icon && <meta property="og:image" content={getIconPath(enemy.icon)} />}
3030
</Head>
3131
<h2 className="font-semibold">
3232
<FormattedLink href="/enemies/" location={location} className="font-semibold text-lg">

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Main from "../../../components/Main"
66
import YouTube from "../../../components/YouTube"
77
import { getGuides } from "../../../utils/data-cache"
88
import { Guide } from "../../../utils/types"
9-
import { clean, removeBrackets, urlify } from "../../../utils/utils"
9+
import { clean, getIconPath, removeBrackets, urlify } from "../../../utils/utils"
1010
import styles from "../../style.module.css"
1111

1212
interface Props {
@@ -25,8 +25,8 @@ export default function GuideWebpage({ guide, pageNumber, location }: Props & {
2525
<title>{page.name} | Hu Tao</title>
2626
<meta name="twitter:card" content={page.img ? "summary_large_image" : "summary"} />
2727
<meta property="og:title" content={`${page.name} | Hu Tao`} />
28-
<meta property="og:description" content={`View ${page.name} guide by ${page.credits}${page.url && page.url.startsWith("https://youtu.be/") ? " (video available!)" : ""}. ${page.desc ? clean(page.desc) : ""}`} />
29-
{page.img && <meta property="og:image" content={page.img} />}
28+
<meta property="og:description" content={`View ${page.name} guide by ${page.credits}${page.url && page.url.startsWith("https://youtu.be/") ? " (video available!)" : ""}. \n${page.desc ? clean(page.desc) : ""}`.trim()} />
29+
{page.img && <meta property="og:image" content={getIconPath(page.img)} />}
3030
</Head>
3131
<h2 className="font-semibold">
3232
<FormattedLink href={`/guides/${urlify(guide.name, false)}`} location={location} className="font-semibold text-lg">

pages/materials/[material].tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Icon, { SmallIcon } from "../../components/Icon"
88
import Main from "../../components/Main"
99
import { CostTemplates, getCharacters, getCostTemplates, getMaterials, getWeapons } from "../../utils/data-cache"
1010
import { Cost, CostTemplate, Material, SmallChar, SmallWeapon } from "../../utils/types"
11-
import { clean, createSmallChar, createSmallWeapon, getCostsFromTemplate, getGuidesFor, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils"
11+
import { clean, createSmallChar, createSmallWeapon, getCostsFromTemplate, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, joinMulti, urlify } from "../../utils/utils"
1212

1313
interface Props {
1414
mat: Material,
@@ -40,8 +40,8 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
4040
<title>{mat.name} | Hu Tao</title>
4141
<meta name="twitter:card" content="summary" />
4242
<meta property="og:title" content={`${mat.name} | Hu Tao`} />
43-
<meta property="og:description" content={`${mat.name} is a ${mat.stars ? `${mat.stars} star ` : ""}${mat.type}. ${usedByDesc.length > 0 ? `Used by ${joinMulti(usedByDesc)}. ` : ""}${mat.desc ? clean(mat.desc ?? "") : ""}`.trim()} />
44-
{mat.icon && <meta property="og:image" content={mat.icon} />}
43+
<meta property="og:description" content={`${mat.name} is a ${mat.stars ? `${mat.stars} star ` : ""}${mat.type}. \n${usedByDesc.length > 0 ? `Used by ${joinMulti(usedByDesc)}.\n ` : ""}${mat.desc ? clean(mat.desc ?? "") : ""}`.trim()} />
44+
{mat.icon && <meta property="og:image" content={getIconPath(mat.icon)} />}
4545
</Head>
4646
<h2 className="font-semibold">
4747
<FormattedLink href="/materials/" location={location} className="font-semibold text-lg">

pages/weapons/[weapon].tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { MaterialImage } from "../../components/Material"
1010
import { FullAscensionCosts } from "../../components/Tables"
1111
import { CostTemplates, getCostTemplates, getWeaponCurves, getWeapons, WeaponCurves } from "../../utils/data-cache"
1212
import { CostTemplate, PlaceHolderStats, Refinement, StatsName, Weapon, WeaponCurveName } from "../../utils/types"
13-
import { clean, getGuidesFor, getLinkToGuide, getStarColor, getWeaponStatsAt, joinMulti, stat, urlify } from "../../utils/utils"
13+
import { clean, getGuidesFor, getIconPath, getLinkToGuide, getStarColor, getWeaponStatsAt, joinMulti, stat, urlify } from "../../utils/utils"
1414
import styles from "../style.module.css"
1515

1616
interface Props {
@@ -32,7 +32,7 @@ export default function WeaponWebpage({ weapon, weaponCurves, costTemplates, loc
3232
<meta name="twitter:card" content="summary" />
3333
<meta property="og:title" content={`${weapon.name} | Hu Tao`} />
3434
<meta property="og:description" content={getDescription(weapon, weaponCurves)} />
35-
{weapon.icon && <meta property="og:image" content={weapon.icon} />}
35+
{weapon.icon && <meta property="og:image" content={getIconPath(weapon.icon)} />}
3636
</Head>
3737
<h2 className="font-semibold">
3838
<FormattedLink href="/weapons/" location={location} className="font-semibold text-lg">
@@ -90,11 +90,11 @@ export default function WeaponWebpage({ weapon, weaponCurves, costTemplates, loc
9090
}
9191

9292
function getDescription(weapon: Weapon, weaponCurves: WeaponCurves | null): string | undefined {
93-
return `${weapon.name} is a ${weapon.stars ? `${weapon.stars} star ` : ""}${weapon.weaponType}. ${getAscensionCostsLine()}${getPlaceholderStatsLine()}${getStatsLineFromAsc()}${getRefinementLine()}`
93+
return `${weapon.name} is a ${weapon.stars ? `${weapon.stars} star ` : ""}${weapon.weaponType}. \n{getAscensionCostsLine()}${getPlaceholderStatsLine()}${getStatsLineFromAsc()}${getRefinementLine()}`.trim()
9494

9595
function getRefinementLine() {
9696
if (weapon.refinements && weapon.refinements.length > 0)
97-
return `Refinement ${weapon.refinements[0].name} Lv. 1: ${clean(weapon.refinements[0].desc)}`
97+
return `Refinement ${weapon.refinements[0].name} Lv. 1: ${clean(weapon.refinements[0].desc)}\n`
9898
}
9999
function getStatsLineFromAsc() {
100100
if (weapon.ascensions && weapon.weaponCurve && weaponCurves)
@@ -113,12 +113,12 @@ function getDescription(weapon: Weapon, weaponCurves: WeaponCurves | null): stri
113113

114114
function getAscensionCostsLine() {
115115
if (weapon.ascensionCosts)
116-
return `Uses ${joinMulti(getAscensionCosts(weapon.ascensionCosts))} for ascensions. `
116+
return `Uses ${joinMulti(getAscensionCosts(weapon.ascensionCosts))} for ascensions. \n`
117117
return ""
118118
}
119119

120120
function getStatsLine(level: number, stats: Partial<Record<StatsName, number>>) {
121-
return `Stats at level ${level}: ${joinMulti(Object.entries(stats).map(([name, value]) => `${name}: ${stat(name, value)}`))}. `
121+
return `Stats at level ${level}: ${joinMulti(Object.entries(stats).map(([name, value]) => `${name}: ${stat(name, value)}`))}. \n`
122122
}
123123
}
124124

utils/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export function image(type: string, name: string, ext="png"): string {
103103
return `/img/${type}/${name.replace(/[:\-,'"]/g, "").replace(/ +/g, "_")}.${ext}`
104104
}
105105

106+
export function getIconPath(icon?: string) {
107+
return (icon?.startsWith("img/") ? ("/" + icon) : icon) ?? "/img/unknown.png"
108+
}
109+
106110
export function getCostsFromTemplate(costTemplate: CostTemplate, costTemplates: Record<string, Cost[]>): Cost[] {
107111
const template = costTemplates[costTemplate.template]
108112

0 commit comments

Comments
 (0)