diff --git a/.vscode/settings.json b/.vscode/settings.json index 83eb7ffd..f547c043 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,6 +26,7 @@ "gsap", "nprogress", "pnpm", + "Tongji", "tsbuildinfo", "vite", "vuepress", diff --git a/packages/plugin-baidu-tongji/LICENSE b/packages/plugin-baidu-tongji/LICENSE new file mode 100644 index 00000000..9f677c90 --- /dev/null +++ b/packages/plugin-baidu-tongji/LICENSE @@ -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. diff --git a/packages/plugin-baidu-tongji/README.md b/packages/plugin-baidu-tongji/README.md new file mode 100644 index 00000000..6ed84194 --- /dev/null +++ b/packages/plugin-baidu-tongji/README.md @@ -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() + ] + // ... +} +``` diff --git a/packages/plugin-baidu-tongji/package.json b/packages/plugin-baidu-tongji/package.json new file mode 100644 index 00000000..31a3e100 --- /dev/null +++ b/packages/plugin-baidu-tongji/package.json @@ -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 ", + "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" + ] +} diff --git a/packages/plugin-baidu-tongji/src/node/index.ts b/packages/plugin-baidu-tongji/src/node/index.ts new file mode 100644 index 00000000..bee13c86 --- /dev/null +++ b/packages/plugin-baidu-tongji/src/node/index.ts @@ -0,0 +1,5 @@ +import { baiduTongjiPlugin } from './plugin' + +export * from './plugin' + +export default baiduTongjiPlugin diff --git a/packages/plugin-baidu-tongji/src/node/plugin.ts b/packages/plugin-baidu-tongji/src/node/plugin.ts new file mode 100644 index 00000000..63f8339b --- /dev/null +++ b/packages/plugin-baidu-tongji/src/node/plugin.ts @@ -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}` }, + ]) + }, + } +} diff --git a/packages/plugin-baidu-tongji/tsconfig.build.json b/packages/plugin-baidu-tongji/tsconfig.build.json new file mode 100644 index 00000000..f45328df --- /dev/null +++ b/packages/plugin-baidu-tongji/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "references": [ + { + "path": "./tsconfig.cjs.json" + } + ], + "files": [] +} diff --git a/packages/plugin-baidu-tongji/tsconfig.cjs.json b/packages/plugin-baidu-tongji/tsconfig.cjs.json new file mode 100644 index 00000000..81bc167c --- /dev/null +++ b/packages/plugin-baidu-tongji/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "CommonJS", + "rootDir": "./src", + "outDir": "./lib" + }, + "include": ["./src/node"] +} diff --git a/packages/plugin-baidu-tongji/tsconfig.esm.json b/packages/plugin-baidu-tongji/tsconfig.esm.json new file mode 100644 index 00000000..59b34084 --- /dev/null +++ b/packages/plugin-baidu-tongji/tsconfig.esm.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "module": "ES2020", + "rootDir": "./src", + "outDir": "./lib", + "types": ["@vuepress/client/types"] + }, + "include": ["./src/client"] +} diff --git a/packages/theme/package.json b/packages/theme/package.json index 4970ff99..4206525c 100644 --- a/packages/theme/package.json +++ b/packages/theme/package.json @@ -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", diff --git a/packages/theme/src/node/plugins/baiduTongji.ts b/packages/theme/src/node/plugins/baiduTongji.ts new file mode 100644 index 00000000..1c23440a --- /dev/null +++ b/packages/theme/src/node/plugins/baiduTongji.ts @@ -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) +} diff --git a/packages/theme/src/node/plugins/index.ts b/packages/theme/src/node/plugins/index.ts index a4651a76..0e411740 100644 --- a/packages/theme/src/node/plugins/index.ts +++ b/packages/theme/src/node/plugins/index.ts @@ -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 } diff --git a/packages/theme/src/shared/options/plugin.ts b/packages/theme/src/shared/options/plugin.ts index 0490443e..38057636 100644 --- a/packages/theme/src/shared/options/plugin.ts +++ b/packages/theme/src/shared/options/plugin.ts @@ -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 } diff --git a/packages/theme/tsconfig.build.json b/packages/theme/tsconfig.build.json index 722b5717..fda0df41 100644 --- a/packages/theme/tsconfig.build.json +++ b/packages/theme/tsconfig.build.json @@ -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" } ], diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 21f080eb..ba7e8971 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -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: