fix(docs): proxy Plausible tracking script

This commit is contained in:
2026-05-15 01:26:26 -07:00
parent f0324cd93a
commit d1ec678d7a
5 changed files with 41 additions and 48 deletions
+25 -16
View File
@@ -3,25 +3,34 @@ import { readFileSync } from 'node:fs';
const docsConfigPath = new URL('./.vitepress/config.ts', import.meta.url);
const docsThemePath = new URL('./.vitepress/theme/index.ts', import.meta.url);
const docsPackagePath = new URL('./package.json', import.meta.url);
const docsConfigContents = readFileSync(docsConfigPath, 'utf8');
const docsThemeContents = readFileSync(docsThemePath, 'utf8');
const docsPackageContents = readFileSync(docsPackagePath, 'utf8');
test('docs site keeps docs hostname while sending plausible events to subminer.moe via worker.subminer.moe capture endpoint', () => {
test('docs site loads the docs.subminer.moe Plausible script through the analytics proxy', () => {
expect(docsConfigContents).toContain("const DOCS_HOSTNAME = 'https://docs.subminer.moe'");
expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME');
expect(docsThemeContents).toContain("const PLAUSIBLE_DOMAIN = 'subminer.moe'");
expect(docsThemeContents).toContain('const PLAUSIBLE_ENABLED_HOSTNAMES = new Set([');
expect(docsThemeContents).toContain("'docs.subminer.moe'");
expect(docsThemeContents).toContain(
"const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture'",
expect(docsConfigContents).toContain(
"const PLAUSIBLE_PROXY_HOSTNAME = 'https://worker.subminer.moe'",
);
expect(docsThemeContents).toContain('@plausible-analytics/tracker');
expect(docsThemeContents).toContain('const { init } = await import');
expect(docsThemeContents).toContain('!PLAUSIBLE_ENABLED_HOSTNAMES.has(window.location.hostname)');
expect(docsThemeContents).toContain('domain: PLAUSIBLE_DOMAIN');
expect(docsThemeContents).toContain('endpoint: PLAUSIBLE_ENDPOINT');
expect(docsThemeContents).toContain('outboundLinks: true');
expect(docsThemeContents).toContain('fileDownloads: true');
expect(docsThemeContents).toContain('formSubmissions: true');
expect(docsThemeContents).toContain('captureOnLocalhost: false');
expect(docsConfigContents).toContain(
"const PLAUSIBLE_SITE_SCRIPT_PATH = '/js/pa-h28Pn9ppgTJRmiSJlyPT6.js'",
);
expect(docsConfigContents).toContain(
'const PLAUSIBLE_ENDPOINT = `${PLAUSIBLE_PROXY_HOSTNAME}/api/event`',
);
expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME');
expect(docsConfigContents).toContain("rel: 'preconnect'");
expect(docsConfigContents).toContain('href: PLAUSIBLE_PROXY_HOSTNAME');
expect(docsConfigContents).toContain("async: ''");
expect(docsConfigContents).toContain(
'src: `${PLAUSIBLE_PROXY_HOSTNAME}${PLAUSIBLE_SITE_SCRIPT_PATH}`',
);
expect(docsConfigContents).toContain('plausible.init({ endpoint:');
expect(docsConfigContents).toContain('PLAUSIBLE_ENDPOINT');
expect(docsConfigContents).not.toContain("'data-domain'");
expect(docsConfigContents).not.toContain("'data-api'");
expect(docsThemeContents).not.toContain('@plausible-analytics/tracker');
expect(docsThemeContents).not.toContain('initPlausibleTracker');
expect(docsPackageContents).not.toContain('@plausible-analytics/tracker');
});