feat(plugin-baidu-tongji): 新增百度统计插件

新增百度统计插件
This commit is contained in:
pengzhanbo 2022-05-07 18:05:27 +08:00
parent ca041664df
commit 69a18b910c
15 changed files with 161 additions and 41 deletions

View File

@ -26,6 +26,7 @@
"gsap",
"nprogress",
"pnpm",
"Tongji",
"tsbuildinfo",
"vite",
"vuepress",

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (C) 2021 - PRESENT by pengzhanbo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,17 @@
# `@vuepress-plume/vuepress-plugin-baidu-tongji`
## Install
```
yarn add @vuepress-plume/vuepress-plugin-baidu-tongji
```
## Usage
``` js
// .vuepress/config.js
module.exports = {
//...
plugins: [
baiduTongjiPlugin()
]
// ...
}
```

View File

@ -0,0 +1,43 @@
{
"name": "@vuepress-plume/vuepress-plugin-baidu-tongji",
"version": "1.0.0-beta.29",
"description": "The Plugin for VuePres 2",
"homepage": "https://github.com/pengzhanbo/vuepress-theme-plume#readme",
"bugs": {
"url": "https://github.com/pengzhanbo/vuepress-theme-plume/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/pengzhanbo/vuepress-theme-plume.git"
},
"license": "MIT",
"author": "pengzhanbo <volodymyr@foxmail.com>",
"main": "lib/node/index.js",
"files": [
"lib"
],
"scripts": {
"build": "pnpm run clean && pnpm run copy && pnpm run ts",
"clean": "rimraf lib *.tsbuildinfo",
"copy": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib",
"copy:watch": "cpx \"src/**/*.{d.ts,vue,css,scss,jpg,png}\" lib -w",
"dev": "concurrently \"pnpm copy:watch\" \"pnpm ts:watch\"",
"ts": "tsc -b tsconfig.build.json",
"ts:watch": "tsc -b tsconfig.build.json --watch"
},
"dependencies": {
"@vuepress/client": "2.0.0-beta.43",
"@vuepress/core": "2.0.0-beta.43",
"@vuepress/shared": "2.0.0-beta.43",
"@vuepress/utils": "2.0.0-beta.43"
},
"publishConfig": {
"access": "public"
},
"keyword": [
"VuePress",
"vuepress plugin",
"baiduTongji",
"vuepress-plugin-plugin-baidu-tongji"
]
}

View File

@ -0,0 +1,5 @@
import { baiduTongjiPlugin } from './plugin'
export * from './plugin'
export default baiduTongjiPlugin

View File

@ -0,0 +1,24 @@
import type { Plugin } from '@vuepress/core'
export interface BaiduTongjiOptions {
key?: string
}
export const baiduTongjiPlugin = ({ key }: BaiduTongjiOptions): Plugin => {
return {
name: '@vuepress-plume/vuepress-plugin-baidu-tongji',
extendsPage: (page) => {
page.frontmatter.head?.push([
'script',
{
type: 'text/javascript',
},
'var _hmt = _hmt || []',
])
page.frontmatter.head?.push([
'script',
{ src: `https://hm.baidu.com/hm.js?${key}` },
])
},
}
}

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"references": [
{
"path": "./tsconfig.cjs.json"
}
],
"files": []
}

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"rootDir": "./src",
"outDir": "./lib"
},
"include": ["./src/node"]
}

View File

@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "ES2020",
"rootDir": "./src",
"outDir": "./lib",
"types": ["@vuepress/client/types"]
},
"include": ["./src/client"]
}

View File

