diff --git a/packages/shared/src/node/plugins.ts b/packages/shared/src/node/plugins.ts index 5d5b58f2ae6e..37cb0358009b 100644 --- a/packages/shared/src/node/plugins.ts +++ b/packages/shared/src/node/plugins.ts @@ -8,10 +8,16 @@ import type { GitPluginOptions } from "@vuepress/plugin-git"; * * @description Should be invoke on node site */ -export const useGitPlugin = (app: App, options: GitPluginOptions): void => { +export const useGitPlugin = ( + app: App, + options: GitPluginOptions | false +): void => { const plugins = app.pluginApi.plugins; - if (plugins.every((plugin) => plugin.name !== "@vuepress/plugin-git")) + if ( + plugins.every((plugin) => plugin.name !== "@vuepress/plugin-git") && + options + ) app.use(gitPlugin, options); }; diff --git a/packages/theme/src/node/plugins/use.ts b/packages/theme/src/node/plugins/use.ts index 7f21887beeb3..70f9df86fe38 100644 --- a/packages/theme/src/node/plugins/use.ts +++ b/packages/theme/src/node/plugins/use.ts @@ -9,11 +9,14 @@ import type { HopeThemePluginsOptions } from "../../shared"; export const usePlugin = (app: App, plugins: HopeThemePluginsOptions): void => { // only use git plugin in production or debug mode if (app.env.isDebug || app.env.isBuild) - useGitPlugin(app, { - createdTime: true, - contributors: true, - updatedTime: true, - }); + useGitPlugin( + app, + plugins.git || { + createdTime: true, + contributors: true, + updatedTime: true, + } + ); useReadingTimePlugin(app, { wordPerMinute: plugins.readingTime?.wordPerMinute, diff --git a/packages/theme/src/shared/options/plugins.ts b/packages/theme/src/shared/options/plugins.ts index ce55d3606765..68b36cf3777a 100644 --- a/packages/theme/src/shared/options/plugins.ts +++ b/packages/theme/src/shared/options/plugins.ts @@ -1,4 +1,5 @@ import type { Page } from "@vuepress/core"; +import type { GitPluginOptions } from "@vuepress/plugin-git"; import type { LocaleConfig } from "@vuepress/shared"; import type { BlogOptions } from "vuepress-plugin-blog2"; import type { CommentOptions } from "vuepress-plugin-comment2"; @@ -245,6 +246,17 @@ export interface HopeThemePluginsOptions { */ feed?: Omit | false; + /** + * Git plugin options + * + * @see https://v2.vuepress.vuejs.org/reference/plugin/git.html#install + * + * Git 插件配置 + * + * @see https://v2.vuepress.vuejs.org/zh/reference/plugin/git.html#install + */ + git?: GitPluginOptions | false; + /** * md-enhance plugin options *