Skip to content

Commit d2fee27

Browse files
committed
feat: use dynamic favicon
1 parent 7477e27 commit d2fee27

File tree

1 file changed

+41
-12
lines changed

1 file changed

+41
-12
lines changed

app.vue

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,47 @@ if (!domain.value) {
8686
watch(domain, () => refresh(), { once: true })
8787
}
8888
89+
const favicon = computed(() => {
90+
const radius = 80
91+
const stroke = 14
92+
const normalizedRadius = radius - stroke * 2
93+
const circumference = normalizedRadius * 2 * Math.PI
94+
95+
const value = (results.value ? Math.floor((results.value.performance + results.value.accessibility + results.value.bestPractices + results.value.seo) / 4) : 97)
96+
const color = value >= 90 ? '#23c55e' : value >= 50 ? '#fbbf24' : '#ef4444'
97+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" height="${radius * 2}" width="${radius * 2}">
98+
<circle
99+
stroke="${color}"
100+
fill="transparent"
101+
stroke-linecap="round"
102+
stroke-dasharray="${circumference + ' ' + circumference}"
103+
style="transform-origin:center;stroke-dashoffset: ${circumference - (Math.floor(value / 4) * 4) / 100 * circumference};transform: rotate(270deg)"
104+
stroke-width="${stroke}"
105+
r="${normalizedRadius}"
106+
cx="${radius}"
107+
cy="${radius}"
108+
/>
109+
<circle
110+
fill="${color}"
111+
stroke-width="${stroke}"
112+
r="${normalizedRadius - 35}"
113+
cx="${radius}"
114+
cy="${radius}"
115+
/>
116+
</svg>`
117+
return `data:image/svg+xml;base64,${btoa(svg)}`
118+
})
119+
120+
useHead({
121+
link: [
122+
{
123+
rel: 'icon',
124+
type: 'image/svg',
125+
href: () => favicon.value
126+
}
127+
]
128+
})
129+
89130
useServerHead({
90131
htmlAttrs: {
91132
lang: 'en',
@@ -100,18 +141,6 @@ useServerHead({
100141
sizes: '180x180',
101142
href: '/apple-touch-icon.png'
102143
},
103-
{
104-
rel: 'icon',
105-
type: 'image/png',
106-
sizes: '32x32',
107-
href: '/favicon-32x32.png'
108-
},
109-
{
110-
rel: 'icon',
111-
type: 'image/png',
112-
sizes: '16x16',
113-
href: '/favicon-16x16.png'
114-
},
115144
{
116145
rel: 'manifest',
117146
href: '/site.webmanifest'

0 commit comments

Comments
 (0)