fix(theme): fix git-plugin execute error when git: false (#591)

This commit is contained in:
pengzhanbo 2025-05-12 09:06:44 +08:00 committed by GitHub
parent 901142d97b
commit 2c9006caf7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 25 deletions

View File

@ -73,6 +73,4 @@ export const theme: Theme = plumeTheme({
content: 'vuepress-theme-plume',
},
},
// plugins: { git: true },
})

View File

@ -0,0 +1,42 @@
import type { App, PluginConfig } from 'vuepress'
import type { ThemeBuiltinPlugins } from '../../shared/index.js'
import { isPlainObject } from '@vuepress/helper'
import { gitPlugin as rawGitPlugin } from '@vuepress/plugin-git'
import { getThemeConfig } from '../loadConfig/index.js'
export function gitPlugin(app: App, pluginOptions: ThemeBuiltinPlugins): PluginConfig {
const options = getThemeConfig()
const git = pluginOptions.git ?? app.env.isBuild
if (!git) {
// disable all git features
return [rawGitPlugin({
createdTime: false,
updatedTime: false,
contributors: false,
changelog: false,
})]
}
const excludes = ['home', 'friends', 'page', 'custom', false]
const changelogOptions = isPlainObject(options.changelog) ? options.changelog : {}
return [rawGitPlugin({
updatedTime: options.lastUpdated !== false,
contributors: isPlainObject(options.contributors) || options.contributors === true
? {
avatar: true,
...options.contributors === true ? {} : options.contributors,
}
: false,
changelog: options.changelog && options.docsRepo
? { repoUrl: options.docsRepo, ...changelogOptions }
: options.changelog,
filter(page) {
if (page.frontmatter.home || excludes.includes(page.frontmatter.pageLayout as string))
return false
return true
},
})]
}

View File

@ -8,7 +8,6 @@ import { isPlainObject } from '@vuepress/helper'
import { cachePlugin } from '@vuepress/plugin-cache'
import { commentPlugin } from '@vuepress/plugin-comment'
import { docsearchPlugin } from '@vuepress/plugin-docsearch'
import { gitPlugin } from '@vuepress/plugin-git'
import { nprogressPlugin } from '@vuepress/plugin-nprogress'
import { photoSwipePlugin } from '@vuepress/plugin-photo-swipe'
import { readingTimePlugin } from '@vuepress/plugin-reading-time'
@ -18,6 +17,7 @@ import { watermarkPlugin } from '@vuepress/plugin-watermark'
import { replaceAssetsPlugin } from 'vuepress-plugin-replace-assets'
import { getThemeConfig } from '../loadConfig/index.js'
import { codePlugins } from './code.js'
import { gitPlugin } from './git.js'
import { markdownPlugins } from './markdown.js'
export function setupPlugins(
@ -103,28 +103,7 @@ export function setupPlugins(
* 2.
* 3.
*/
if (pluginOptions.git ?? isProd) {
const excludes = ['home', 'friends', 'page', 'custom', false]
const changelogOptions = isPlainObject(options.changelog) ? options.changelog : {}
plugins.push(gitPlugin({
createdTime: false,
updatedTime: options.lastUpdated !== false,
contributors: isPlainObject(options.contributors) || options.contributors === true
? {
avatar: true,
...options.contributors === true ? {} : options.contributors,
}
: false,
changelog: options.changelog && options.docsRepo
? { repoUrl: options.docsRepo, ...changelogOptions }
: options.changelog,
filter(page) {
if (page.frontmatter.home || excludes.includes(page.frontmatter.pageLayout as string))
return false
return true
},
}))
}
plugins.push(...gitPlugin(app, pluginOptions))
/**
*