Skip to content

Commit

Permalink
[TTV] add sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanvm committed Nov 1, 2024
1 parent a04d736 commit fad1567
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions examples/text-to-voice/x-to-voice/app/sitemap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { MetadataRoute } from "next";
import { Redis } from "@upstash/redis";
import { env } from "@/env.mjs";

const kv = new Redis({
url: env.KV_REST_API_URL,
token: env.KV_REST_API_TOKEN,
});

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const keyHandles: string[] = [];
let cursor = "0";
const keyMatcher = "ttv_x:"
try {
do {
const result = await kv.scan(cursor, {
match: `${keyMatcher}*`, count: 100,
});
cursor = result[0];
keyHandles.push(...result[1]);
} while (cursor !== "0");
} catch (error) {
console.error("Could not fetch keyHandles:", error);
}

const sites: MetadataRoute.Sitemap = keyHandles.map((keyHandle: string) => (
{
url: `https://www.xtovoice.com/${keyHandle.slice(keyMatcher.length)}`,
changeFrequency: "weekly",
priority: 1,
}
));

return [
{
url: "https://www.xtovoice.com/",
changeFrequency: "weekly",
priority: 1,
},
...sites,
];
}

0 comments on commit fad1567

Please sign in to comment.