Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(theme): add attr name for navbar social icon #249

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/notes/theme/config/主题配置.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,19 @@ export default {
- `'douban'`
- `'steam'`
- `'xbox'`
- `{ svg: string }`: 自定义图标,传入 svg 字符串
- `{ svg: string, name?: string }`: 自定义图标,传入 svg 源码字符串,可选 `name` 字段,用于配置 [`navbarSocialInclude`](#navbarsocialinclude)

示例:

``` ts
``` ts :no-line-numbers
export default {
theme: plumeTheme({
social: [
{ icon: 'github', link: 'https://github.com/zhangsan' }
{ icon: 'github', link: 'https://github.com/zhangsan' },
{
icon: { svg: '<svg>xxxxx</svg>', name: 'xxx' },
link: 'https://xxx.com'
},
]
})
}
Expand All @@ -364,6 +368,8 @@ export default {
允许显示在导航栏的社交链接。
该配置仅在 PC 端下有效。

如果 [`social`](#social) 配置为 `{ svg: string, name: string}` 则可将 `name` 作为 `navbarSocialInclude` 的值。

### navbar

- 类型: `NavItem[]`
Expand Down
10 changes: 7 additions & 3 deletions theme/src/client/components/Nav/VPNavBarExtra.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ const social = computed(() => {
if (!includes.length)
return theme.value.social

return theme.value.social?.filter(
({ icon }) => typeof icon === 'string' && includes.includes(icon),
)
return theme.value.social?.filter(({ icon }) => {
if (typeof icon === 'string')
return includes.includes(icon)
if (icon.name)
return includes.includes(icon.name)
return false
})
})

const hasExtraContent = computed(
Expand Down
10 changes: 7 additions & 3 deletions theme/src/client/components/Nav/VPNavBarSocialLinks.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ const social = computed(() => {
if (!includes.length)
return theme.value.social

return theme.value.social?.filter(
({ icon }) => typeof icon === 'string' && includes.includes(icon),
)
return theme.value.social?.filter(({ icon }) => {
if (typeof icon === 'string')
return includes.includes(icon)
if (icon.name)
return includes.includes(icon.name)
return false
})
})
</script>

Expand Down
2 changes: 1 addition & 1 deletion theme/src/shared/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type SocialLinkIconUnion =
| 'stackoverflow'
| 'xbox'

export type SocialLinkIcon = SocialLinkIconUnion | { svg: string }
export type SocialLinkIcon = SocialLinkIconUnion | { svg: string, name?: string }

export interface PresetLocale {
home: string
Expand Down
2 changes: 1 addition & 1 deletion theme/src/shared/options/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface PlumeThemeLocaleData extends LocaleData {
* 允许显示在导航栏的社交类型
* @default - ['github', 'twitter', 'discord', 'facebook']
*/
navbarSocialInclude?: SocialLinkIconUnion[]
navbarSocialInclude?: (SocialLinkIconUnion | (string & { zz_IGNORE_ME?: never }))[]

/**
* 博客配置
Expand Down