Files
social-media/frontend/scripts/write-public-seo.mjs
Jonathan Bourdon a437bfcfc3
Some checks failed
deploy-socialize / test (push) Failing after 2s
deploy-socialize / image (push) Has been skipped
deploy-socialize / deploy (push) Has been skipped
chore(ci): update SEO
2026-05-05 22:24:57 -04:00

71 lines
2.3 KiB
JavaScript

import { mkdir, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';
const publicRoutes = [
{ path: '/', changefreq: 'weekly', priority: '1.0' },
{ path: '/product', changefreq: 'weekly', priority: '0.8' },
{ path: '/product/content-planning', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/asset-revisions', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/comment-threads', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/approval-workflows', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/client-review', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/review-queues', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/audit-trail', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/workspace-access', changefreq: 'weekly', priority: '0.7' },
{ path: '/product/team-collaboration', changefreq: 'weekly', priority: '0.7' },
{ path: '/pricing', changefreq: 'monthly', priority: '0.7' },
{ path: '/blogs', changefreq: 'weekly', priority: '0.6' },
{ path: '/guides', changefreq: 'weekly', priority: '0.6' },
];
const disallowedRoutes = [
'/app/',
'/login',
'/register',
'/forgot-password',
'/reset-password',
'/verify-email',
];
const siteUrl = (process.env.VITE_PUBLIC_SITE_URL ?? process.env.SITE_URL ?? 'https://socialize.mapachotes.com')
.replace(/\/$/, '');
const distDir = resolve(process.cwd(), 'dist');
function absoluteUrl(path) {
return new URL(path, `${siteUrl}/`).toString();
}
const robots = [
'User-agent: *',
'Allow: /',
...disallowedRoutes.map(route => `Disallow: ${route}`),
'',
`Sitemap: ${absoluteUrl('/sitemap.xml')}`,
'',
].join('\n');
const sitemapEntries = publicRoutes
.map(route => [
' <url>',
` <loc>${absoluteUrl(route.path)}</loc>`,
` <changefreq>${route.changefreq}</changefreq>`,
` <priority>${route.priority}</priority>`,
' </url>',
].join('\n'))
.join('\n');
const sitemap = [
'<?xml version="1.0" encoding="UTF-8"?>',
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
sitemapEntries,
'</urlset>',
'',
].join('\n');
await mkdir(distDir, { recursive: true });
await writeFile(resolve(distDir, 'robots.txt'), robots);
await writeFile(resolve(distDir, 'sitemap.xml'), sitemap);
console.log(`Wrote public SEO files for ${siteUrl}`);