diff --git a/docs/2.preview/主题效果预览.md b/docs/2.preview/主题效果预览.md index 49bc5efd..cde5a7c8 100644 --- a/docs/2.preview/主题效果预览.md +++ b/docs/2.preview/主题效果预览.md @@ -100,8 +100,8 @@ H~2~O **图标:** - home - -- vscode - -- twitter - +- vscode - +- twitter - **demo wrapper:** diff --git a/docs/notes/theme/config/frontmatter/basic.md b/docs/notes/theme/config/frontmatter/basic.md index 96052ff0..24a5ec83 100644 --- a/docs/notes/theme/config/frontmatter/basic.md +++ b/docs/notes/theme/config/frontmatter/basic.md @@ -56,16 +56,6 @@ permalink: /config/frontmatter/basic/ 主题会在文件创建时,自动填充 当前文件名作为 文章标题。 -### author - -- 类型: `string` -- 默认值: `''` -- 详情: - - 文章作者。 - - 主题会在文件创建时,自动填充 `avatar.name || packageJson.author` 作为 文章作者。 - ### createTime - 类型: `string` @@ -186,11 +176,13 @@ permalink: /config/frontmatter/basic/ ### contributors - 类型: `boolean` -- 默认值: `true` +- 默认值: `true | string | string[]` - 详情: 当前文章是否 显示 贡献者。 贡献者 根据 git 提交者自动填充。 + 如果您的文章来源于第三方, git 提交不能完整列出所有的作者,您可以在此处补充贡献者。 + ### editLink - 类型: `boolean` diff --git a/docs/notes/theme/guide/博客.md b/docs/notes/theme/guide/博客.md index 808189c3..332a5ca3 100644 --- a/docs/notes/theme/guide/博客.md +++ b/docs/notes/theme/guide/博客.md @@ -69,14 +69,13 @@ export default defineUserConfig({ --- title: 文章标题 createTime: 2024/01/01 00:00:00 -author: your name tags: - tag1 - tag2 --- ``` -其中,`title` / `createTime` / `author` 会在新建 md 文件时由主题自动填充,你可以随意修改它们。 +其中,`title` / `createTime` 会在新建 md 文件时由主题自动填充,你可以随意修改它们。 以下是在 博客文章中可用的 `frontmatter` 属性。 @@ -84,7 +83,6 @@ tags: | ---------- | ------------------- | --------------------------- | -------------------------------------------- | | title | `string` | 默认自动填入文件名 | 文章标题 | | createTime | `string` | 当前时间 | 文章创建时间 | -| author | `string` | 默认自动填入 `profile.name` | 文章作者 | | tags | `string[]` | `[]` | 文章标签 | | sticky | `boolean \| number` | false | 是否置顶, 如果为数字,则数字越大,置顶越靠前 | | draft | `boolean` | false | 是否为草稿,草稿文章不会被展示 | diff --git a/theme/src/client/components/VPDocFooter.vue b/theme/src/client/components/VPDocFooter.vue index fac0cdc8..6449877b 100644 --- a/theme/src/client/components/VPDocFooter.vue +++ b/theme/src/client/components/VPDocFooter.vue @@ -21,9 +21,7 @@ const hasEditLink = computed(() => const hasLastUpdated = computed(() => Boolean(theme.value.lastUpdated && frontmatter.value.lastUpdated !== false && lastUpdated.value), ) -const hasContributors = computed(() => - Boolean(theme.value.contributors && frontmatter.value.contributors !== false && contributors.value?.length), -) +const hasContributors = computed(() => Boolean(contributors.value.length)) const showFooter = computed(() => { return hasEditLink.value @@ -62,8 +60,8 @@ const showFooter = computed(() => { diff --git a/theme/src/client/components/VPDocMeta.vue b/theme/src/client/components/VPDocMeta.vue index 5a313628..ed298519 100644 --- a/theme/src/client/components/VPDocMeta.vue +++ b/theme/src/client/components/VPDocMeta.vue @@ -59,10 +59,10 @@ const hasMeta = computed(() => readingTime.value.time || tags.value.length || cr {{ page.title }}
-

+

