summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-02-09 00:47:32 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-02-09 00:47:32 +0300
commit2f74411118c35f0c9d852966af25e04b45dd3f53 (patch)
treec4ab5c61475294020832cc24bc2931a368fb3d0d /scripts
parent169ab22e65874ecfd9c047d60934220b60a86f15 (diff)
formatting and more perf
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generate-sitemap.ts49
1 files changed, 28 insertions, 21 deletions
diff --git a/scripts/generate-sitemap.ts b/scripts/generate-sitemap.ts
index 3270fea..e9f711f 100644
--- a/scripts/generate-sitemap.ts
+++ b/scripts/generate-sitemap.ts
@@ -1,36 +1,43 @@
-import { promises as fs } from 'node:fs';
-import path from 'node:path';
-import { fileURLToPath } from 'node:url';
+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 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');
+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);
+ const files = await fs.readdir(postsDir);
- return files
- .filter((file) => file.endsWith('.svx'))
- .map((file) => `/posts/${file.replace(/\.svx$/, '')}`)
- .sort();
+ 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`;
+ 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)`);
+ 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);
+ console.error("Failed to generate sitemap.txt");
+ console.error(error);
+ process.exit(1);
});