refactor(theme): render VPSocialLink through VPIcon

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
pull/5407/head
Divyansh Singh 2 weeks ago
parent fbe364633d
commit dac6c723b0

@ -3,11 +3,6 @@ import { useIcon } from 'vitepress'
import { useTemplateRef } from 'vue' import { useTemplateRef } from 'vue'
const props = defineProps<{ const props = defineProps<{
/**
* A fully qualified `collection:name` for any `@iconify-json/*`
* collection in the project's dependencies (e.g. `simple-icons:github`,
* `lucide:rocket`), or a raw `{ svg }` string.
*/
icon: string | { svg: string } icon: string | { svg: string }
}>() }>()

@ -1,9 +1,9 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useIcon } from 'vitepress'
import type { DefaultTheme } from 'vitepress/theme' import type { DefaultTheme } from 'vitepress/theme'
import { useTemplateRef } from 'vue' import { computed } from 'vue'
import { isExternal } from '../../shared' import { isExternal } from '../../shared'
import VPIcon from './VPIcon.vue'
const props = defineProps<{ const props = defineProps<{
icon: DefaultTheme.SocialLinkIcon icon: DefaultTheme.SocialLinkIcon
@ -13,16 +13,10 @@ const props = defineProps<{
me: boolean me: boolean
}>() }>()
const el = useTemplateRef('el') const qualifiedIcon = computed(() =>
typeof props.icon === 'string' && !props.icon.includes(':')
// socialLinks accepts bare simple-icons names; everything downstream ? `simple-icons:${props.icon}`
// speaks fully qualified `collection:name` : props.icon
const iconClass = useIcon(
() =>
typeof props.icon === 'string' && !props.icon.includes(':')
? `simple-icons:${props.icon}`
: props.icon,
el
) )
</script> </script>
@ -34,8 +28,7 @@ const iconClass = useIcon(
:target="target ?? (isExternal(link) ? '_blank' : undefined)" :target="target ?? (isExternal(link) ? '_blank' : undefined)"
:rel="me ? 'me noopener' : 'noopener'" :rel="me ? 'me noopener' : 'noopener'"
> >
<span v-if="typeof icon === 'object'" v-html="icon.svg"></span> <VPIcon :icon="qualifiedIcon" />
<span v-else ref="el" :class="iconClass"></span>
</a> </a>
</template> </template>
@ -58,12 +51,11 @@ const iconClass = useIcon(
.VPSocialLink > :deep(span) { .VPSocialLink > :deep(span) {
/* keeps a nested custom svg centered instead of baseline-aligned */ /* keeps a nested custom svg centered instead of baseline-aligned */
display: flex; display: flex;
}
.VPSocialLink :deep(svg),
.VPSocialLink > :deep([class^='vpi-']) {
width: 1.25rem; width: 1.25rem;
height: 1.25rem; height: 1.25rem;
}
.VPSocialLink :deep(svg) {
fill: currentColor; fill: currentColor;
} }
</style> </style>

Loading…
Cancel
Save