-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapp.vue
More file actions
140 lines (122 loc) Β· 4 KB
/
app.vue
File metadata and controls
140 lines (122 loc) Β· 4 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
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
<template>
<nuxt-layout>
<nuxt-page />
</nuxt-layout>
</template>
<script setup lang="ts">
import { useFavicon, usePreferredDark } from "@vueuse/core";
import getPostDigest from "~/utils/getPostDigests";
import getSiteName from "~/utils/getSiteName.js";
const route = useRoute();
const postname = computed(() => route.params.postname as string);
const sitename = getSiteName();
const titleWithPrefix = computed(() => {
if (route.params.postname) {
return `${sitename} - ${getPostDigest(postname.value)?.title}`
}
return `${sitename} - ${route.meta.title}`;
});
const titleWithSuffix = computed(() => {
if (route.params.postname) {
return `${getPostDigest(postname.value)?.title} - ${sitename}`
}
return `${route.meta.title} - ${sitename}`;
});
const cookie = useCookie('subilan-blog-dark-mode-indicator');
const forceMode = useState('force-mode', () => cookie.value || 'auto');
const preferredDark = usePreferredDark();
const isDark = computed(() => {
if (forceMode.value === 'dark') return true;
if (forceMode.value === 'light') return false;
return preferredDark.value;
});
onMounted(() => {
document.documentElement.classList.toggle('dark', isDark.value);
});
watch(isDark, (val) => {
if (import.meta.client) {
document.documentElement.classList.toggle('dark', val);
}
});
watch(forceMode, (val) => {
cookie.value = val;
});
const fontCookie = useCookie('subilan-blog-font-style');
const fontStyle = useState('font-style', () => fontCookie.value || 'sans');
const isSerif = computed(() => fontStyle.value === 'serif');
const fontCssLinks = [
{ rel: 'stylesheet', href: '/fonts/source-serif/source-serif.css' },
{ rel: 'stylesheet', href: '/fonts/noto-serif-sc/noto-serif-sc.css' }
];
onMounted(() => {
document.documentElement.classList.toggle('serif', isSerif.value);
if (isSerif.value) {
fontCssLinks.forEach(l => {
const link = document.createElement('link');
link.rel = l.rel;
link.href = l.href;
link.setAttribute('data-font-style', 'true');
document.head.appendChild(link);
});
}
});
watch(isSerif, (val) => {
if (import.meta.client) {
document.documentElement.classList.toggle('serif', val);
if (val) {
fontCssLinks.forEach(l => {
const link = document.createElement('link');
link.rel = l.rel;
link.href = l.href;
link.setAttribute('data-font-style', 'true');
document.head.appendChild(link);
});
} else {
document.head.querySelectorAll('link[data-font-style]').forEach(l => l.remove());
}
}
});
watch(fontStyle, (val) => {
fontCookie.value = val;
});
onMounted(() => {
useFavicon('/avatar.jpg', {
rel: 'icon'
});
});
useHead({
script: [
{
innerHTML: `(function(){var c=document.cookie.match(/(?:^|;\\s*)subilan-blog-dark-mode-indicator=([^;]+)/);var m=c?c[1]:'auto';if(m==='dark'||(m==='auto'&&window.matchMedia('(prefers-color-scheme:dark)').matches)){document.documentElement.classList.add('dark')}})()`,
type: 'text/javascript'
},
{
innerHTML: `(function(){var c=document.cookie.match(/(?:^|;\\s*)subilan-blog-font-style=([^;]+)/);if(c&&c[1]==='serif'){var l1=document.createElement('link');l1.rel='stylesheet';l1.href='/fonts/source-serif/source-serif.css';var l2=document.createElement('link');l2.rel='stylesheet';l2.href='/fonts/noto-serif-sc/noto-serif-sc.css';document.head.appendChild(l1);document.head.appendChild(l2);document.documentElement.classList.add('serif')}})()`,
type: 'text/javascript'
}
],
meta: [
{
property: 'og:title',
content: titleWithPrefix
}
],
link: [
{
rel: 'preconnect',
href: 'https://rsms.me/'
},
{
rel: 'stylesheet',
href: 'https://rsms.me/inter/inter.css'
},
{
rel: 'stylesheet',
href: 'https://cdn.jsdelivr.net/npm/katex@0.16.27/dist/katex.min.css',
integrity: 'sha384-Pu5+C18nP5dwykLJOhd2U4Xen7rjScHN/qusop27hdd2drI+lL5KvX7YntvT8yew',
crossorigin: 'anonymous'
}
],
title: titleWithSuffix,
})
</script>