feat(theme): add support disable blog

This commit is contained in:
pengzhanbo 2024-07-26 16:46:05 +08:00
parent 8c6604e5af
commit ce544d2dfc
6 changed files with 59 additions and 45 deletions

View File

@ -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

View File

@ -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: '*',

View File

@ -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

View File

@ -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 || {}

View File

@ -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)

View File

@ -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 ================================ */
/**
*