@ -28,6 +28,7 @@
},
"dependencies": {
"@types/lodash.merge": "^4.6.6",
"@vuepress-plume/vuepress-plugin-baidu-tongji": "workspace:*",
"@vuepress-plume/vuepress-plugin-caniuse": "workspace:*",
"@vuepress-plume/vuepress-plugin-copy-code": "workspace:*",
"@vuepress/client": "2.0.0-beta.43",

View File

@ -0,0 +1,12 @@
// 8a4e65dd3f2d30e64c828481295e09d1
import type { BaiduTongjiOptions } from '@vuepress-plume/vuepress-plugin-baidu-tongji'
import { baiduTongjiPlugin } from '@vuepress-plume/vuepress-plugin-baidu-tongji'
import type { Plugin } from '@vuepress/core'
import type { PlumeThemePluginOptions } from '../../shared'
export const resolveBaiduTongji = ({
baiduTongji,
}: PlumeThemePluginOptions): Plugin => {
if (baiduTongji === false || !baiduTongji?.key) return [] as unknown as Plugin
return baiduTongjiPlugin(baiduTongji as BaiduTongjiOptions)
}

View File

@ -4,6 +4,7 @@ import type {
PlumeThemePluginOptions,
} from '../../shared'
import { resolveActiveHeaderLink } from './activeHeaderLink'
import { resolveBaiduTongji } from './baiduTongji'
import { resolveCanIUse } from './caniuse'
import { resolveComment } from './comment'
import { resolveCopyCode } from './copyCode'
@ -39,6 +40,7 @@ export const getPlugins = (
resolveSitemap(plugins, localeOptions),
resolveSeo(plugins, localeOptions),
resolveThemeData(localeOptions),
resolveBaiduTongji(plugins),
]
return resolvePlugins
}

View File

