import { websiteUrl, seoPages, socialImage } from '../seo.config.js'; const absolute = (path) => new URL(path, websiteUrl).href; // NO SEO (2026-12-02): no sitemap, llms.txt or crawler courting. robots.txt just allows everyone. export const robots = 'User-agent: *\nAllow: /\n'; export function seoPlugin() { return { name: 'pulsecanvas-seo', transformIndexHtml: { order: 'pre', handler(html, context) { const path = context.path.replace(/index\.html$/, '').replace(/\/{2,}/g, '/'); if (path === "/404.html") return html; const page = seoPages[path]; if (!page) throw new Error(`Missing page metadata for ${context.path}`); // Replace legacy metadata, so every route has exactly one canonical title and description. html = html.replace('href="/images/app-icon.png"', 'href="/images/favicon.png"') .replace(/[\s\S]*?<\/title>/gi, '') .replace(/<meta\b(?=[^>]*\b(?:name\s*=\s*["'](?:description|robots|msvalidate\.01|twitter:[^"']+)["']|property\s*=\s*["']og:[^"']+["']))[^>]*>/gi, '') .replace(/<link\b(?=[^>]*\brel\s*=\s*["']canonical["'])[^>]*>/gi, '') .replace(/<script\b(?=[^>]*\btype\s*=\s*["']application\/ld\+json["'])[^>]*>[\s\S]*?<\/script>/gi, ''); return { html, tags: [ { tag: 'title', children: page.title }, { tag: 'meta', attrs: { name: 'description', content: page.description } }, ...Object.entries({ 'og:title': page.socialTitle || page.title, 'og:description': page.description, 'og:type': path.startsWith('/guides/') && path !== '/guides/' ? 'article' : 'website', 'og:url': absolute(path), 'og:site_name': 'PulseCanvas Studio', 'og:locale': 'en_US', 'og:image': absolute(socialImage.path), 'og:image:secure_url': absolute(socialImage.path), 'og:image:type': socialImage.type, 'og:image:width': String(socialImage.width), 'og:image:height': String(socialImage.height), 'og:image:alt': socialImage.alt, }).map(([property, content]) => ({ tag: 'meta', attrs: { property, content } })), ...Object.entries({ 'twitter:card': 'summary_large_image', 'twitter:title': page.socialTitle || page.title, 'twitter:description': page.description, 'twitter:image': absolute(socialImage.path), 'twitter:image:alt': socialImage.alt, }).map(([name, content]) => ({ tag: 'meta', attrs: { name, content } })), ].map(tag => ({ ...tag, injectTo: 'head' })) }; }, }, configureServer(server) { server.middlewares.use((request, response, next) => { const route = request.url?.split('?')[0]; if (route !== '/robots.txt') return next(); response.setHeader('Content-Type', 'text/plain'); response.end(robots); }); }, generateBundle() { this.emitFile({ type: 'asset', fileName: 'robots.txt', source: robots }); }, }; }