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) const { notFound, path } = resolveRoute(targetPath)
if (!notFound) if (!notFound)
return path return path
const blog = theme.value.blog const blog = theme.value.blog
if (isBlogPost.value) if (isBlogPost.value && blog !== false)
return withBase(blog?.link || normalizeLink(locale, 'blog/')) return withBase(blog?.link || normalizeLink(locale, 'blog/'))
const sidebarList = sidebar.value const sidebarList = sidebar.value

View File

@ -194,7 +194,8 @@ export function resolveOptions(
include: '**/{readme,README,index}.md', include: '**/{readme,README,index}.md',
frontmatter: {}, frontmatter: {},
}, },
{ localeOptions.blog !== false
? {
include: localeOptions.blog?.include ?? ['**/*.md'], include: localeOptions.blog?.include ?? ['**/*.md'],
frontmatter: { frontmatter: {
...options.title !== false ...options.title !== false
@ -221,7 +222,8 @@ export function resolveOptions(
} as AutoFrontmatterObject } as AutoFrontmatterObject
: undefined, : undefined,
}, },
}, }
: '',
{ {
include: '*', 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]) => { entries(options.locales || {}).forEach(([locale, opt]) => {
// 注入预设 导航栏 // 注入预设 导航栏
// home | blog | tags | archives // home | blog | tags | archives
@ -47,6 +45,9 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
text: PRESET_LOCALES[localePath].home, text: PRESET_LOCALES[localePath].home,
link: locale, link: locale,
}] }]
if (options.blog !== false) {
const blog = options.blog || {}
const blogLink = blog.link || '/blog/'
navbar.push({ navbar.push({
text: PRESET_LOCALES[localePath].blog, text: PRESET_LOCALES[localePath].blog,
link: withBase(blogLink, locale), link: withBase(blogLink, locale),
@ -63,6 +64,7 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale), link: withBase(blog.archivesLink || `${blogLink}/archives/`, locale),
}) })
} }
}
themeData.locales![locale].navbar = navbar themeData.locales![locale].navbar = navbar
} }

View File

@ -25,6 +25,12 @@ export async function preparedBlogData(
localeOptions: PlumeThemeLocaleOptions, localeOptions: PlumeThemeLocaleOptions,
encrypt?: PlumeThemeEncrypt, encrypt?: PlumeThemeEncrypt,
): Promise<void> { ): 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 start = performance.now()
const blog = localeOptions.blog || {} const blog = localeOptions.blog || {}

View File

@ -18,6 +18,9 @@ export async function setupPage(
app: App, app: App,
localeOption: PlumeThemeLocaleOptions, localeOption: PlumeThemeLocaleOptions,
) { ) {
if (localeOption.blog === false)
return
const pageList: Promise<Page>[] = [] const pageList: Promise<Page>[] = []
const locales = localeOption.locales || {} const locales = localeOption.locales || {}
const rootPath = getRootLangPath(app) 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 encryptPlaceholder?: string
} }
/** =========================== Avatar ================================ */ /** =========================== Profile ================================ */
/** /**
* *