@ -1,8 +1,9 @@
import type { BaiduTongjiOptions } from '@vuepress-plume/vuepress-plugin-baidu-tongji'
import type { CanIUsePluginOptions } from '@vuepress-plume/vuepress-plugin-caniuse'
import type { CopyCodeOptions } from '@vuepress-plume/vuepress-plugin-copy-code'
import type { DocsearchOptions } from '@vuepress/plugin-docsearch'
import type { SearchPluginOptions } from '@vuepress/plugin-search'
import type { CommentOptions } from 'vuepress-plugin-comment2'
import type { CopyCodeOptions } from 'vuepress-plugin-copy-code2'
import type { MarkdownEnhanceOptions } from 'vuepress-plugin-md-enhance'
export interface PlumeThemePluginOptions {
/**
@ -40,4 +41,6 @@ export interface PlumeThemePluginOptions {
comment?: false | CommentOptions
sitemap?: false
baiduTongji?: false | BaiduTongjiOptions
}

View File

@ -3,6 +3,7 @@
"references": [
{ "path": "../plugin-caniuse/tsconfig.build.json" },
{ "path": "../plugin-copy-code/tsconfig.build.json" },
{ "path": "../plugin-baidu-tongji/tsconfig.build.json" },
{ "path": "./tsconfig.esm.json" },
{ "path": "./tsconfig.cjs.json" }
],

42
pnpm-lock.yaml generated
View File

@ -121,7 +121,6 @@ importers:
'@vuepress/core': 2.0.0-beta.43
'@vuepress/shared': 2.0.0-beta.43
'@vuepress/utils': 2.0.0-beta.43
balloon-css: ^1.2.0
vue: ^3.2.33
vue-router: ^4.0.14
dependencies:
@ -129,13 +128,13 @@ importers:
'@vuepress/core': 2.0.0-beta.43
'@vuepress/shared': 2.0.0-beta.43
'@vuepress/utils': 2.0.0-beta.43
balloon-css: 1.2.0
vue: 3.2.33
vue-router: 4.0.14_vue@3.2.33
packages/theme:
specifiers:
'@types/lodash.merge': ^4.6.6
'@vuepress-plume/vuepress-plugin-baidu-tongji': workspace:*
'@vuepress-plume/vuepress-plugin-caniuse': workspace:*
'@vuepress-plume/vuepress-plugin-copy-code': workspace:*
'@vuepress/client': 2.0.0-beta.43
@ -167,14 +166,12 @@ importers:
vue: ^3.2.33
vue-router: ^4.0.14
vuepress-plugin-comment2: 2.0.0-beta.49
vuepress-plugin-copy-code2: 2.0.0-beta.49
vuepress-plugin-md-enhance: 2.0.0-beta.49
vuepress-plugin-reading-time2: 2.0.0-beta.49
vuepress-plugin-sass-palette: 2.0.0-beta.49
vuepress-plugin-seo2: 2.0.0-beta.49
vuepress-plugin-sitemap2: 2.0.0-beta.49
dependencies:
'@types/lodash.merge': 4.6.7
'@vuepress-plume/vuepress-plugin-baidu-tongji': link:../plugin-baidu-tongji
'@vuepress-plume/vuepress-plugin-caniuse': link:../plugin-caniuse
'@vuepress-plume/vuepress-plugin-copy-code': link:../plugin-copy-code
'@vuepress/client': 2.0.0-beta.43
@ -206,10 +203,7 @@ importers:
vue: 3.2.33
vue-router: 4.0.14_vue@3.2.33
vuepress-plugin-comment2: 2.0.0-beta.49_sass-loader@12.6.0
vuepress-plugin-copy-code2: 2.0.0-beta.49_sass-loader@12.6.0
vuepress-plugin-md-enhance: 2.0.0-beta.49_sass-loader@12.6.0
vuepress-plugin-reading-time2: 2.0.0-beta.49
vuepress-plugin-sass-palette: 2.0.0-beta.49_sass-loader@12.6.0
vuepress-plugin-seo2: 2.0.0-beta.49
vuepress-plugin-sitemap2: 2.0.0-beta.49
@ -2110,10 +2104,6 @@ packages:
/balanced-match/1.0.2:
resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
/balloon-css/1.2.0:
resolution: {integrity: sha512-urXwkHgwp6GsXVF+it01485Z2Cj4pnW02ICnM0TemOlkKmCNnDLmyy+ZZiRXBpwldUXO+aRNr7Hdia4CBvXJ5A==}
dev: false
/base64-js/1.5.1:
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
@ -8005,26 +7995,6 @@ packages:
- supports-color
dev: false
/vuepress-plugin-copy-code2/2.0.0-beta.49_sass-loader@12.6.0:
resolution: {integrity: sha512-BYipVAj2Ajaatziho/TmOiPkm9GBX4z8nnOMgAwZS56S/xsKS8kM76MxikcIUFv+R0UANB+tTa5e1tNNa32IJQ==}
peerDependencies:
sass-loader: ^12.6.0
peerDependenciesMeta:
sass-loader:
optional: true
dependencies:
'@mr-hope/vuepress-shared': 2.0.0-beta.49
'@vuepress/client': 2.0.0-beta.43
'@vuepress/utils': 2.0.0-beta.43
balloon-css: 1.2.0
sass-loader: 12.6.0_sass@1.51.0
vue: 3.2.33
vue-router: 4.0.14_vue@3.2.33
vuepress-plugin-sass-palette: 2.0.0-beta.49_sass-loader@12.6.0
transitivePeerDependencies:
- supports-color
dev: false
/vuepress-plugin-md-enhance/2.0.0-beta.49_sass-loader@12.6.0:
resolution: {integrity: sha512-1HvUKjJbhC3dsS5SpenjRrO9SBysYvBfNepeIpoBonBfZXMZIXYJA8Rv0zp8LtkOhtQZVYbSBLJdiBnm0Xj4yw==}
peerDependencies:
@ -8061,14 +8031,6 @@ packages:
- supports-color
dev: false
/vuepress-plugin-reading-time2/2.0.0-beta.49:
resolution: {integrity: sha512-dZYC6nct/2i5eZSDt9KlsA7lnYweyazJw3/pHuyU2EkmgccYKMZfstnY0yI0nU5Pa1uMArWbO8Diajyxd/rYIA==}
dependencies:
'@mr-hope/vuepress-shared': 2.0.0-beta.49
transitivePeerDependencies:
- supports-color
dev: false
/vuepress-plugin-sass-palette/2.0.0-beta.49_sass-loader@12.6.0:
resolution: {integrity: sha512-C0fKeRqj61KdrMM2sPPW56REOR/GUFvk/znMcGY7yCOJeMW3dVOCUVOD4ndKkuDsSfzbrNJvNGlT9t1Pa5Gdow==}
peerDependencies: