Skip to content

Commit

Permalink
chore: add titleCase util to handle url formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sbsrnt committed Mar 16, 2024
1 parent 454e0fc commit 84079e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
19 changes: 10 additions & 9 deletions packages/seo/src/meta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {DefaultSeoProps} from "next-seo";
import {titleCase} from "../src/utils";

type Description = {
directory: string | string[]
Expand Down Expand Up @@ -30,27 +31,27 @@ const metaWelcome: Meta = () => ({

const metaDirectory: Meta = ({directory}) => ({
title: `Directory`,
description: `Advance your ${directory} gameplay with exile.watch: Discover visual ability insights and GIFs designed to conquer new challenges.`,
description: `Advance your ${titleCase(directory)} gameplay with exile.watch: Discover visual ability insights and GIFs designed to conquer new challenges.`,
})

const metaEncounters: Meta = ({directory}) => ({
title: `${directory} Encounters`,
encounters: `Navigate ${directory} encounters with ease on exile.watch: Access a curated list of encounter categories for targeted visual ability insights.`
title: `${titleCase(directory)} Encounters`,
description: `Navigate ${titleCase(directory)} encounters with ease on exile.watch: Access a curated list of encounter categories for targeted visual ability insights.`
})

const metaEncountersCategories: Meta = ({directory, category}) => ({
title: `${category} - ${directory} Encounters`,
encounters: `Master the ${category} encounters in ${directory} with exile.watch: Visual ability insights and GIFs to conquer the Atlas's toughest foes.`
title: `${titleCase(category)} - ${titleCase(directory)} Encounters`,
description: `Master the ${titleCase(category)} encounters in ${titleCase(directory)} with exile.watch: Visual ability insights and GIFs to conquer the Atlas's toughest foes.`
})

const metaEncountersCategoryMaps: Meta = ({directory, category, map}) => ({
title: `${map} - ${category}, ${directory} Encounters`,
encounters: `Master ${map} encounters in ${directory} with exile.watch: Visual ability insights and GIFs for all encounters.`
title: `${titleCase(map)} - ${titleCase(category)}, ${titleCase(directory)} Encounters`,
description: `Master ${titleCase(map)} encounters in ${titleCase(directory)} with exile.watch: Visual ability insights and GIFs for all encounters.`
})

const metaEncounter: Meta = ({directory, category, encounter}) => ({
title: `${encounter} - ${category}, ${directory} Encounters`,
encounters: `Understand and conquer ${encounter} in ${directory} with exile.watch: Discover key abilities and their effects through our concise, informative GIFs.`
title: `${titleCase(encounter)} - ${titleCase(category)}, ${titleCase(directory)} Encounters`,
description: `Understand and conquer ${titleCase(encounter)} in ${titleCase(directory)} with exile.watch: Discover key abilities and their effects through our concise, informative GIFs.`
})

export {
Expand Down
18 changes: 17 additions & 1 deletion packages/seo/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,20 @@ function generateXml() {
return xml.trim();
}

export {generateXml}
function titleCase(str) {
const lowerCaseWords = ['of'];
return str
.split('-') // Split the string into an array by dashes.
.map((word, index) => {
// Check if the word should remain in lowercase, except if it's the first word.
if (lowerCaseWords.includes(word) && index !== 0) {
return word;
}
// Capitalize the first letter of the word.
return word.charAt(0).toUpperCase() + word.slice(1);
})
.join(' ') // Join the array back into a string with spaces.
.replace(/(\d+)/, ' $1'); // Ensure numbers are correctly spaced.
}

export {generateXml, titleCase}

0 comments on commit 84079e2

Please sign in to comment.