Skip to content

Commit

Permalink
Update descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibowl committed Jan 20, 2022
1 parent e162ca4 commit 9f6c119
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pages/artifacts/[artifact].tsx
Expand Up @@ -24,7 +24,7 @@ export default function ArtifactWebpage({ artifact, location, guides }: Props &
<meta name="twitter:card" content="summary" />
<meta property="og:title" content={`${artifact.name} | Hu Tao`} />
<meta property="og:description" content={`The ${artifact.name} artifact set${artifact.artis?.length ?? 0 > 0 ?
` consists of ${artifact.artis?.length} pieces and is available in ${joinMulti(artifact.levels?.map(l => `${l} star`) ?? [])} variants. \nIt also has` :
` consists of ${artifact.artis?.length} pieces and is available in ${joinMulti(artifact.levels?.map(l => `${l}`) ?? [])} star variants. \nIt also has` :
" has"} ${joinMulti(artifact.bonuses?.map(b => `a ${b.count} piece set bonus: "${clean(b.desc)}"`) ?? [])}.`} />
{artifact.artis?.[0]?.icon && <meta property="og:image" content={getIconPath(artifact.artis[0].icon)} />}
</Head>
Expand Down
19 changes: 16 additions & 3 deletions pages/characters/[char].tsx
Expand Up @@ -34,7 +34,7 @@ export default function CharacterWebpage({ char, location, characterCurves, cost
<title>{char.name} | Hu Tao</title>
<meta name="twitter:card" content="summary" />
<meta property="og:title" content={`${char.name} | Hu Tao`} />
<meta property="og:description" content={getDescription(char, charElems)} />
<meta property="og:description" content={getDescription(char, charElems, characterCurves)} />
{char.icon && <meta property="og:image" content={getIconPath(char.icon)} />}
</Head>
<h2 className="font-semibold">
Expand Down Expand Up @@ -109,8 +109,21 @@ export default function CharacterWebpage({ char, location, characterCurves, cost
)
}

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

function getCharStatsLine() {
if (isFullCharacter(char) && characterCurves)
return getStatsLine(
char.ascensions[char.ascensions.length - 1].maxLevel,
getCharStatsAt(char, char.ascensions[char.ascensions.length - 1].maxLevel, char.ascensions.length - 1, characterCurves)
)
return ""
}

function getStatsLine(level: number, stats: Record<string, number>) {
return `Stats at level ${level}: ${joinMulti(Object.entries(stats).map(([name, value]) => `${stat(name, value)} ${name}`))}. \n`
}

function getWeaponLine() {
if (char.weaponType)
Expand Down
10 changes: 5 additions & 5 deletions pages/materials/[material].tsx
Expand Up @@ -25,22 +25,22 @@ export default function MaterialWebpage({ mat, location, guides, usedBy }: Props
const usedByDesc = []

if (usedBy.charTalents.length > 0 && usedBy.charAscension.length > 0)
usedByDesc.push(`${joinMulti([...usedBy.charTalents, ...usedBy.charAscension].filter((v, i, a) => a.indexOf(v) == i).map(x => x.name))} character talents/ascensions`)
usedByDesc.push(`Used by ${joinMulti([...usedBy.charTalents, ...usedBy.charAscension].map(x => x.name).filter((v, i, a) => a.indexOf(v) == i))} character talents/ascensions.`)
else if (usedBy.charTalents.length > 0)
usedByDesc.push(`${joinMulti(usedBy.charTalents.map(x => x.name))} character talents`)
usedByDesc.push(`Used by ${joinMulti(usedBy.charTalents.map(x => x.name))} character talents.`)
else if (usedBy.charAscension.length > 0)
usedByDesc.push(`${joinMulti(usedBy.charAscension.map(x => x.name))} character ascensions`)
usedByDesc.push(`Used by ${joinMulti(usedBy.charAscension.map(x => x.name))} character ascensions.`)

if (usedBy.weaponAscension.length > 0)
usedByDesc.push(`${joinMulti(usedBy.weaponAscension.map(x => x.name))} weapon ascensions`)
usedByDesc.push(`Used by ${joinMulti(usedBy.weaponAscension.map(x => x.name))} weapon ascensions.`)

return (
<Main>
<Head>
<title>{mat.name} | Hu Tao</title>
<meta name="twitter:card" content="summary" />
<meta property="og:title" content={`${mat.name} | Hu Tao`} />
<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()} />
<meta property="og:description" content={`${mat.name} is a ${mat.stars ? `${mat.stars} star ` : ""}${mat.type}. \n${usedByDesc.join("\n")}\n${mat.desc ? clean(mat.desc ?? "") : ""}`.trim()} />
{mat.icon && <meta property="og:image" content={getIconPath(mat.icon)} />}
</Head>
<h2 className="font-semibold">
Expand Down
8 changes: 2 additions & 6 deletions pages/weapons/[weapon].tsx
Expand Up @@ -90,7 +90,7 @@ export default function WeaponWebpage({ weapon, weaponCurves, costTemplates, loc
}

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

function getRefinementLine() {
if (weapon.refinements && weapon.refinements.length > 0)
Expand All @@ -102,10 +102,6 @@ function getDescription(weapon: Weapon, weaponCurves: WeaponCurves | null): stri
weapon.ascensions[weapon.ascensions.length - 1].maxLevel,
getWeaponStatsAt(weapon, weapon.ascensions[weapon.ascensions.length - 1].maxLevel, weapon.ascensions.length - 1, weaponCurves)
)
return ""
}

function getPlaceholderStatsLine() {
if (weapon.placeholderStats)
return getStatsLine(weapon.placeholderStats.level, weapon.placeholderStats.stats)
return ""
Expand All @@ -118,7 +114,7 @@ function getDescription(weapon: Weapon, weaponCurves: WeaponCurves | null): stri
}

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

Expand Down

0 comments on commit 9f6c119

Please sign in to comment.