PulseCanvas / website / vite.config.js
| 1 | import { defineConfig } from 'vite'; |
| 2 | import { readFileSync } from 'node:fs'; |
| 3 | import { fileURLToPath } from 'node:url'; |
| 4 | import { seoPlugin } from './scripts/seo.mjs'; |
| 5 | import { seoPages } from './seo.config.js'; |
| 6 | |
| 7 | export 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 | }); |