From 7d4bed3ba6d6b8cbbc0be64bb7497445647935eb Mon Sep 17 00:00:00 2001 From: Sped0n Date: Wed, 12 Nov 2025 00:03:38 +0800 Subject: [PATCH] feat: use absolute URLs for assets closes #473, closes #476 Signed-off-by: Sped0n --- assets/scss/_core/_font.scss | 12 ++++++-- assets/ts/resources.ts | 10 ++++++- .../partials/function/currentMenuItem.html | 6 ++-- layouts/partials/head/favicon.html | 4 +-- layouts/partials/head/link.html | 28 +++++++++++------ layouts/partials/head/meta.html | 30 +++++++++---------- layouts/partials/head/seo.html | 14 ++++----- layouts/partials/nav.html | 4 +-- layouts/partials/plugin/analytics.html | 22 +++++++------- layouts/partials/plugin/style.html | 24 +++++++-------- layouts/robots.txt | 2 +- layouts/shortcodes/year.html | 2 +- layouts/sitemap.xml | 12 ++++---- 13 files changed, 98 insertions(+), 72 deletions(-) diff --git a/assets/scss/_core/_font.scss b/assets/scss/_core/_font.scss index deb4df7..b9bd1fa 100644 --- a/assets/scss/_core/_font.scss +++ b/assets/scss/_core/_font.scss @@ -1,8 +1,16 @@ @font-face { font-family: 'Geist'; src: - url('/lib/fonts/GeistVF.woff2') format('woff2 supports variations'), - url('/lib/fonts/GeistVF.woff2') format('woff2-variations'); + url('{{- "lib/fonts/GeistVF.woff2" | absURL -}}') format('woff2 supports variations'), + url('{{- "lib/fonts/GeistVF.woff2" | absURL -}}') format('woff2-variations'); + font-weight: 400; + font-style: normal; + font-display: swap; +} + +@font-face { + font-family: 'FW'; + src: url('/lib/fonts/fw.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; diff --git a/assets/ts/resources.ts b/assets/ts/resources.ts index d3c5509..aabeac6 100644 --- a/assets/ts/resources.ts +++ b/assets/ts/resources.ts @@ -14,8 +14,16 @@ export async function getImageJSON(): Promise { if (document.title.split(' | ')[0] === '404') { return [] // no images on 404 page } + + const ogUrlMetaTag = document.querySelector( + 'meta[property="og:url"]' + ) as HTMLMetaElement | null + const indexJsonUrl = ogUrlMetaTag?.content + ? new URL('index.json', ogUrlMetaTag.content).href + : new URL('index.json', window.location.href).href + try { - const response = await fetch(`${window.location.href}index.json`, { + const response = await fetch(indexJsonUrl, { headers: { Accept: 'application/json' } diff --git a/layouts/partials/function/currentMenuItem.html b/layouts/partials/function/currentMenuItem.html index 8b49a03..dd70364 100644 --- a/layouts/partials/function/currentMenuItem.html +++ b/layouts/partials/function/currentMenuItem.html @@ -5,9 +5,9 @@ {{- $weight := -1 -}} {{- range site.Menus.main -}} - {{ $menu_item_url := .URL | relLangURL }} - {{ $page_url:= $currentPage.RelPermalink | relLangURL }} - {{ if eq $menu_item_url $page_url }} + {{- $menu_item_url := .URL | relLangURL -}} + {{- $page_url:= $currentPage.RelPermalink | relLangURL -}} + {{- if eq $menu_item_url $page_url -}} {{- $identifier = .Identifier -}} {{- $title = .Title -}} {{- $weight = .Weight -}} diff --git a/layouts/partials/head/favicon.html b/layouts/partials/head/favicon.html index d085b92..14d66b5 100644 --- a/layouts/partials/head/favicon.html +++ b/layouts/partials/head/favicon.html @@ -1,8 +1,8 @@ {{- if site.Params.favicon -}} {{- with site.Params.svgFavicon -}} - + {{- with site.Params.svgFaviconFallback -}} - + {{- end -}} {{- else -}} diff --git a/layouts/partials/head/link.html b/layouts/partials/head/link.html index edf5112..c8c827a 100644 --- a/layouts/partials/head/link.html +++ b/layouts/partials/head/link.html @@ -1,16 +1,16 @@ -{{/* fingerprint */}} +{{- /* fingerprint */ -}} {{- $fingerprint := .Scratch.Get "fingerprint" | default "" -}} -{{/* critical style */}} +{{- /* critical style */ -}} {{- $style := dict "Source" "scss/critical.scss" "Fingerprint" $fingerprint -}} {{- $options := dict "enableSourceMap" true "includePaths" (slice "node_modules") "transpiler" "dartsass" -}} {{- $style = dict "Context" . "ToCSS" $options "Inline" true "Template" true | merge $style -}} {{- partial "plugin/style.html" $style -}} -{{- $style := dict "Link" "/bundled/css/main.css" "Defer" true -}} +{{- $style := dict "Link" ("bundled/css/main.css" | absURL) "Defer" true -}} {{- partial "plugin/style.html" $style -}} -{{/* fuck safari */}} +{{- /* fuck safari */ -}} -{{/* main js */}} -{{- $script := dict "Link" "/bundled/js/main.js" "Defer" true "Esm" true -}} +{{- /* main js */ -}} +{{- $script := dict "Link" ("bundled/js/main.js" | absURL) "Defer" true "Esm" true -}} {{- partial "plugin/script.html" $script -}} -{{/* fonts */}} - - +{{- /* fonts */ -}} + + diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index 652218d..ef163a0 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -1,22 +1,22 @@ -{{/* Title */}} +{{- /* Title */ -}} {{- $page_title := "" -}} {{- with partial "function/currentMenuItem.html" . -}} - {{ $page_title = printf "%s" site.Title | printf "%s%s" " | " | printf "%s%s" .Title | printf "%s" }} + {{- $page_title = printf "%s" site.Title | printf "%s%s" " | " | printf "%s%s" .Title | printf "%s" -}} {{- end -}} -{{ $page_title }} +{{- $page_title -}} -{{/* Basic */}} - - - +{{- /* Basic */ -}} + + + -{{/* Opengraph */}} - - +{{- /* Opengraph */ -}} + + - - - + + + -{{/* Generator */}} -{{ hugo.Generator }} +{{- /* Generator */ -}} +{{- hugo.Generator -}} diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index f49d864..2df9dc8 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -1,21 +1,21 @@ {{- with site.Params.verification.google -}} - + {{- end -}} {{- with site.Params.verification.bing -}} - + {{- end -}} {{- with site.Params.verification.yandex -}} - + {{- end -}} {{- with site.Params.verification.pinterest -}} - + {{- end -}} {{- with site.Params.verification.baidu -}} - + {{- end -}} {{- with site.Params.verification.sogou -}} - + {{- end -}} {{- with site.Params.verification.so -}} - + {{- end -}} diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html index a18ff47..3722826 100644 --- a/layouts/partials/nav.html +++ b/layouts/partials/nav.html @@ -1,6 +1,6 @@