feat(theme): add support for author and creation in global copyright config, close #573 (#576)

This commit is contained in:
pengzhanbo 2025-04-28 10:53:48 +08:00 committed by GitHub
parent 729a0cbd40
commit 7ecce2db5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 4 deletions

View File

@ -91,7 +91,12 @@ export default defineUserConfig({
license: { license: {
name: 'MIT', // 许可证名称 name: 'MIT', // 许可证名称
url: 'https://your-license-url' // 许可证地址 url: 'https://your-license-url' // 许可证地址
} },
author: {
name: 'Your Name', // 版权所有者名称
url: 'https://your-author-url' // 版权所有者地址
},
creation: 'reprint' // 创作方式
} }
}) })
}) })
@ -116,12 +121,24 @@ export type CopyrightLicense =
*/ */
type CopyrightOptions = boolean | string | CopyrightLicense | { type CopyrightOptions = boolean | string | CopyrightLicense | {
/** /**
* 许可证 * 版权许可证
*/ */
license: CopyrightLicense | { license?: CopyrightLicense | {
name: CopyrightLicense | string name: CopyrightLicense | string
url: string url: string
} }
/**
* 版权所有者,未配置时,默认从 git 提交记录中获取
*/
author?: {
name: string
url?: string
}
/**
* 创作方式,原创、翻译、转载
* @default 'original'
*/
creation?: 'original' | 'translate' | 'reprint'
} }
``` ```

View File

@ -15,6 +15,7 @@ const copyright = computed<CopyrightFrontmatter | null>(() => {
const docCopyright = (isPlainObject(frontmatter.value.copyright) const docCopyright = (isPlainObject(frontmatter.value.copyright)
? frontmatter.value.copyright ? frontmatter.value.copyright
: { license: frontmatter.value.copyright === true ? '' : frontmatter.value.copyright }) as CopyrightFrontmatter : { license: frontmatter.value.copyright === true ? '' : frontmatter.value.copyright }) as CopyrightFrontmatter
if (!theme.value.copyright) if (!theme.value.copyright)
return docCopyright return docCopyright
@ -23,6 +24,8 @@ const copyright = computed<CopyrightFrontmatter | null>(() => {
: { license: theme.value.copyright === true ? undefined : theme.value.copyright }) as CopyrightOptions : { license: theme.value.copyright === true ? undefined : theme.value.copyright }) as CopyrightOptions
docCopyright.license ??= themeCopyright.license docCopyright.license ??= themeCopyright.license
docCopyright.author ??= themeCopyright.author
docCopyright.creation ??= themeCopyright.creation
return docCopyright return docCopyright
}) })

View File

@ -29,4 +29,12 @@ export interface CopyrightOptions {
* @default 'CC-BY-4.0' * @default 'CC-BY-4.0'
*/ */
license?: CopyrightLicense | { name: string, url: string } license?: CopyrightLicense | { name: string, url: string }
/**
*
*/
author?: string | { name: string, url?: string }
/**
*
*/
creation?: 'original' | 'translate' | 'reprint'
} }

View File

@ -51,7 +51,6 @@ export interface CopyrightFrontmatter extends CopyrightOptions {
/** /**
* *
* *
* contributors
* @default '' * @default ''
*/ */
author?: string | { name: string, url?: string } author?: string | { name: string, url?: string }