mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-16 19:51:07 +02:00
feat: enhance image handling and analytics configuration
- Add @unpic/astro for improved image optimization - Configure image service with blurhash placeholder - Update analytics script to support custom JavaScript URLs - Modify preload configuration for more flexible analytics integration - Remove deprecated rehype image transformation plugin
This commit is contained in:
parent
6bcd51765d
commit
ad9fabe937
8 changed files with 218 additions and 146 deletions
|
@ -92,10 +92,10 @@ export const themeConfig: ThemeConfig = {
|
|||
preload: {
|
||||
commentURL: '', // https://comment.example.com
|
||||
imageHostURL: 'https://image.radishzz.cc', // https://image.example.com
|
||||
// If you proxy analytics requests to the custom domain, you can fill in below
|
||||
customGoogleAnalyticsURL: '', // https://custom.example.com
|
||||
customUmamiAnalyticsURL: '', // https://custom.example.com
|
||||
customUmamiAnalyticsJS: '', // https://custom.example.com/custom.js
|
||||
// If you proxy analytics JavaScript to the custom domain, you can fill in below.
|
||||
// See more at https://gist.github.com/xiaopc/0602f06ca465d76bd9efd3dda9393738 and https://github.com/umami-software/umami/discussions/1026
|
||||
customGoogleAnalyticsJS: '', // https://custom.example.com/whatever.js
|
||||
customUmamiAnalyticsJS: '', // https://custom.example.com/whatever.js
|
||||
},
|
||||
// PRELOAD SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@ title: 故鄉
|
|||
published: 2024-01-10
|
||||
tags: ["鲁迅"]
|
||||
---
|
||||
import { Image } from 'astro:assets';
|
||||
|
||||
<!--  -->
|
||||
<Image src="https://image.radishzz.cc/image/gallery/03.webp" inferSize alt="一只猫在阳光下睡觉。" />
|
||||
|
||||

|
||||
|
||||
我冒了嚴寒,回到相隔二千餘里,別了二十餘年的故鄉去。
|
||||
|
||||
|
@ -16,9 +19,9 @@ tags: ["鲁迅"]
|
|||
|
||||
我這次是專為了別他而來的。我們多年聚族而居的老屋,已經公同賣給別姓了,交屋的期限,只在本年,所以必須趕在正月初一以前,永別了熟識的老屋,而且遠離了熟識的故鄉,搬家到我在謀食的異地去。
|
||||
|
||||
<!-- 第二日清早晨我到了我家的門口了。瓦楞上許多枯草的斷莖當風抖著,正在說明這老屋難免易主的原因。幾房的本家大約已經搬走了,所以很寂靜。我到了自家的房外,我的母親早已迎著出來了,接著便飛出了八歲的侄兒宏兒。 -->
|
||||
第二日清早晨我到了我家的門口了。瓦楞上許多枯草的斷莖當風抖著,正在說明這老屋難免易主的原因。幾房的本家大約已經搬走了,所以很寂靜。我到了自家的房外,我的母親早已迎著出來了,接著便飛出了八歲的侄兒宏兒。 -->
|
||||
|
||||
<!-- 我的母親很高興,但也藏著許多淒涼的神情,教我坐下,歇息,喝茶,且不談搬家的事。宏兒沒有見過我,遠遠的對面站著只是看。
|
||||
我的母親很高興,但也藏著許多淒涼的神情,教我坐下,歇息,喝茶,且不談搬家的事。宏兒沒有見過我,遠遠的對面站著只是看。
|
||||
|
||||
但我們終於談到搬家的事。我說外間的寓所已經租定了,又買了幾件傢具,此外須將家裡所有的木器賣去,再去增添。母親也說好,而且行李也略已齊集,木器不便搬運的,也小半賣去了,只是收不起錢來。
|
||||
|
||||
|
@ -182,4 +185,4 @@ tags: ["鲁迅"]
|
|||
|
||||
我在朦朧中,眼前展開一片海邊碧綠的沙地來,上面深藍的天空中掛著一輪金黃的圓月。我想:希望本是無所謂有,無所謂無的。這正如地上的路;其實地上本沒有路,走的人多了,也便成了路。
|
||||
|
||||
一九二一年一月 -->
|
||||
一九二一年一月
|
|
@ -15,7 +15,7 @@ const initMetaTheme = mode === 'dark' ? darkMode : lightMode
|
|||
const { locale, moreLocale } = themeConfig.global
|
||||
const { verification = {}, twitterID = '', googleAnalyticsID = '', umamiAnalyticsID = '' } = themeConfig.seo ?? {}
|
||||
const { google = '', bing = '', yandex = '', baidu = '' } = verification
|
||||
const { commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '', customUmamiAnalyticsURL = '', customUmamiAnalyticsJS = '' } = themeConfig.preload
|
||||
const { commentURL = '', imageHostURL = '', customGoogleAnalyticsJS = '', customUmamiAnalyticsJS = '' } = themeConfig.preload
|
||||
---
|
||||
|
||||
<head>
|
||||
|
@ -34,10 +34,10 @@ const { commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '', custo
|
|||
<!-- Preload -->
|
||||
<link rel="preload" href="/font/Snell-Black.woff2" as="font" type="font/woff2" crossorigin />
|
||||
<link rel="preload" href="/font/EarlySummer-subset.woff2" as="font" type="font/woff2" crossorigin />
|
||||
{commentURL && <link rel="preconnect" href={commentURL} crossorigin />}
|
||||
{commentURL && <link rel="dns-prefetch" href={commentURL} />}
|
||||
{imageHostURL && <link rel="preconnect" href={imageHostURL} crossorigin />}
|
||||
{imageHostURL && <link rel="dns-prefetch" href={imageHostURL} />}
|
||||
{customGoogleAnalyticsURL && <link rel="dns-prefetch" href={customGoogleAnalyticsURL} />}
|
||||
{customUmamiAnalyticsURL && <link rel="dns-prefetch" href={customUmamiAnalyticsURL} />}
|
||||
<link rel="alternate" href="/rss.xml" type="application/rss+xml" title="RSS" />
|
||||
<link rel="canonical" href={Astro.url} />
|
||||
|
||||
|
@ -45,7 +45,7 @@ const { commentURL = '', imageHostURL = '', customGoogleAnalyticsURL = '', custo
|
|||
{[locale, ...moreLocale].map(lang => (
|
||||
<link
|
||||
rel="alternate"
|
||||
href={`${url}${lang === locale ? '' : lang}`}
|
||||
href={`${url}${lang === locale ? '' : `/${lang}`}`}
|
||||
hreflang={lang === 'zh-tw' ? 'zh-TW' : lang}
|
||||
/>
|
||||
))}
|
||||
|
@ -105,12 +105,6 @@ function initTheme(doc = document) {
|
|||
}
|
||||
}
|
||||
|
||||
// Follow system theme changes automatically
|
||||
function followSystemTheme() {
|
||||
initTheme()
|
||||
document.dispatchEvent(new Event('theme-changed'))
|
||||
}
|
||||
|
||||
// Function 1: Initialize theme on first load
|
||||
initTheme()
|
||||
|
||||
|
@ -124,51 +118,45 @@ window
|
|||
.matchMedia('(prefers-color-scheme: dark)')
|
||||
.addEventListener('change', ({ matches: isDark }) => {
|
||||
localStorage.setItem('theme', isDark ? 'dark' : 'light')
|
||||
followSystemTheme()
|
||||
initTheme()
|
||||
document.dispatchEvent(new Event('theme-changed'))
|
||||
})
|
||||
</script>
|
||||
|
||||
<!-- Google Analytics -->
|
||||
{
|
||||
googleAnalyticsID && (
|
||||
<>
|
||||
<script
|
||||
type="text/partytown"
|
||||
crossorigin="anonymous"
|
||||
src={`${customGoogleAnalyticsURL || 'https://www.googletagmanager.com'}/gtag/js?id=${googleAnalyticsID}`}
|
||||
/>
|
||||
<script
|
||||
type="text/partytown"
|
||||
define:vars={{ googleAnalyticsID, customGoogleAnalyticsURL }}
|
||||
>
|
||||
window.dataLayer = window.dataLayer || []
|
||||
function gtag(...args) {
|
||||
dataLayer.push(args)
|
||||
}
|
||||
gtag('js', new Date())
|
||||
if (customGoogleAnalyticsURL) {
|
||||
gtag('config', googleAnalyticsID, {
|
||||
transport_url: customGoogleAnalyticsURL,
|
||||
})
|
||||
}
|
||||
else {
|
||||
gtag('config', googleAnalyticsID)
|
||||
}
|
||||
</script>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
<!-- Umami Analytics -->
|
||||
{
|
||||
umamiAnalyticsID && (
|
||||
{googleAnalyticsID && (
|
||||
<>
|
||||
<script
|
||||
type="text/partytown"
|
||||
crossorigin="anonymous"
|
||||
data-website-id={umamiAnalyticsID}
|
||||
src={customUmamiAnalyticsJS || 'https://analytics.umami.is/script.js'}
|
||||
data-cache="true"
|
||||
src={customGoogleAnalyticsJS || `https://www.googletagmanager.com/gtag/js?id=${googleAnalyticsID}`}
|
||||
/>
|
||||
)
|
||||
}
|
||||
<script type="text/partytown" define:vars={{ googleAnalyticsID, customGoogleAnalyticsJS }}>
|
||||
window.dataLayer = window.dataLayer || []
|
||||
function gtag(...args) {
|
||||
dataLayer.push(args)
|
||||
}
|
||||
gtag('js', new Date())
|
||||
|
||||
if (customGoogleAnalyticsJS) {
|
||||
gtag('config', googleAnalyticsID, {
|
||||
transport_url: new URL(customGoogleAnalyticsJS).origin,
|
||||
})
|
||||
}
|
||||
else {
|
||||
gtag('config', googleAnalyticsID)
|
||||
}
|
||||
</script>
|
||||
</>
|
||||
)}
|
||||
|
||||
<!-- Umami Analytics -->
|
||||
{umamiAnalyticsID && (
|
||||
<script
|
||||
type="text/partytown"
|
||||
crossorigin="anonymous"
|
||||
data-website-id={umamiAnalyticsID}
|
||||
src={customUmamiAnalyticsJS || 'https://analytics.umami.is/script.js'}
|
||||
data-cache="true"
|
||||
/>
|
||||
)}
|
||||
</head>
|
||||
|
|
3
src/types/index.d.ts
vendored
3
src/types/index.d.ts
vendored
|
@ -79,8 +79,7 @@ export interface ThemeConfig {
|
|||
preload: {
|
||||
commentURL?: string
|
||||
imageHostURL?: string
|
||||
customGoogleAnalyticsURL?: string
|
||||
customUmamiAnalyticsURL?: string
|
||||
customGoogleAnalyticsJS?: string
|
||||
customUmamiAnalyticsJS?: string
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue