From bfd2c9cf864c514ff28e47bf286bfbe99dae9cdd Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 12 Aug 2024 16:32:25 +0800 Subject: [PATCH] feat(projects): add static plugin --- nuxt.config.js | 3 ++- plugins/goatcounter.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 plugins/goatcounter.js diff --git a/nuxt.config.js b/nuxt.config.js index 6d0b7c0..d9167b2 100644 --- a/nuxt.config.js +++ b/nuxt.config.js @@ -59,7 +59,8 @@ export default { {src: '~/plugins/element-ui'}, {src: '~/plugins/vditor', ssr: false}, {src: '~/plugins/vue-sse'}, - {src: '~/plugins/vue-cropper', ssr: false} + {src: '~/plugins/vue-cropper', ssr: false}, + {src: '~/plugins/goatcounter.js', ssr: false} ], /* ** Nuxt.js dev-modules diff --git a/plugins/goatcounter.js b/plugins/goatcounter.js new file mode 100644 index 0000000..ab8d1cc --- /dev/null +++ b/plugins/goatcounter.js @@ -0,0 +1,15 @@ +// plugins/goatcounter.js + +export default ({ app }) => { + // 检查 window 是否已经定义,因为插件在服务端渲染时也会执行 + if (process.client) { + // 创建 script 标签 + let script = document.createElement('script'); + script.async = true; + script.dataset.goatcounter = "https://statis.atduck.com/count"; + script.src = "//statis.atduck.com/count.js"; + + // 将 script 标签插入到页面中 + document.head.appendChild(script); + } +};