From 9561226d0b0e3a70071c081a4340422e7b1db189 Mon Sep 17 00:00:00 2001 From: Rui Wu Date: Wed, 11 Sep 2024 21:52:48 +0800 Subject: [PATCH] docs: google adsense & google analytics --- docs/.vitepress/config.ts | 25 +++++++++++++++++++++++ docs/.vitepress/theme/VAd.vue | 37 ++++++++++++++++++++++++++++++++++ docs/.vitepress/theme/index.ts | 21 ++++++++++++++++--- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 docs/.vitepress/theme/VAd.vue diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 0ba9807..971e66d 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -15,6 +15,31 @@ export default defineConfig({ // content: "/logo.png", // }, // ], + // Google Analytics + [ + 'script', + { + async: '', + src: `https://www.googletagmanager.com/gtag/js?id=G-GBE9KNFWLS`, + }, + ], + [ + 'script', + {}, + `window.dataLayer = window.dataLayer || []; + function gtag(){dataLayer.push(arguments);} + gtag('js', new Date()); + gtag('config', 'G-GBE9KNFWLS');`, + ], + // Google AdSense + [ + 'script', + { + async: '', + crossorigin: 'anonymous', + src: `https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3102250747488251`, + }, + ], ], locales: { root: { diff --git a/docs/.vitepress/theme/VAd.vue b/docs/.vitepress/theme/VAd.vue new file mode 100644 index 0000000..9e726a2 --- /dev/null +++ b/docs/.vitepress/theme/VAd.vue @@ -0,0 +1,37 @@ + + + + + diff --git a/docs/.vitepress/theme/index.ts b/docs/.vitepress/theme/index.ts index 6a2be75..bd931ee 100644 --- a/docs/.vitepress/theme/index.ts +++ b/docs/.vitepress/theme/index.ts @@ -1,8 +1,23 @@ // https://vitepress.dev/guide/custom-theme -import type { Theme } from "vitepress"; -import DefaultTheme from "vitepress/theme"; -import "./custom.css"; +import type {EnhanceAppContext, Theme} from 'vitepress' +import DefaultTheme from 'vitepress/theme'; +import { h } from 'vue'; +import VAd from './VAd.vue'; +import './custom.css'; export default { extends: DefaultTheme, + + enhanceApp(ctx: EnhanceAppContext) { + ctx.app.component('VAd', VAd) + DefaultTheme.enhanceApp(ctx); + }, + + Layout() { + return h(DefaultTheme.Layout, null, { + // 添加广告 + 'aside-bottom': () => [h(VAd)], + }); + }, + } satisfies Theme;