mirror of
https://github.com/samber/awesome-prometheus-alerts.git
synced 2026-06-25 02:46:59 +08:00
Update site/astro.config.mjs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
58adb7c960
commit
e056652504
1 changed files with 8 additions and 2 deletions
|
|
@ -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)};`,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue