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)
|
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
|
||||||
|
|||||||
@ -194,34 +194,36 @@ export function resolveOptions(
|
|||||||
include: '**/{readme,README,index}.md',
|
include: '**/{readme,README,index}.md',
|
||||||
frontmatter: {},
|
frontmatter: {},
|
||||||
},
|
},
|
||||||
{
|
localeOptions.blog !== false
|
||||||
include: localeOptions.blog?.include ?? ['**/*.md'],
|
? {
|
||||||
frontmatter: {
|
include: localeOptions.blog?.include ?? ['**/*.md'],
|
||||||
...options.title !== false
|
frontmatter: {
|
||||||
? {
|
...options.title !== false
|
||||||
title(title: string, { relativePath }) {
|
? {
|
||||||
if (title)
|
title(title: string, { relativePath }) {
|
||||||
return title
|
if (title)
|
||||||
const basename = path.basename(relativePath || '', '.md')
|
return title
|
||||||
return basename
|
const basename = path.basename(relativePath || '', '.md')
|
||||||
},
|
return basename
|
||||||
} as AutoFrontmatterObject
|
},
|
||||||
: undefined,
|
} as AutoFrontmatterObject
|
||||||
...baseFrontmatter,
|
: undefined,
|
||||||
...options.permalink !== false
|
...baseFrontmatter,
|
||||||
? {
|
...options.permalink !== false
|
||||||
permalink(permalink: string, { relativePath }) {
|
? {
|
||||||
if (permalink)
|
permalink(permalink: string, { relativePath }) {
|
||||||
return permalink
|
if (permalink)
|
||||||
const locale = resolveLocale(relativePath)
|
return permalink
|
||||||
const prefix = withBase(articlePrefix, locale)
|
const locale = resolveLocale(relativePath)
|
||||||
|
const prefix = withBase(articlePrefix, locale)
|
||||||
|
|
||||||
return normalizePath(`${prefix}/${nanoid()}/`)
|
return normalizePath(`${prefix}/${nanoid()}/`)
|
||||||
},
|
},
|
||||||
} as AutoFrontmatterObject
|
} as AutoFrontmatterObject
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
|
: '',
|
||||||
|
|
||||||
{
|
{
|
||||||
include: '*',
|
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]) => {
|
entries(options.locales || {}).forEach(([locale, opt]) => {
|
||||||
// 注入预设 导航栏
|
// 注入预设 导航栏
|
||||||
// home | blog | tags | archives
|
// home | blog | tags | archives
|
||||||
@ -47,21 +45,25 @@ export function resolveThemeData(app: App, options: PlumeThemeLocaleOptions): Pl
|
|||||||
text: PRESET_LOCALES[localePath].home,
|
text: PRESET_LOCALES[localePath].home,
|
||||||
link: locale,
|
link: locale,
|
||||||
}]
|
}]
|
||||||
navbar.push({
|
if (options.blog !== false) {
|
||||||
text: PRESET_LOCALES[localePath].blog,
|
const blog = options.blog || {}
|
||||||
link: withBase(blogLink, locale),
|
const blogLink = blog.link || '/blog/'
|
||||||
})
|
|
||||||
if (blog.tags !== false) {
|
|
||||||
navbar.push({
|
navbar.push({
|
||||||
text: PRESET_LOCALES[localePath].tag,
|
text: PRESET_LOCALES[localePath].blog,
|
||||||
link: withBase(blog.tagsLink || `${blogLink}/tags/`, locale),
|
link: withBase(blogLink, locale),
|
||||||
})
|
|
||||||
}
|
|
||||||
if (blog.archives !== false) {
|
|
||||||
navbar.push({
|
|
||||||
text: PRESET_LOCALES[localePath].archive,
|
|
||||||
link: withBase(blog.archivesLink || `${blogLink}/archives/`, 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
|
themeData.locales![locale].navbar = navbar
|
||||||
|
|||||||
@ -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 || {}
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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 ================================ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 个人资料
|
* 个人资料
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user