Skip to main content

Generete Sitemap.xml based on dynamic categories

  • Hardcoded categories to generate a sitemap from.

Code​

export const Categories = [
"free",
"christmas",
"halloween",
"flower",
"relief",
"trippy",
"animal",
"cute",
"disney",
"dragon",
"realistic",
"fairy",
"day",
"butterfly",
"mandala",
"anime",
"thanksgiving",
"cool",
"funny",
"winter",
"easter",
"mythical",
"summer",
"spring",
"birthday",
"horse",
"car",
"cow",
"cartoon",
"skull",
"fun",
"heart",
"abstract",
"love",
"relationship",
"mushroom",
"cat",
"hard",
"beach",
"sunflower",
"valentine",
"fall",
"fairy",
"girl",
"ocean",
"mermaid",
"rated",
"number",
"sanrio",
"pumpkin",
"nature",
"space",
"animal",
"aesthetic",
"fantasy",
"hello-kitty",
"rainbow",
"princess-peach",
"unicorn",
"pokemon",
"mario",
"puppy",
"cat",
"minnie-mouse",
"princess",
"spiderman",
"mermaid",
"pikachu",
"bunny",
"barbie",
"dinosaur",
"snowman",
"grinch",
"dragon",
"halloween",
"butterfly",
"flower",
"sonic",
"dog",
"adult",
"bowser",
"paw patrol",
"leprechaun",
"bluey",
"lightning-mcqueen",
"t-rex",
"wednesday",
"house",
"baby-yoda",
"minecraft",
"charizard",
"among-us",
"donut",
"car",
"monster-truck",
"cute",
"axolotl",
"horse",
"snowflake",
"kitty",
"pumpkin",
"iron man",
"turkey",
"gingerbread-man",
"tiger",
"stitch",
"fire-truck",
"heart",
"cupcake",
"airplane",
"basketball",
"cheetah",
"elsa",
"mushroom",
"ladybug",
"fish",
"shark",
"spongebob",
"batman",
"rainbow-friends",
"easter",
"octopus",
"blippi",
"yoshi",
"snake",
"american-flag",
"elf",
"rapunzel",
"race-car",
"train",
"santa",
"thanksgiving",
"ariel",
"roblox",
"anime",
"4th-of-july",
"my-little-pony",
"encanto",
"apple",
"birthday-cake",
"sun",
"gingerbread-house",
"tractor",
"squishmallow",
"fox",
"kitten",
];

export function GeneratePaths() {
return Categories.map((category) => ({
params: { slug: category },
}));
}

export function GenerateXmlStrings(url) {
return Categories.map(
(category) =>
`<url><loc>${url}coloring-pages/${category}</loc><lastmod>${GetCurrentDateTime()}</lastmod><changefreq>daily</changefreq><priority>0.8</priority></url>`,
);
}

export const GenerateCategoryData = () => {
return Categories.map((category) => ({
href: `/coloring-pages/${category}`,
children: `${category} coloring pages for adults`,
key: category,
count: 0,
}));
};

export function GetCurrentDateTime() {
const currentDate = new Date();
const year = currentDate.getUTCFullYear().toString().padStart(4, "0");
const month = (currentDate.getUTCMonth() + 1).toString().padStart(2, "0");
const day = currentDate.getUTCDate().toString().padStart(2, "0");
const hours = currentDate.getUTCHours().toString().padStart(2, "0");
const minutes = currentDate.getUTCMinutes().toString().padStart(2, "0");
const seconds = currentDate.getUTCSeconds().toString().padStart(2, "0");
const milliseconds = currentDate
.getUTCMilliseconds()
.toString()
.padStart(3, "0");

return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;
}