summaryrefslogtreecommitdiff
path: root/scripts/generate-sitemap.ts
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-02-08 23:57:12 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-02-08 23:57:12 +0300
commit653176734cf3a2b74a40460e5288a6f73a14c983 (patch)
treeb4064c81bb41bf438bacbdee1bd5ffb4255125e8 /scripts/generate-sitemap.ts
parent1ebca0ddb022c456d9b6963b0a4e7bf5954293d2 (diff)
sitemap
Diffstat (limited to 'scripts/generate-sitemap.ts')
-rw-r--r--scripts/generate-sitemap.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/generate-sitemap.ts b/scripts/generate-sitemap.ts
new file mode 100644
index 0000000..e521365
--- /dev/null
+++ b/scripts/generate-sitemap.ts
@@ -0,0 +1,36 @@
+import { promises as fs } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const SITE_URL = (process.env.SITE_URL ?? 'https://wsap.dev').replace(/\/+$/, '');
+const STATIC_ROUTES = ['/', '/about', '/apps'];
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = path.dirname(__filename);
+const projectRoot = path.resolve(__dirname, '..');
+const postsDir = path.join(projectRoot, 'src', 'posts');
+const sitemapPath = path.join(projectRoot, 'static', 'sitemap.txt');
+
+async function getPostRoutes(): Promise<string[]> {
+ const files = await fs.readdir(postsDir);
+
+ return files
+ .filter((file) => file.endsWith('.svx'))
+ .map((file) => `/posts/${file.replace(/\.svx$/, '')}`)
+ .sort();
+}
+
+async function main(): Promise<void> {
+ const postRoutes = await getPostRoutes();
+ const urls = [...STATIC_ROUTES, ...postRoutes].map((route) => `${SITE_URL}${route}`);
+ const body = `${urls.join('\n')}\n`;
+
+ await fs.writeFile(sitemapPath, body, 'utf8');
+ console.log(`Generated sitemap: ${path.relative(projectRoot, sitemapPath)} (${urls.length} URLs)`);
+}
+
+main().catch((error: unknown) => {
+ console.error('Failed to generate sitemap.txt');
+ console.error(error);
+ process.exit(1);
+});