Update site/astro.config.mjs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Samuel Berthe 2026-04-10 20:57:23 +02:00 committed by GitHub
parent 58adb7c960
commit e056652504
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -9,14 +9,20 @@ import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url)); const __dirname = dirname(fileURLToPath(import.meta.url));
function normalizeViteId(id) {
const cleanId = id.split('?', 1)[0].split('#', 1)[0];
return cleanId.startsWith('/@fs/') ? cleanId.slice(4) : cleanId;
}
/** Custom Vite plugin that parses YAML files using the 'yaml' package, /** Custom Vite plugin that parses YAML files using the 'yaml' package,
* which tolerates duplicate keys (last one wins) unlike js-yaml 4.x. */ * which tolerates duplicate keys (last one wins) unlike js-yaml 4.x. */
function yamlPlugin() { function yamlPlugin() {
return { return {
name: 'vite-plugin-yaml-tolerant', name: 'vite-plugin-yaml-tolerant',
transform(code, id) { transform(code, id) {
if (!id.endsWith('.yml') && !id.endsWith('.yaml')) return null; const normalizedId = normalizeViteId(id);
const content = readFileSync(resolve(id), 'utf-8'); if (!normalizedId.endsWith('.yml') && !normalizedId.endsWith('.yaml')) return null;
const content = typeof code === 'string' ? code : readFileSync(resolve(normalizedId), 'utf-8');
const data = parseYaml(content, { merge: true, strict: false, uniqueKeys: false }); const data = parseYaml(content, { merge: true, strict: false, uniqueKeys: false });
return { return {
code: `export default ${JSON.stringify(data)};`, code: `export default ${JSON.stringify(data)};`,