forked from labex-labs/python-cheatsheet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.vue
More file actions
82 lines (72 loc) · 1.94 KB
/
App.vue
File metadata and controls
82 lines (72 loc) · 1.94 KB
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
<script setup>
import { generateStructuredData } from '~/composables/structuredData'
const route = useRoute()
const { currentLocale } = useI18n()
// Extract article meta from route
const articleMeta = computed(() => {
const routeMeta = route.meta || {}
const childMeta = route.matched[0]?.children?.[0]?.meta || {}
if (routeMeta.title || routeMeta.date) {
return {
title: routeMeta.title,
description: routeMeta.description,
date: routeMeta.date,
updated: routeMeta.updated,
tags: routeMeta.tags,
socialImage: routeMeta.socialImage,
}
}
if (childMeta.title || childMeta.date) {
return {
title: childMeta.title,
description: childMeta.description,
date: childMeta.date,
updated: childMeta.updated,
tags: childMeta.tags,
socialImage: childMeta.socialImage,
}
}
return undefined
})
const { meta } = useMeta(articleMeta.value)
useHead(meta)
useScrollBehavior()
const { t } = useI18n()
// Generate structured data
const structuredData = computed(() => {
return generateStructuredData(route, currentLocale.value, articleMeta.value)
})
// Inject structured data as JSON-LD
useHead({
script: computed(() =>
structuredData.value.map((schema, index) => ({
type: 'application/ld+json',
innerHTML: JSON.stringify(schema),
key: `structured-data-${index}-${route.path}`,
})),
),
})
// Inject Google Analytics script if VITE_GTAG is configured
const gTag = import.meta.env.VITE_GTAG
if (gTag && gTag !== 'tag' && gTag.trim() !== '') {
useHead({
script: [
{
src: `https://www.googletagmanager.com/gtag/js?id=${gTag}`,
async: true,
},
{
innerHTML: `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${gTag}');
`,
},
],
})
}
</script>
<template>
<RouterView />
</template>