mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-05-15 08:12:53 -07:00
fix(docs): proxy Plausible tracking script
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
const DOCS_HOSTNAME = 'https://docs.subminer.moe';
|
const DOCS_HOSTNAME = 'https://docs.subminer.moe';
|
||||||
|
const PLAUSIBLE_PROXY_HOSTNAME = 'https://worker.subminer.moe';
|
||||||
|
const PLAUSIBLE_SITE_SCRIPT_PATH = '/js/pa-h28Pn9ppgTJRmiSJlyPT6.js';
|
||||||
|
const PLAUSIBLE_ENDPOINT = `${PLAUSIBLE_PROXY_HOSTNAME}/api/event`;
|
||||||
|
const PLAUSIBLE_INIT_SCRIPT = [
|
||||||
|
'window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};',
|
||||||
|
`plausible.init({ endpoint: '${PLAUSIBLE_ENDPOINT}' });`,
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
function pageToCanonicalHref(page: string): string | null {
|
function pageToCanonicalHref(page: string): string | null {
|
||||||
if (page === '404.md') return null;
|
if (page === '404.md') return null;
|
||||||
@@ -15,6 +22,15 @@ export default {
|
|||||||
description:
|
description:
|
||||||
'SubMiner: an MPV immersion-mining overlay with Yomitan and AnkiConnect integration.',
|
'SubMiner: an MPV immersion-mining overlay with Yomitan and AnkiConnect integration.',
|
||||||
head: [
|
head: [
|
||||||
|
['link', { rel: 'preconnect', href: PLAUSIBLE_PROXY_HOSTNAME }],
|
||||||
|
[
|
||||||
|
'script',
|
||||||
|
{
|
||||||
|
async: '',
|
||||||
|
src: `${PLAUSIBLE_PROXY_HOSTNAME}${PLAUSIBLE_SITE_SCRIPT_PATH}`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
['script', {}, PLAUSIBLE_INIT_SCRIPT],
|
||||||
['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }],
|
['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }],
|
||||||
[
|
[
|
||||||
'link',
|
'link',
|
||||||
|
|||||||
@@ -7,32 +7,7 @@ import './mermaid-modal.css';
|
|||||||
import TuiLayout from './TuiLayout.vue';
|
import TuiLayout from './TuiLayout.vue';
|
||||||
|
|
||||||
let mermaidLoader: Promise<any> | null = null;
|
let mermaidLoader: Promise<any> | null = null;
|
||||||
let plausibleTrackerInitialized = false;
|
|
||||||
const MERMAID_MODAL_ID = 'mermaid-diagram-modal';
|
const MERMAID_MODAL_ID = 'mermaid-diagram-modal';
|
||||||
const PLAUSIBLE_DOMAIN = 'subminer.moe';
|
|
||||||
const PLAUSIBLE_ENABLED_HOSTNAMES = new Set(['docs.subminer.moe']);
|
|
||||||
const PLAUSIBLE_ENDPOINT = 'https://worker.subminer.moe/api/capture';
|
|
||||||
|
|
||||||
async function initPlausibleTracker() {
|
|
||||||
if (typeof window === 'undefined' || plausibleTrackerInitialized) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!PLAUSIBLE_ENABLED_HOSTNAMES.has(window.location.hostname)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { init } = await import('@plausible-analytics/tracker');
|
|
||||||
init({
|
|
||||||
domain: PLAUSIBLE_DOMAIN,
|
|
||||||
endpoint: PLAUSIBLE_ENDPOINT,
|
|
||||||
outboundLinks: true,
|
|
||||||
fileDownloads: true,
|
|
||||||
formSubmissions: true,
|
|
||||||
captureOnLocalhost: false,
|
|
||||||
});
|
|
||||||
plausibleTrackerInitialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeMermaidModal() {
|
function closeMermaidModal() {
|
||||||
if (typeof document === 'undefined') {
|
if (typeof document === 'undefined') {
|
||||||
@@ -222,9 +197,6 @@ export default {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initPlausibleTracker().catch((error) => {
|
|
||||||
console.error('Failed to initialize Plausible tracker:', error);
|
|
||||||
});
|
|
||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
watch(() => route.path, render);
|
watch(() => route.path, render);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
"@catppuccin/vitepress": "^0.1.2",
|
"@catppuccin/vitepress": "^0.1.2",
|
||||||
"@fontsource/jetbrains-mono": "^5.2.8",
|
"@fontsource/jetbrains-mono": "^5.2.8",
|
||||||
"@fontsource/manrope": "^5.2.8",
|
"@fontsource/manrope": "^5.2.8",
|
||||||
"@plausible-analytics/tracker": "^0.4.4",
|
|
||||||
"mermaid": "^11.12.3",
|
"mermaid": "^11.12.3",
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -143,8 +142,6 @@
|
|||||||
|
|
||||||
"@mermaid-js/parser": ["@mermaid-js/parser@1.0.0", "", { "dependencies": { "langium": "^4.0.0" } }, "sha512-vvK0Hi/VWndxoh03Mmz6wa1KDriSPjS2XMZL/1l19HFwygiObEEoEwSDxOqyLzzAI6J2PU3261JjTMTO7x+BPw=="],
|
"@mermaid-js/parser": ["@mermaid-js/parser@1.0.0", "", { "dependencies": { "langium": "^4.0.0" } }, "sha512-vvK0Hi/VWndxoh03Mmz6wa1KDriSPjS2XMZL/1l19HFwygiObEEoEwSDxOqyLzzAI6J2PU3261JjTMTO7x+BPw=="],
|
||||||
|
|
||||||
"@plausible-analytics/tracker": ["@plausible-analytics/tracker@0.4.4", "", {}, "sha512-fz0NOYUEYXtg1TBaPEEvtcBq3FfmLFuTe1VZw4M8sTWX129br5dguu3M15+plOQnc181ShYe67RfwhKgK89VnA=="],
|
|
||||||
|
|
||||||
"@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.59.0", "", { "os": "android", "cpu": "arm" }, "sha512-upnNBkA6ZH2VKGcBj9Fyl9IGNPULcjXRlg0LLeaioQWueH30p6IXtJEbKAgvyv+mJaMxSm1l6xwDXYjpEMiLMg=="],
|
"@rollup/rollup-android-arm-eabi": ["@rollup/rollup-android-arm-eabi@4.59.0", "", { "os": "android", "cpu": "arm" }, "sha512-upnNBkA6ZH2VKGcBj9Fyl9IGNPULcjXRlg0LLeaioQWueH30p6IXtJEbKAgvyv+mJaMxSm1l6xwDXYjpEMiLMg=="],
|
||||||
|
|
||||||
"@rollup/rollup-android-arm64": ["@rollup/rollup-android-arm64@4.59.0", "", { "os": "android", "cpu": "arm64" }, "sha512-hZ+Zxj3SySm4A/DylsDKZAeVg0mvi++0PYVceVyX7hemkw7OreKdCvW2oQ3T1FMZvCaQXqOTHb8qmBShoqk69Q=="],
|
"@rollup/rollup-android-arm64": ["@rollup/rollup-android-arm64@4.59.0", "", { "os": "android", "cpu": "arm64" }, "sha512-hZ+Zxj3SySm4A/DylsDKZAeVg0mvi++0PYVceVyX7hemkw7OreKdCvW2oQ3T1FMZvCaQXqOTHb8qmBShoqk69Q=="],
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
"@catppuccin/vitepress": "^0.1.2",
|
"@catppuccin/vitepress": "^0.1.2",
|
||||||
"@fontsource/jetbrains-mono": "^5.2.8",
|
"@fontsource/jetbrains-mono": "^5.2.8",
|
||||||
"@fontsource/manrope": "^5.2.8",
|
"@fontsource/manrope": "^5.2.8",
|
||||||
"@plausible-analytics/tracker": "^0.4.4",
|
|
||||||
"mermaid": "^11.12.3"
|
"mermaid": "^11.12.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
+25
-16
@@ -3,25 +3,34 @@ import { readFileSync } from 'node:fs';
|
|||||||
|
|
||||||
const docsConfigPath = new URL('./.vitepress/config.ts', import.meta.url);
|
const docsConfigPath = new URL('./.vitepress/config.ts', import.meta.url);
|
||||||
const docsThemePath = new URL('./.vitepress/theme/index.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 docsConfigContents = readFileSync(docsConfigPath, 'utf8');
|
||||||
const docsThemeContents = readFileSync(docsThemePath, '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("const DOCS_HOSTNAME = 'https://docs.subminer.moe'");
|
||||||
expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME');
|
expect(docsConfigContents).toContain(
|
||||||
expect(docsThemeContents).toContain("const PLAUSIBLE_DOMAIN = 'subminer.moe'");
|
"const PLAUSIBLE_PROXY_HOSTNAME = 'https://worker.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(docsThemeContents).toContain('@plausible-analytics/tracker');
|
expect(docsConfigContents).toContain(
|
||||||
expect(docsThemeContents).toContain('const { init } = await import');
|
"const PLAUSIBLE_SITE_SCRIPT_PATH = '/js/pa-h28Pn9ppgTJRmiSJlyPT6.js'",
|
||||||
expect(docsThemeContents).toContain('!PLAUSIBLE_ENABLED_HOSTNAMES.has(window.location.hostname)');
|
);
|
||||||
expect(docsThemeContents).toContain('domain: PLAUSIBLE_DOMAIN');
|
expect(docsConfigContents).toContain(
|
||||||
expect(docsThemeContents).toContain('endpoint: PLAUSIBLE_ENDPOINT');
|
'const PLAUSIBLE_ENDPOINT = `${PLAUSIBLE_PROXY_HOSTNAME}/api/event`',
|
||||||
expect(docsThemeContents).toContain('outboundLinks: true');
|
);
|
||||||
expect(docsThemeContents).toContain('fileDownloads: true');
|
expect(docsConfigContents).toContain('hostname: DOCS_HOSTNAME');
|
||||||
expect(docsThemeContents).toContain('formSubmissions: true');
|
expect(docsConfigContents).toContain("rel: 'preconnect'");
|
||||||
expect(docsThemeContents).toContain('captureOnLocalhost: false');
|
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');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user