mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
feat(theme): add support disable blog
This commit is contained in:
parent
8c6604e5af
commit
ce544d2dfc
@ -29,8 +29,9 @@ export function useLangs({
|
||||
const { notFound, path } = resolveRoute(targetPath)
|
||||
if (!notFound)
|
||||
return path
|
||||
|
||||
const blog = theme.value.blog
|
||||
if (isBlogPost.value)
|
||||
if (isBlogPost.value && blog !== false)
|
||||
return withBase(blog?.link || normalizeLink(locale, 'blog/'))
|
||||
|
||||
const sidebarList = sidebar.value
|
||||
|
||||
@ -194,34 +194,36 @@ export function resolveOptions(
|
||||
include: '**/{readme,README,index}.md',
|
||||
frontmatter: {},
|
||||
},
|
||||
{
|
||||
include: localeOptions.blog?.include ?? ['**/*.md'],
|
||||
frontmatter: {
|
||||
...options.title !== false
|
||||
? {
|
||||
title(title: string, { relativePath }) {
|
||||
if (title)
|
||||
return title
|
||||
const basename = path.basename(relativePath || '', '.md')
|
||||
return basename
|
||||
},
|
||||
} as AutoFrontmatterObject
|
||||
: undefined,
|
||||
...baseFrontmatter,
|
||||
...options.permalink !== false
|
||||
? {
|
||||
permalink(permalink: string, { relativePath }) {
|
||||
if (permalink)
|
||||
return permalink
|
||||
const locale = resolveLocale(relativePath)
|
||||
const prefix = withBase(articlePrefix, locale)
|
||||
localeOptions.blog !== false
|
||||
? {
|
||||
include: localeOptions.blog?.include ?? ['**/*.md'],
|
||||
frontmatter: {
|
||||
...options.title !== false
|
||||
? {
|
||||
title(title: string, { relativePath }) {
|
||||
if (title)
|
||||
return title
|
||||
const basename = path.basename(relativePath || '', '.md')
|
||||
return basename
|
||||
},
|
||||
} as AutoFrontmatterObject
|
||||
: undefined,
|
||||
...baseFrontmatter,
|
||||
...options.permalink !== false
|
||||
? {
|
||||
permalink(permalink: string, { relativePath }) {
|
||||
if (permalink)
|
||||
return permalink
|
||||
const locale = resolveLocale(relativePath)
|
||||
const prefix = withBase(articlePrefix, locale)
|
||||
|
||||
return normalizePath(`${prefix}/${nanoid()}/`)
|
||||
},
|
||||
} as AutoFrontmatterObject
|
||||
: undefined,
|
||||
},
|
||||
},
|
||||
return normalizePath(`${prefix}/${nanoid()}/`)
|
||||
},
|
||||
} as AutoFrontmatterObject
|
||||
: undefined,
|
||||
},
|
||||
}
|
||||
: '',
|
||||
|
||||
{
|
||||
include: '*',
|
||||
|
||||
@ -35,8 +35,6 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
|
||||
}
|
||||
})
|
||||
|
||||
const blog = options.blog || {}
|
||||
const blogLink = blog.link || '/blog/'
|
||||
entries(options.locales || {}).forEach(([locale, opt]) => {
|
||||
// 注入预设 导航栏
|
||||
// home | blog | tags | archives
|
||||
@ -47,21 +45,25 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
|
||||
text: PRESET_LOCALES[localePath].home,
|
||||
link: locale,
|
||||
}]
|
||||
navbar.push({
|
||||
text: PRESET_LOCALES[localePath].blog,
|
||||
link: withBase(blogLink, locale),
|
||||
})
|
||||
if (blog.tags !== false) {
|
||||
if (options.blog !== false) {
|
||||
const blog = options.blog || {}
|
||||
const blogLink = blog.link || '/blog/'
|
||||
navbar.push({
|
||||
text: PRESET_LOCALES[localePath].tag,
|
||||
link: withBase(blog.tagsLink || `${blogLink}/tags/`, locale),
|
||||
})
|
||||
}
|
||||
if (blog.archives !== false) {
|
||||
navbar.push({
|
||||
text: PRESET_LOCALES[localePath].archive,
|
||||
link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale),
|
||||
text: PRESET_LOCALES[localePath].blog,
|
||||
link: withBase(blogLink, locale),
|
||||
})
|
||||
if (blog.tags !== false) {
|
||||
navbar.push({
|
||||
text: PRESET_LOCALES[localePath].tag,
|
||||
link: withBase(blog.tagsLink || `${blogLink}/tags/`, locale),
|
||||
})
|
||||
}
|
||||
if (blog.archives !== false) {
|
||||
navbar.push({
|
||||
text: PRESET_LOCALES[localePath].archive,
|
||||
link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
themeData.locales![locale].navbar = navbar
|
||||
|
||||
@ -25,6 +25,12 @@ export async function preparedBlogData(
|
||||
localeOptions: PlumeThemeLocaleOptions,
|
||||
encrypt?: PlumeThemeEncrypt,
|
||||
): Promise<void> {
|
||||
if (localeOptions.blog === false) {
|
||||
const content = resolveContent(app, { name: 'blogPostData', content: [] })
|
||||
await writeTemp(app, 'internal/blogData.js', content)
|
||||
return
|
||||
}
|
||||
|
||||
const start = performance.now()
|
||||
|
||||
const blog = localeOptions.blog || {}
|
||||
|
||||
@ -18,6 +18,9 @@ export async function setupPage(
|
||||
app: App,
|
||||
localeOption: PlumeThemeLocaleOptions,
|
||||
) {
|
||||
if (localeOption.blog === false)
|
||||
return
|
||||
|
||||
const pageList: Promise<Page>[] = []
|
||||
const locales = localeOption.locales || {}
|
||||
const rootPath = getRootLangPath(app)
|
||||
|
||||
@ -64,7 +64,7 @@ export interface PlumeThemeLocaleData extends LocaleData {
|
||||
/**
|
||||
* 博客配置
|
||||
*/
|
||||
blog?: PlumeThemeBlog
|
||||
blog?: false | PlumeThemeBlog
|
||||
|
||||
/**
|
||||
* 文章链接前缀
|
||||
@ -274,7 +274,7 @@ export interface PlumeThemeLocaleData extends LocaleData {
|
||||
encryptPlaceholder?: string
|
||||
}
|
||||
|
||||
/** =========================== Avatar ================================ */
|
||||
/** =========================== Profile ================================ */
|
||||
|
||||
/**
|
||||
* 个人资料
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user