Something went wrong. Try again.
A warm, tech-dystopian color scheme inspired by corrupted hardware and failing systems. digitalrust.katsuricata.com
theme color-scheme color-theme warm color
Something went wrong. Try again.
DigitalRust vite.config.ts
2.5 kB · 75 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576// SPDX-FileCopyrightText: 2025-2026 Kat Suricata <https://KatSuricata.com/>// SPDX-License-Identifier: (CC-BY-4.0+ OR Apache-2.0+)
import adapter from '@sveltejs/adapter-static';import { sveltekit } from '@sveltejs/kit/vite';import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';import { dirname, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { defineConfig, type Plugin } from 'vite';import { toTokensCss } from './src/lib/palette.ts';
const generatedTokens = fileURLToPath(new URL('./src/lib/generated/tokens.css', import.meta.url));const specMarkdown = fileURLToPath( new URL('./Digital Rust Syntax Highlighting Specification.md', import.meta.url));
// The version lives in the spec's version history. Inlining it at build time// keeps the whole markdown document out of the client bundle.function readSpecVersion(): string { const markdown = readFileSync(specMarkdown, 'utf8'); const match = /- \*\*(v\d+\.\d+\.\d+)\*\*/.exec(markdown); if (!match) { throw new Error( 'Spec version not found. The syntax specification must keep a "- **vX.Y.Z**" entry in its version history.' ); } return match[1];}
// Local date, so the site reports the day the build actually ran here.function buildDate(): string { const now = new Date(); const month = String(now.getMonth() + 1).padStart(2, '0'); const day = String(now.getDate()).padStart(2, '0'); return `${now.getFullYear()}-${month}-${day}`;}
// Keeps src/lib/generated/tokens.css in sync with src/lib/palette.ts so the// site has a single palette source.function paletteTokens(): Plugin { const write = () => { mkdirSync(dirname(generatedTokens), { recursive: true }); writeFileSync(generatedTokens, toTokensCss()); }; return { name: 'digital-rust-tokens', buildStart: write, configureServer(server) { server.watcher.add(resolve('./src/lib/palette.ts')); server.watcher.on('change', (file) => { if (file.endsWith('palette.ts')) write(); }); } };}
export default defineConfig({ define: { __SPEC_VERSION__: JSON.stringify(readSpecVersion()), __BUILD_DATE__: JSON.stringify(buildDate()) }, plugins: [ paletteTokens(), sveltekit({ compilerOptions: { // Force runes mode for the project, except for libraries. Can be removed in svelte 6. runes: ({ filename }) => filename.split(/[/\\]/).includes('node_modules') ? undefined : true, experimental: { async: true } }, adapter: adapter(), experimental: { remoteFunctions: true, forkPreloads: true } }) ]});