Skip to content

Commit

Permalink
feat: 添加自定义版权区内组织名的功能 (#7)
Browse files Browse the repository at this point in the history
- 优先级为:文章配置 > 站点配置 > 默认配置
  • Loading branch information
Lee authored Oct 12, 2024
1 parent c0944fc commit ac4a223
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/CopyrightInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { ref, watch, computed } from 'vue'
import { useRoute } from 'vitepress' // 获取路由信息
import type { Node, Trie } from '../plugins/CopyrightLoader.data'
import { data } from '../plugins/CopyrightLoader.data'
import { useData } from 'vitepress';
const orgName = useData().theme.value.org;
// 初始化需要更新的变量
const attrs = ref<Record<string, any> | null>(null)
Expand Down Expand Up @@ -63,7 +66,19 @@ watch(
<a v-if="attrs?.copyright?.url" :href="attrs.copyright.url">{{ displayAuthors }}</a>
<span v-else>{{ displayAuthors }}</span>
<span> 创作</span>
<span v-if="attrs?.copyright?.license">
<span v-if="attrs?.copyright?.org">
,{{ attrs.copyright.org }} 在
<a v-if="attrs?.copyright?.licenseUrl" :href="attrs.copyright.licenseUrl">{{ attrs.copyright.license }}</a>
<span v-else>{{ attrs.copyright.license }}</span>
许可下使用
</span>
<span v-else-if="orgName">
,{{ orgName }} 在
<a v-if="attrs?.copyright?.licenseUrl" :href="attrs.copyright.licenseUrl">{{ attrs.copyright.license }}</a>
<span v-else>{{ attrs.copyright.license }}</span>
许可下使用
</span>
<span v-else-if="attrs?.copyright?.license">
,Project Trans 在
<a v-if="attrs?.copyright?.licenseUrl" :href="attrs.copyright.licenseUrl">{{ attrs.copyright.license }}</a>
<span v-else>{{ attrs.copyright.license }}</span>
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function genConfig() {
enableChangeLog = true,
enableSuggestionBox = true,
sitePattern,
org,
} = themeConfig
return defineConfigWithTheme<PjtsThemeConfig>({
lang: 'zh-CN',
Expand Down Expand Up @@ -106,6 +107,7 @@ function genConfig() {
['meta', { property: 'og:site_name', content: siteTitle }],
],
themeConfig: {
org,
enableSuggestionBox,
enableChangeLog,
// https://vitepress.dev/reference/default-theme-config
Expand Down
1 change: 1 addition & 0 deletions src/utils/themeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ThemeContext {
enableSuggestionBox?: boolean
enableChangeLog?: boolean
sitePattern?: string
org?: string
}

const themeContext = new AsyncLocalStorage<ThemeContext>()
Expand Down

0 comments on commit ac4a223

Please sign in to comment.