forked from nuxt/devtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SocialPreviewGroup.vue
57 lines (52 loc) · 1.67 KB
/
SocialPreviewGroup.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script setup lang="ts">
import type { NormalizedHeadTag, SocialPreviewResolved } from '../../../src/types'
const props = defineProps<{
tags: NormalizedHeadTag[]
}>()
const types = [
'twitter',
'facebook',
'linkedin',
]
const selected = ref(types[0])
const card = computed((): SocialPreviewResolved => {
return {
url: window.location.host,
title: props.tags.find(tag => tag.tag === 'title')?.value,
image: props.tags.find(tag => tag.tag === 'meta' && tag.name === 'og:image')?.value,
imageAlt: props.tags.find(tag => tag.tag === 'meta' && tag.name === 'og:image:alt')?.value,
description: props.tags.find(tag => tag.tag === 'meta' && tag.name === 'og:description')?.value,
favicon: props.tags.find(tag => tag.tag === 'link' && tag.name === 'icon')?.value,
}
})
</script>
<template>
<div h-full w-max flex="~ col">
<div flex="~ wrap" w-full flex-none>
<template v-for="name, idx of types" :key="idx">
<button
px4 py2 border="r base"
hover="bg-active"
:class="name === selected ? '' : 'border-b'"
@click="selected = name"
>
<div :class="name === selected ? '' : 'op30' " capitalize>
{{ name }}
</div>
</button>
</template>
<div border="b base" flex-auto />
</div>
<div flex="~ items-center justify-center" flex-auto p4>
<div v-if="selected === 'facebook'">
<SocialFacebook :card="card" />
</div>
<div v-else-if="selected === 'twitter'">
<SocialTwitter :tags="tags" />
</div>
<div v-else-if="selected === 'linkedin'">
<SocialLinkedin :card="card" />
</div>
</div>
</div>
</template>