/
OpenGraphMissingTabs.vue
141 lines (128 loc) · 3.97 KB
/
OpenGraphMissingTabs.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<script setup lang="ts">
import { defu } from 'defu'
import type { ReactiveHead } from '@unhead/vue'
import type { MetaFlatInput } from '@uhead/schema'
import type { NormalizedHeadTag } from '../../src/types'
import { ogTags } from '../data/open-graph'
const props = defineProps<{
tags: NormalizedHeadTag[]
matchedRouteFilepath?: string
}>()
const missingTags = computed(() => {
return ogTags.filter(define => !props.tags?.some(tag => tag.name === define.name))
})
const codeSnippet = computed(() => {
let mergedHeadOptions: Partial<ReactiveHead> = {}
const mergedSeoMetaOptions: Partial<MetaFlatInput> = {}
missingTags.value
.forEach((tag) => {
if (tag.seoMeta)
Object.assign(mergedSeoMetaOptions, tag.seoMeta)
else
mergedHeadOptions = defu(mergedHeadOptions, tag.head)
})
const lines = []
if (Object.keys(mergedSeoMetaOptions).length) {
const body = JSON.stringify(mergedSeoMetaOptions, null, 2)
.replace(/"([^"]+)":/g, '$1:')
.replace(/"/g, '\'')
lines.push(`useSeoMeta(${body})`)
}
if (Object.keys(mergedHeadOptions).length) {
const body = JSON.stringify(mergedHeadOptions, null, 2)
.replace(/"([^"]+)":/g, '$1:')
.replace(/"/g, '\'')
lines.push(`useHead(${body})`)
}
return lines.join('\n\n')
})
const copy = useCopy()
const openInEditor = useOpenInEditor()
const tabs = [
'Missing Tags',
'Code Snippet',
]
const selectedTab = ref(tabs[0])
</script>
<template>
<template v-if="missingTags.length">
<NSectionBlock
text="Missing Tags"
:description="`${missingTags.length} missing tags`"
icon="carbon:warning-other"
header-class="text-orange op100! [[open]_&]:text-inherit"
:padding="false"
>
<div flex="~ wrap" mt--2 w-full flex-none>
<template v-for="name, idx of tabs" :key="idx">
<button
px4 py2 border="r t base"
hover="bg-active"
:class="name === selectedTab ? '' : 'border-b'"
@click="selectedTab = name"
>
<div :class="name === selectedTab ? '' : 'op30' " capitalize>
{{ name }}
</div>
</button>
</template>
<div border="b base" flex-auto />
</div>
<NCard v-if="selectedTab === tabs[0]" grid="~ cols-[max-content_1fr]" m4 items-center justify-between of-hidden>
<template v-for="item, index of missingTags" :key="index">
<div v-if="index" x-divider />
<div v-if="index" x-divider />
<div flex="~ gap-1 items-center" px4 py2>
<div i-carbon-warning text-orange />
<NTextExternalLink
op50
:link="item.docs"
n="orange"
>
{{ item.name }}
</NTextExternalLink>
</div>
<div w-full p2 op75>
{{ item.description }}
</div>
</template>
</NCard>
<div v-else m4 flex="~ col gap-2">
<p flex="~ gap-1 wrap items-center">
<NButton
icon="carbon-copy" n="xs" px-2
@click="copy(codeSnippet)"
>
Copy
</NButton>
the following code snippet and paste it into your
<NButton
v-if="matchedRouteFilepath"
icon="carbon-launch" n="xs" px-2
@click="openInEditor(matchedRouteFilepath)"
>
page component
</NButton>
<span v-else>page component</span>
to full fill the missing tags.
</p>
<NCard relative n-code-block>
<NCodeBlock
:code="codeSnippet"
lang="ts"
:lines="false"
w-full of-auto p3
/>
<div flex="~ gap-2" n="sm primary" absolute right-2 top-2>
<NButton
icon="carbon-copy"
@click="copy(codeSnippet)"
>
Copy
</NButton>
</div>
</NCard>
</div>
</NSectionBlock>
</template>
</template>