Skip to content

Commit 74e4950

Browse files
authored
feat: allow adding custom social icons as inline svg (#738) (#953)
1 parent ad9af83 commit 74e4950

File tree

12 files changed

+42
-69
lines changed

12 files changed

+42
-69
lines changed

docs/config/theme-configs.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ interface SidebarItem {
130130
}
131131
```
132132

133-
134133
## outlineTitle
135134

136135
- Type: `string`
@@ -148,7 +147,7 @@ export default {
148147

149148
## socialLinks
150149

151-
- Type: `SocialLink`
150+
- Type: `SocialLink[]`
152151

153152
You may define this option to show your social account links with icons in nav.
154153

@@ -158,7 +157,13 @@ export default {
158157
socialLinks: [
159158
{ icon: 'github', link: 'https://github.com/vuejs/vitepress' },
160159
{ icon: 'twitter', link: '...' },
161-
{ icon: 'discord', link: '...' }
160+
// You can also add custom icons by passing SVG as string:
161+
{
162+
icon: {
163+
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Dribbble</title><path d="M12...6.38z"/></svg>'
164+
},
165+
link: '...'
166+
}
162167
]
163168
}
164169
}
@@ -179,6 +184,7 @@ type SocialLinkIcon =
179184
| 'slack'
180185
| 'twitter'
181186
| 'youtube'
187+
| { svg: string }
182188
```
183189
184190
## footer

src/client/theme-default/components/VPSocialLink.vue

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,27 @@
11
<script lang="ts" setup>
22
import type { DefaultTheme } from 'vitepress/theme'
3-
import VPIconDiscord from './icons/VPIconDiscord.vue'
4-
import VPIconFacebook from './icons/VPIconFacebook.vue'
5-
import VPIconGitHub from './icons/VPIconGitHub.vue'
6-
import VPIconLinkedIn from './icons/VPIconLinkedIn.vue'
7-
import VPIconInstagram from './icons/VPIconInstagram.vue'
8-
import VPIconSlack from './icons/VPIconSlack.vue'
9-
import VPIconTwitter from './icons/VPIconTwitter.vue'
10-
import VPIconYouTube from './icons/VPIconYouTube.vue'
3+
import { computed } from 'vue'
4+
import { icons } from '../support/socialIcons'
115
12-
defineProps<{
6+
const props = defineProps<{
137
icon: DefaultTheme.SocialLinkIcon
148
link: string
159
}>()
1610
17-
const icons = {
18-
discord: VPIconDiscord,
19-
facebook: VPIconFacebook,
20-
github: VPIconGitHub,
21-
instagram: VPIconInstagram,
22-
linkedin: VPIconLinkedIn,
23-
slack: VPIconSlack,
24-
twitter: VPIconTwitter,
25-
youtube: VPIconYouTube
26-
}
11+
const svg = computed(() => {
12+
if (typeof props.icon === 'object') return props.icon.svg
13+
return icons[props.icon]
14+
})
2715
</script>
2816

2917
<template>
3018
<a
3119
class="VPSocialLink"
3220
:href="link"
33-
:title="icon"
3421
target="_blank"
35-
rel="noreferrer"
22+
rel="noopener"
23+
v-html="svg"
3624
>
37-
<component :is="icons[icon]" class="icon" />
38-
<span class="visually-hidden">{{ icon }}</span>
3925
</a>
4026
</template>
4127

@@ -47,15 +33,15 @@ const icons = {
4733
width: 36px;
4834
height: 36px;
4935
color: var(--vp-c-text-2);
50-
transition: color .5s;
36+
transition: color 0.5s;
5137
}
5238
5339
.VPSocialLink:hover {
5440
color: var(--vp-c-text-1);
55-
transition: color .25s;
41+
transition: color 0.25s;
5642
}
5743
58-
.icon {
44+
.VPSocialLink > :deep(svg) {
5945
width: 20px;
6046
height: 20px;
6147
fill: currentColor;

src/client/theme-default/components/icons/VPIconDiscord.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconFacebook.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconGitHub.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconInstagram.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconLinkedIn.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconSlack.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconTwitter.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/client/theme-default/components/icons/VPIconYouTube.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)