From fb2d237d45885513c3188b9167cdb9164725d865 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:27:07 +0330 Subject: [PATCH] Import source: global/scripts/generate-article-pages.mjs Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- global/scripts/generate-article-pages.mjs | 76 +++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 global/scripts/generate-article-pages.mjs diff --git a/global/scripts/generate-article-pages.mjs b/global/scripts/generate-article-pages.mjs new file mode 100644 index 0000000..fba9d89 --- /dev/null +++ b/global/scripts/generate-article-pages.mjs @@ -0,0 +1,76 @@ +#!/usr/bin/env node +// Generates static HTML for each article under dist/article/{slug}/index.html +import { readFileSync, writeFileSync, mkdirSync } from 'fs'; +import { articles, authors, siteConfig } from '../global-data.js'; + +const SITE = siteConfig.url; +const template = readFileSync('dist/index.html', 'utf8'); + +function capDate(d) { + const now = new Date().toISOString().split('T')[0]; + return d > now ? now : d; +} + +let count = 0; +for (const article of articles) { + const author = authors.find(a => a.id === article.author); + const canonical = `${SITE}/article/${article.slug}`; + const ogImage = `${SITE}${article.photo}`; + const lastmod = capDate(article.dateEn); + + const jsonLd = JSON.stringify({ + '@context': 'https://schema.org', + '@type': ['NewsArticle', 'TechArticle'], + headline: article.metaTitle || article.title, + description: article.metaDescription || article.subtitle, + image: ogImage, + datePublished: article.dateEn, + dateModified: lastmod, + inLanguage: 'en', + isAccessibleForFree: true, + mainEntityOfPage: { '@type': 'WebPage', '@id': canonical }, + author: author ? { + '@type': 'Person', + name: author.name, + url: `${SITE}/author/${author.slug}`, + } : undefined, + publisher: { + '@type': ['Organization', 'NewsMediaOrganization'], + name: 'Teknav', + url: SITE, + logo: { '@type': 'ImageObject', url: `${SITE}/images/og/default.jpg` }, + }, + }); + + const hreflang = article.persianUrl + ? ` + + ` + : ''; + + const head = ` + ${(article.metaTitle || article.title).replace(/"/g, '"')} | Teknav + + + ${hreflang} + + + + + + + ${article.persianUrl ? `` : ''} + + + + `; + + const html = template.replace('', `${head}\n `); + + const dir = `dist/article/${article.slug}`; + mkdirSync(dir, { recursive: true }); + writeFileSync(`${dir}/index.html`, html); + count++; +} + +console.log(`[article-pages] generated ${count} static article HTML pages`);