Files
2026-09-15 20:37:49 +03:30

24 lines
1.8 KiB
JavaScript

import assert from 'node:assert/strict';
import { access, readFile } from 'node:fs/promises';
import { join, resolve } from 'node:path';
const output=resolve('out');
const routes=['/','/aboutus/','/blog/','/contactus/','/ourservices/','/portfolios/'];
const titles=new Set(); const descriptions=new Set();
for(const route of routes){
const html=await readFile(join(output,route,'index.html'),'utf8');
const title=html.match(/<title>([^<]+)<\/title>/)?.[1];
const description=html.match(/<meta name="description" content="([^"]+)"/)?.[1];
assert.ok(title,`Missing title: ${route}`); assert.ok(description,`Missing description: ${route}`);
assert.ok(!titles.has(title),`Duplicate title: ${title}`); assert.ok(!descriptions.has(description),`Duplicate description: ${description}`);
titles.add(title); descriptions.add(description);
assert.equal((html.match(/<h1(?:\s|>)/g)||[]).length,1,`Expected one H1: ${route}`);
assert.match(html,/<link rel="canonical" href="https:\/\/sanazgoodarzi\.ir\//,`Missing canonical: ${route}`);
for(const image of html.matchAll(/<img\b[^>]*>/g)) assert.match(image[0],/\salt="[^"]+"/,`Missing meaningful image alt in ${route}`);
}
const sitemap=JSON.parse(await readFile(join(output,'meshkee','sitemap-config.json'),'utf8'));
assert.equal(sitemap.baseUrl,'https://sanazgoodarzi.ir');
assert.deepEqual(sitemap.staticPages.map(page=>page.path),['/','/aboutus','/blog','/contactus','/ourservices','/portfolios']);
for(const forbidden of ['sitemap.xml','robots.txt']){try{await access(join(output,forbidden));assert.fail(`${forbidden} must be proxied, not shipped`)}catch(error){if(error.code!=='ENOENT')throw error}}
console.log(`PASS: SEO metadata, one H1, canonical URLs and image alt text on ${routes.length} crawlable static pages; sitemap config contains ${sitemap.staticPages.length} routes.`);