Skip to content

Commit

Permalink
feat(theme): support git options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 12, 2022
1 parent 957c3c6 commit 32712de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 8 additions & 2 deletions packages/shared/src/node/plugins.ts
Expand Up @@ -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);
};

Expand Down
13 changes: 8 additions & 5 deletions packages/theme/src/node/plugins/use.ts
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions 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";
Expand Down Expand Up @@ -245,6 +246,17 @@ export interface HopeThemePluginsOptions {
*/
feed?: Omit<FeedOptions, "hostname"> | 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
*
Expand Down

0 comments on commit 32712de

Please sign in to comment.