Branchwell

PulseCanvas / website · pulsecanvas.ai / vite.config.js

Raw 1.0 KB on 0cef5bc007bcecc69010c0ad24efe67f29d0dada
1import { defineConfig } from 'vite';
2import { readFileSync } from 'node:fs';
3import { fileURLToPath } from 'node:url';
4import { seoPlugin } from './scripts/seo.mjs';
5import { seoPages } from './seo.config.js';
6
7export default defineConfig({
8 plugins: [
9 {
10 name: 'pulsecanvas-footer',
11 transformIndexHtml: {
12 order: 'pre',
13 handler(html, context) {
14 const route = context.path.replace(/index\.html$/, '');
15 let footer = readFileSync(new URL('./footer.html', import.meta.url), 'utf8');
16 footer = footer.replaceAll(`href="${route}"`, `href="${route}" aria-current="page"`);
17 return html.replace('<!-- site-footer -->', footer);
18 },
19 },
20 },
21 seoPlugin(),
22 ],
23 build: {
24 rolldownOptions: {
25 input: { notFound: fileURLToPath(new URL('./404.html', import.meta.url)), ...Object.fromEntries(Object.keys(seoPages).map((path) => [path === '/' ? 'home' : path.slice(1, -1).replaceAll('/', '-'), fileURLToPath(new URL(`.${path}index.html`, import.meta.url))])) },
26 },
27 },
28});