-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathsitemap.ts
More file actions
87 lines (77 loc) · 2.07 KB
/
sitemap.ts
File metadata and controls
87 lines (77 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { routing } from "@/i18n/routing";
import { MetadataRoute } from "next";
import { SEO } from "@/configs/seo";
import { getAllPosts } from "@/lib/api";
export const dynamic = "force-static";
interface Release {
tag_name: string;
}
// Fetch releases from GitHub API
async function fetchReleases(): Promise<Release[]> {
const res = await fetch(
"https://api.github.com/repos/nomandhoni-cs/blink-eye/releases",
{
cache: "force-cache",
headers: {
Authorization: `Bearer ${process.env.BLINK_EYE_WEBSITE_TOKEN}`,
},
},
);
if (!res.ok) {
throw new Error("Failed to fetch releases");
}
const data = await res.json();
return data;
}
// Predefined routes
const routes = [
"",
"/goodbye",
"/about",
"/features",
"/download",
"/howtouse",
"/contribute",
"/privacy",
"/pricing",
"/changelog",
"/howblinkeyehelps",
"/blogs",
];
// Sitemap generation function
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const baseUrl = SEO.url;
const releases = await fetchReleases();
const posts = getAllPosts();
const postRoutes = posts.flatMap((post) =>
routing.locales.map((locale) => ({
url: `${SEO.url}/${locale}/posts/${post.slug}`,
lastModified: new Date().toISOString(),
changeFrequency: "weekly" as const,
priority: 0.8,
})),
);
// Generate release-specific routes
const releaseRoutes = releases.flatMap((release) =>
routing.locales.map((locale) => ({
url: `${SEO.url}/${locale}/changelog/release/${release.tag_name}`,
lastModified: new Date().toISOString(),
changeFrequency: "weekly" as const,
priority: 0.8,
})),
);
// Generate routes for all locales
const localeRoutes = routing.locales.flatMap((locale) =>
routes.map((route) => ({
url: `${baseUrl}/${locale}${route}`,
lastModified: new Date(),
changeFrequency: "weekly" as const,
priority: route === "" ? 1 : 0.9,
})),
);
return [
...localeRoutes, // Include all routes for all locales
...releaseRoutes,
...postRoutes,
];
}