mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
fix(theme): fix git-plugin execute error when git: false (#591)
This commit is contained in:
parent
901142d97b
commit
2c9006caf7
@ -73,6 +73,4 @@ export const theme: Theme = plumeTheme({
|
||||
content: 'vuepress-theme-plume',
|
||||
},
|
||||
},
|
||||
|
||||
// plugins: { git: true },
|
||||
})
|
||||
|
||||
42
theme/src/node/plugins/git.ts
Normal file
42
theme/src/node/plugins/git.ts
Normal 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
|
||||
},
|
||||
})]
|
||||
}
|
||||
@ -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))
|
||||
|
||||
/**
|
||||
* 资源替换
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user