From 2bea3214b7da18f4bf41cf9db750528d3b1a9465 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:27:09 +0330 Subject: [PATCH] Import source: global/scripts/generate-seo.mjs Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- global/scripts/generate-seo.mjs | 96 +++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 global/scripts/generate-seo.mjs diff --git a/global/scripts/generate-seo.mjs b/global/scripts/generate-seo.mjs new file mode 100644 index 0000000..449648f --- /dev/null +++ b/global/scripts/generate-seo.mjs @@ -0,0 +1,96 @@ +#!/usr/bin/env node +// Generates sitemap.xml, robots.txt, and feed.xml for teknavglobal.com +import { writeFileSync, mkdirSync } from 'fs'; +import { createRequire } from 'module'; + +const SITE = 'https://www.teknavglobal.com'; + +// Load article data (CommonJS-compatible workaround for ES module data) +const require = createRequire(import.meta.url); + +// Dynamic import of global-data.js +const { articles, authors, siteConfig } = await import('../global-data.js'); + +function capDate(d) { + const now = new Date().toISOString().split('T')[0]; + return d > now ? now : d; +} + +// ── sitemap.xml ───────────────────────────────────────────────────── +const staticPages = [ + { url: '/', priority: '1.0', freq: 'daily' }, + { url: '/articles', priority: '0.9', freq: 'daily' }, + { url: '/about', priority: '0.7', freq: 'monthly' }, + { url: '/privacy', priority: '0.4', freq: 'yearly' }, + { url: '/terms', priority: '0.4', freq: 'yearly' }, + { url: '/editorial-policy', priority: '0.5', freq: 'monthly' }, +]; + +const articleEntries = articles.map(a => ({ + url: `/article/${a.slug}`, + lastmod: capDate(a.dateEn), + priority: '0.8', + freq: 'weekly', +})); + +const allEntries = [...staticPages, ...articleEntries]; + +const sitemap = ` + +${allEntries.map(e => ` + ${SITE}${e.url} + ${e.lastmod ? `${e.lastmod}` : ''} + ${e.freq} + ${e.priority} + `).join('\n')} +`; + +// ── robots.txt ────────────────────────────────────────────────────── +const robots = `User-agent: * +Allow: / +Disallow: /api/ +Disallow: /profile/ +Disallow: /admin/ + +Sitemap: ${SITE}/sitemap.xml +`; + +// ── feed.xml (RSS) ────────────────────────────────────────────────── +const feed = ` + + + Teknav — Deep Technology Analysis for Builders + ${SITE} + Technical analysis on AI engineering, security, software architecture, and emerging compute. + en + ${new Date().toUTCString()} + + + ${SITE}/images/og/default.jpg + Teknav + ${SITE} + +${articles + .sort((a, b) => new Date(b.dateEn) - new Date(a.dateEn)) + .map(a => { + const author = authors.find(au => au.id === a.author); + return ` + <![CDATA[${a.title}]]> + ${SITE}/article/${a.slug} + ${SITE}/article/${a.slug} + ${new Date(a.dateEn).toUTCString()} + + ${author ? `${author.name}` : ''} + ${a.category} + `; + }).join('\n')} + +`; + +mkdirSync('public', { recursive: true }); +writeFileSync('public/sitemap.xml', sitemap); +writeFileSync('public/robots.txt', robots); +writeFileSync('public/feed.xml', feed); + +console.log(`[seo] sitemap: ${allEntries.length} URLs | feed: ${articles.length} items`);