darkings_Obsidian-MonokaiSy.../scripts/audit-css.js
Darkings fe4dc7faf8 Initial commit: Monokai Syntax Obsidian theme
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 08:57:12 +08:00

31 lines
876 B
JavaScript

import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const themeCssPath = resolve(import.meta.dirname, "../dist/theme.css");
const themeCss = readFileSync(themeCssPath, "utf8");
const urlMatches = [...themeCss.matchAll(/url\((["']?)(.*?)\1\)/gi)].map((match) => match[2]);
const forbiddenRuntimeUrls = urlMatches.filter(
(url) => !url.startsWith("data:font/woff;base64,"),
);
const checks = [
["外部 @import", /@import/i.test(themeCss)],
["远程 URL", /https?:\/\//i.test(themeCss)],
["非本地内联字体 url() 资源", forbiddenRuntimeUrls.length > 0],
["!important 声明", /!important/i.test(themeCss)],
];
let hasFailure = false;
for (const [label, matched] of checks) {
console.log(`${label}: ${matched ? "发现" : "未发现"}`);
if (matched) {
hasFailure = true;
}
}
if (hasFailure) {
process.exitCode = 1;
}