feat(theme): remove frontmatter.author, and improve frontmatter.contributors type
This commit is contained in:
parent
1358f77b50
commit
7832a9b13c
@ -100,8 +100,8 @@ H~2~O
|
||||
**图标:**
|
||||
|
||||
- home - <Icon name="material-symbols:home" color="currentColor" size="1em" />
|
||||
- vscode - <Iconify name="skill-icons:vscode-dark" size="2em" />
|
||||
- twitter - <Iconify name="skill-icons:twitter" size="2em" />
|
||||
- vscode - <Icon name="skill-icons:vscode-dark" size="2em" />
|
||||
- twitter - <Icon name="skill-icons:twitter" size="2em" />
|
||||
|
||||
**demo wrapper:**
|
||||
|
||||
|
||||
@ -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`
|
||||
|
||||
@ -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 | 是否为草稿,草稿文章不会被展示 |
|
||||
|
||||
@ -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(() => {
|
||||
</span>
|
||||
<span class="contributors-info">
|
||||
<template v-for="(contributor, index) in contributors" :key="contributor">
|
||||
<span class="contributor" :title="`email: ${contributor.email}`">
|
||||
{{ contributor.name }}
|
||||
<span class="contributor">
|
||||
{{ contributor }}
|
||||
</span>
|
||||
<template v-if="index !== contributors.length - 1">, </template>
|
||||
</template>
|
||||
|
||||
@ -59,10 +59,10 @@ const hasMeta = computed(() => readingTime.value.time || tags.value.length || cr
|
||||
{{ page.title }}
|
||||
</h1>
|
||||
<div v-if="hasMeta" class="vp-doc-meta">
|
||||
<p v-if="matter.author" class="author">
|
||||
<!-- <p v-if="matter.author" class="author">
|
||||
<span class="icon vpi-user" />
|
||||
<span>{{ matter.author }}</span>
|
||||
</p>
|
||||
</p> -->
|
||||
<p v-if="readingTime.time && matter.readingTime !== false" class="reading-time">
|
||||
<span class="vpi-books icon" />
|
||||
<span>{{ readingTime.words }}</span>
|
||||
|
||||
@ -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<PlumeThemePageData['git']>['contributors']
|
||||
> {
|
||||
export function useContributors(): ComputedRef<string[]> {
|
||||
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]))
|
||||
})
|
||||
}
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -51,6 +51,8 @@ export interface AutoFrontmatter {
|
||||
* 是否自动生成 author
|
||||
*
|
||||
* 默认读取 `profile.name` 或 `package.json` 的 `author`
|
||||
*
|
||||
* @deprecated 不再默认生成 `author`, 该配置已废弃
|
||||
*/
|
||||
author?: boolean
|
||||
/**
|
||||
|
||||
@ -25,7 +25,7 @@ export interface PlumeThemePageFrontmatter extends PlumeNormalFrontmatter {
|
||||
/**
|
||||
* 是否显示贡献者
|
||||
*/
|
||||
contributors?: boolean
|
||||
contributors?: boolean | string | string[]
|
||||
/**
|
||||
* 上一篇
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user