Fix umami script not added
Some checks failed
ci / site (push) Has been cancelled
publish-image / publish (push) Has been cancelled

This commit is contained in:
2026-02-10 06:17:21 -05:00
parent 35afd9208f
commit 7cb72b2746
6 changed files with 64 additions and 3 deletions

View File

@@ -9,6 +9,7 @@
"fetch-content": "tsx scripts/fetch-content.ts",
"cache:clear": "tsx scripts/cache-clear.ts",
"verify:blog": "npm run build && tsx scripts/verify-blog-build.ts",
"verify:umami": "npm run build && tsx scripts/verify-umami-in-dist.ts",
"typecheck": "astro check",
"format": "prettier -w .",
"format:check": "prettier -c .",

View File

@@ -0,0 +1,39 @@
import "dotenv/config";
import { readFile } from "node:fs/promises";
function fail(msg: string): never {
// eslint-disable-next-line no-console
console.error(`[verify:umami] ${msg}`);
process.exit(1);
}
function info(msg: string) {
// eslint-disable-next-line no-console
console.log(`[verify:umami] ${msg}`);
}
async function main() {
const html = await readFile("dist/index.html", "utf8");
const scriptUrl = process.env.PUBLIC_UMAMI_SCRIPT_URL || "";
const websiteId = process.env.PUBLIC_UMAMI_WEBSITE_ID || "";
const expectsEnabled = Boolean(scriptUrl && websiteId);
const hasWebsiteId = html.includes('data-website-id="');
const hasScriptUrl = scriptUrl ? html.includes(`src="${scriptUrl}"`) : false;
if (expectsEnabled) {
if (!hasWebsiteId) fail(`expected Umami enabled, but data-website-id not found in dist/index.html`);
if (!hasScriptUrl)
fail(`expected Umami enabled, but src="${scriptUrl}" not found in dist/index.html`);
info("ok (umami script present)");
return;
}
// When not configured, the site should not render a script tag.
if (hasWebsiteId) fail("expected Umami disabled, but data-website-id was found in dist/index.html");
info("ok (umami disabled, no script rendered)");
}
main().catch((e) => fail(String(e)));