Skip to content

Commit 23d77cd

Browse files
committed
fix: improve dynamic favicon
1 parent def6cab commit 23d77cd

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

app.vue

+19-24
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,21 @@ const favicon = computed(() => {
9292
const normalizedRadius = radius - stroke * 2
9393
const circumference = normalizedRadius * 2 * Math.PI
9494
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'
95+
const value = status.value === 'pending' || (domain.value && !results.value)
96+
? undefined
97+
: (results.value ? Math.floor((results.value.performance + results.value.accessibility + results.value.bestPractices + results.value.seo) / 4) : 100)
98+
const color = !value ? '#6b7280' : value >= 90 ? '#23c55e' : value >= 50 ? '#fbbf24' : '#ef4444'
9799
const svg = `<svg xmlns="http://www.w3.org/2000/svg" height="${radius * 2}" width="${radius * 2}">
100+
<style>@keyframes spin {
101+
from {transform: rotate(0deg)}
102+
to {transform: rotate(360deg)}
103+
}</style>
98104
<circle
99105
stroke="${color}"
100106
fill="transparent"
101107
stroke-linecap="round"
102108
stroke-dasharray="${circumference + ' ' + circumference}"
103-
style="transform-origin:center;stroke-dashoffset: ${circumference - (Math.floor(value / 4) * 4) / 100 * circumference};transform: rotate(270deg)"
109+
style="transform-origin:center;stroke-dashoffset:${circumference - (Math.floor((value || 85) / 4) * 4) / 100 * circumference};transform:rotate(270deg)${!value ? ';animation:spin 1s linear infinite' : ''}"
104110
stroke-width="${stroke}"
105111
r="${normalizedRadius}"
106112
cx="${radius}"
@@ -119,14 +125,17 @@ const favicon = computed(() => {
119125
120126
useHead({
121127
link: [
122-
{
128+
() => ({
129+
key: 'favicon',
123130
rel: 'icon',
124131
type: 'image/svg',
125-
href: () => favicon.value
126-
}
132+
href: favicon.value
133+
})
127134
]
128135
})
129136
137+
138+
130139
useServerHead({
131140
htmlAttrs: {
132141
lang: 'en',
@@ -167,31 +176,17 @@ useServerSeoMeta({
167176
ogUrl: joinURL(`https://page-speed.dev`, domain.value)
168177
})
169178
179+
useSeoMeta({
180+
title: () => domain.value ? `page-speed.dev - ${domain.value}` : 'page-speed.dev',
181+
})
182+
170183
if (!domain.value) {
171184
defineOgImageComponent('Home')
172185
useServerSeoMeta({
173-
title: 'page-speed.dev',
174186
description: 'See and share PageSpeed Insights results simply and easily.',
175187
})
176-
useHead({
177-
link: [
178-
{
179-
rel: 'icon',
180-
type: 'image/png',
181-
sizes: '32x32',
182-
href: '/favicon-32x32.png'
183-
},
184-
{
185-
rel: 'icon',
186-
type: 'image/png',
187-
sizes: '16x16',
188-
href: '/favicon-16x16.png'
189-
},
190-
]
191-
})
192188
} else if (results.value) {
193189
useServerSeoMeta({
194-
title: 'page-speed.dev - ' + domain.value,
195190
description:
196191
`Performance: ${results.value?.performance} | ` +
197192
`Accessibility: ${results.value?.accessibility} | ` +

0 commit comments

Comments
 (0)