{{ readingTime.words }} diff --git a/theme/src/client/composables/contributors.ts b/theme/src/client/composables/contributors.ts index 7a8c98e7..5eb13266 100644 --- a/theme/src/client/composables/contributors.ts +++ b/theme/src/client/composables/contributors.ts @@ -1,20 +1,20 @@ import { computed } from 'vue' import type { ComputedRef } from 'vue' -import type { PlumeThemePageData } from '../../shared/index.js' import { useData } from '../composables/data.js' +import { toArray } from '../utils/index.js' -export function useContributors(): ComputedRef< - null | Required['contributors'] -> { +export function useContributors(): ComputedRef { const { theme, page, frontmatter } = useData() return computed(() => { - const showContributors - = frontmatter.value.contributors ?? theme.value.contributors ?? true + const config = frontmatter.value.contributors ?? theme.value.contributors ?? true - if (!showContributors) - return null + if (config === false) + return [] - return page.value.git?.contributors ?? null + const contributors = config === true ? [] : toArray(config) + const gitContributors = (page.value.git?.contributors ?? []).map(({ name }) => name) + + return Array.from(new Set([...gitContributors, ...contributors])) }) } diff --git a/theme/src/node/autoFrontmatter/resolveOptions.ts b/theme/src/node/autoFrontmatter/resolveOptions.ts index 35947d59..3b47f548 100644 --- a/theme/src/node/autoFrontmatter/resolveOptions.ts +++ b/theme/src/node/autoFrontmatter/resolveOptions.ts @@ -12,7 +12,6 @@ import type { } from '../../shared/index.js' import { getCurrentDirname, - getPackage, nanoid, normalizePath, pathJoin, @@ -24,8 +23,7 @@ export function resolveOptions( localeOptions: PlumeThemeLocaleOptions, options: AutoFrontmatter, ): AutoFrontmatter { - const pkg = getPackage() - const { locales = {}, article: articlePrefix = '/article/' } = localeOptions + const { article: articlePrefix = '/article/' } = localeOptions const resolveLocale = (relativeFilepath: string) => { const file = ensureLeadingSlash(relativeFilepath) @@ -33,11 +31,6 @@ export function resolveOptions( return resolveLocalePath(localeOptions.locales!, file) } - const resolveOptions = (relativeFilepath: string) => { - const locale = resolveLocale(relativeFilepath) - return locales[locale] || localeOptions - } - const notesList = resolveNotesOptions(localeOptions) const localesNotesDirs = uniq(notesList .flatMap(({ notes, dir }) => @@ -46,18 +39,6 @@ export function resolveOptions( const baseFrontmatter: AutoFrontmatterObject = {} - if (options.author !== false) { - baseFrontmatter.author = (author: string, { relativePath }, data) => { - if (author) - return author - if (data.friends || data.pageLayout === 'friends') - return - const profile = resolveOptions(relativePath).profile ?? resolveOptions(relativePath).avatar - - return profile?.name || pkg.author || '' - } - } - if (options.createTime !== false) { baseFrontmatter.createTime = (formatTime: string, { createTime }, data) => { if (formatTime) diff --git a/theme/src/node/plugins/getPlugins.ts b/theme/src/node/plugins/getPlugins.ts index 9bae6cfe..128b608c 100644 --- a/theme/src/node/plugins/getPlugins.ts +++ b/theme/src/node/plugins/getPlugins.ts @@ -69,13 +69,13 @@ export function getPlugins({ plugins.push(nprogressPlugin()) } - if (pluginOptions.git ?? isProd) { - plugins.push(gitPlugin({ - createdTime: false, - updatedTime: true, - contributors: true, - })) - } + // if (pluginOptions.git ?? isProd) { + plugins.push(gitPlugin({ + createdTime: true, + updatedTime: true, + contributors: true, + })) + // } if (pluginOptions.photoSwipe !== false) { plugins.push(photoSwipePlugin({ diff --git a/theme/src/shared/auto-frontmatter.ts b/theme/src/shared/auto-frontmatter.ts index 924a1987..597b8cea 100644 --- a/theme/src/shared/auto-frontmatter.ts +++ b/theme/src/shared/auto-frontmatter.ts @@ -51,6 +51,8 @@ export interface AutoFrontmatter { * 是否自动生成 author * * 默认读取 `profile.name` 或 `package.json` 的 `author` + * + * @deprecated 不再默认生成 `author`, 该配置已废弃 */ author?: boolean /** diff --git a/theme/src/shared/frontmatter/page.ts b/theme/src/shared/frontmatter/page.ts index 9baaa16e..763422d6 100644 --- a/theme/src/shared/frontmatter/page.ts +++ b/theme/src/shared/frontmatter/page.ts @@ -25,7 +25,7 @@ export interface PlumeThemePageFrontmatter extends PlumeNormalFrontmatter { /** * 是否显示贡献者 */ - contributors?: boolean + contributors?: boolean | string | string[] /** * 上一篇 */