fix: 修复在最小配置下的预设问题 #40

This commit is contained in:
pengzhanbo 2024-01-08 16:05:02 +08:00
parent 981ee99046
commit 2dbbc79a75
6 changed files with 32 additions and 16 deletions

View File

@ -83,7 +83,10 @@ export function watchNotesData(app: App, watchers: any[], options: NotesDataOpti
if (!allOptions.length)
return
const [firstLink, ...links] = allOptions.map(option => option.link)
const [firstLink, ...links] = allOptions.map(option => option.link).filter(Boolean)
if (!firstLink)
return
const dir = path.join('pages', firstLink, '**/*')
const watcher = chokidar.watch(dir, {

View File

@ -25,15 +25,15 @@ const homeStyle = computed(() => {
mask.value
? `linear-gradient(rgba(0, 0, 0, ${mask.value}), rgba(0, 0, 0, ${mask.value}))`
: '',
`url(${withBase(matter.value.banner || '')})`,
`url(${withBase(matter.value.banner ?? 'https://pengzhanbo.cn/images/home-banner.jpg')})`,
]
.filter(Boolean)
.join(','),
}
})
const name = computed(() => matter.value.hero?.name)
const tagline = computed(() => matter.value.hero?.tagline)
const name = computed(() => matter.value.hero?.name ?? 'Plume')
const tagline = computed(() => matter.value.hero?.tagline ?? 'A VuePress Theme')
const text = computed(() => matter.value.hero?.text)
const actions = computed(() => {
@ -44,7 +44,7 @@ const actions = computed(() => {
<template>
<div class="plume-home" :style="homeStyle">
<div class="container">
<div v-if="matter.hero" class="content">
<div class="content">
<h2 v-if="name" class="hero-name">
{{ name }}
</h2>

View File

@ -2,7 +2,7 @@ import type { App } from '@vuepress/core'
import { deepClone, deepMerge } from '@pengzhanbo/utils'
import type { PlumeThemeLocaleOptions } from '../shared/index.js'
import { pathJoin } from './utils.js'
import { resolveLocaleOptions } from './resolveLocaleOptions.js'
import { resolveLocaleOptions, resolvedAppLocales } from './resolveLocaleOptions.js'
const defaultLocales: NonNullable<PlumeThemeLocaleOptions['locales']> = {
'en-US': {
@ -102,8 +102,9 @@ export function mergeLocaleOptions(app: App, options: PlumeThemeLocaleOptions) {
})
const langs: Record<string, string> = {}
Object.keys(app.siteData.locales || {}).forEach((locale) => {
const lang = app.siteData.locales![locale]?.lang || 'en-US'
const siteLocales = resolvedAppLocales(app)
Object.keys(siteLocales).forEach((locale) => {
const lang = siteLocales[locale]?.lang || 'en-US'
langs[locale] = lang
if (defaultLocales[lang]) {
locales[locale] = deepMerge(

View File

@ -1,3 +1,5 @@
import { isEmptyObject } from '@pengzhanbo/utils'
import type { App } from '@vuepress/core'
import type { PlumeThemeLocaleOptions } from '../shared/index.js'
import { normalizePath } from './utils.js'
@ -24,3 +26,11 @@ export function resolveLocaleOptions<
return value ?? (fallback ? fallbackData : undefined)
}
export function resolvedAppLocales(app: App): NonNullable<App['siteData']['locales']> {
if (app.siteData.locales && !isEmptyObject(app.siteData.locales))
return app.siteData.locales
const defaultLang = app.siteData.lang || 'en-US'
return { '/': { lang: defaultLang } }
}

View File

@ -2,6 +2,7 @@ import type { DocsearchPluginOptions } from '@vuepress/plugin-docsearch'
import type { SearchPluginOptions } from '@vuepress/plugin-search'
import type { App } from '@vuepress/core'
import { deepMerge } from '@pengzhanbo/utils'
import { resolvedAppLocales } from './resolveLocaleOptions.js'
// `en-US` is used by default
const defaultDocsearchLocales: NonNullable<DocsearchPluginOptions['locales']> = {
@ -56,8 +57,9 @@ const defaultSearchLocales: NonNullable<SearchPluginOptions['locales']> = {
export function resolvedDocsearchOption(app: App, options: DocsearchPluginOptions): DocsearchPluginOptions {
options.locales ??= {}
Object.keys(app.siteData.locales || {}).forEach((locale) => {
const lang = app.siteData.locales![locale]?.lang || 'en-US'
const locales = resolvedAppLocales(app)
Object.keys(locales).forEach((locale) => {
const lang = locales[locale]?.lang || 'en-US'
if (defaultDocsearchLocales[lang]) {
options.locales![locale] = deepMerge(
{},
@ -72,9 +74,9 @@ export function resolvedDocsearchOption(app: App, options: DocsearchPluginOption
export function resolvedSearchOptions(app: App, options: SearchPluginOptions = {}): SearchPluginOptions {
options.locales ??= {}
Object.keys(app.siteData.locales || {}).forEach((locale) => {
const lang = app.siteData.locales![locale]?.lang || 'en-US'
const locales = resolvedAppLocales(app)
Object.keys(locales).forEach((locale) => {
const lang = locales[locale]?.lang || 'en-US'
if (defaultSearchLocales[lang]) {
options.locales![locale] = deepMerge(
{},

View File

@ -7,13 +7,13 @@ import type {
PlumeThemePageData,
} from '../shared/index.js'
import { pathJoin } from './utils.js'
import { resolveLocaleOptions } from './resolveLocaleOptions.js'
import { resolveLocaleOptions, resolvedAppLocales } from './resolveLocaleOptions.js'
export async function setupPage(
app: App,
localeOption: PlumeThemeLocaleOptions,
) {
const locales = app.siteData.locales || {}
const locales = resolvedAppLocales(app)
const defaultBlog = resolveLocaleOptions(localeOption, 'blog')
for (const [, locale] of Object.keys(locales).entries()) {
const blog = resolveLocaleOptions(localeOption, 'blog', locale, false)
@ -82,7 +82,7 @@ export function autoCategory(
const pagePath = page.filePathRelative
if (page.frontmatter.type || !pagePath)
return
const locales = Object.keys(app.siteData.locales)
const locales = Object.keys(resolvedAppLocales(app))
const notesLinks: string[] = []
for (const [, locale] of locales.entries()) {
const notes = options.locales?.[locale]?.notes