feat: use absolute URLs for assets

closes #473, closes #476

Signed-off-by: Sped0n <hi@sped0n.com>
This commit is contained in:
Sped0n
2025-11-12 00:03:38 +08:00
committed by Ryan
parent 72b830def9
commit 7d4bed3ba6
13 changed files with 98 additions and 72 deletions

View File

@@ -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;

View File

@@ -14,8 +14,16 @@ export async function getImageJSON(): Promise<ImageJSON[]> {
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'
}

View File

@@ -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 -}}

View File

@@ -1,8 +1,8 @@
{{- if site.Params.favicon -}}
{{- with site.Params.svgFavicon -}}
<link rel="icon" type="image/svg+xml" href="{{ . }}" />
<link rel="icon" type="image/svg+xml" href="{{- . -}}" />
{{- with site.Params.svgFaviconFallback -}}
<link rel="icon" type="image/png" href="{{ . }}" />
<link rel="icon" type="image/png" href="{{- . -}}" />
{{- end -}}
{{- else -}}
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />

View File

@@ -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 */ -}}
<script>
function z() {
const r = document.querySelector(':root')
@@ -20,10 +20,20 @@
window.addEventListener('resize', z, { passive: true })
</script>
{{/* 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 */}}
<link rel="preload" href="/lib/fonts/fw.woff2" as="font" crossorigin />
<link rel="preload" href="/lib/fonts/GeistVF.woff2" as="font" crossorigin />
{{- /* fonts */ -}}
<link
rel="preload"
href="{{- "lib/fonts/fw.woff2" | absURL -}}"
as="font"
crossorigin
/>
<link
rel="preload"
href="{{- "lib/fonts/GeistVF.woff2" | absURL -}}"
as="font"
crossorigin
/>

View File

@@ -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 -}}
<title>{{ $page_title }}</title>
<title>{{- $page_title -}}</title>
{{/* Basic */}}
<meta name="Description" content="{{ site.Params.description }}" />
<meta name="application-name" content="{{ $page_title }}" />
<meta name="apple-mobile-web-app-title" content="{{ $page_title }}" />
{{- /* Basic */ -}}
<meta name="Description" content="{{- site.Params.description -}}" />
<meta name="application-name" content="{{- $page_title -}}" />
<meta name="apple-mobile-web-app-title" content="{{- $page_title -}}" />
{{/* Opengraph */}}
<meta property="og:title" content="{{ $page_title }}" />
<meta name="twitter:title" content="{{ $page_title }}" />
{{- /* Opengraph */ -}}
<meta property="og:title" content="{{- $page_title -}}" />
<meta name="twitter:title" content="{{- $page_title -}}" />
<meta property="og:type" content="website" />
<meta property="og:url" content="{{ .Permalink }}" />
<meta property="og:description" content="{{ site.Params.description }}" />
<meta name="twitter:description" content="{{ site.Params.description }}" />
<meta property="og:url" content="{{- .Permalink -}}" />
<meta property="og:description" content="{{- site.Params.description -}}" />
<meta name="twitter:description" content="{{- site.Params.description -}}" />
{{/* Generator */}}
{{ hugo.Generator }}
{{- /* Generator */ -}}
{{- hugo.Generator -}}

View File

@@ -1,21 +1,21 @@
{{- with site.Params.verification.google -}}
<meta name="google-site-verification" content="{{ . }}" />
<meta name="google-site-verification" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.bing -}}
<meta name="msvalidate.01" content="{{ . }}" />
<meta name="msvalidate.01" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.yandex -}}
<meta name="yandex-verification" content="{{ . }}" />
<meta name="yandex-verification" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.pinterest -}}
<meta name="p:domain_verify" content="{{ . }}" />
<meta name="p:domain_verify" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.baidu -}}
<meta name="baidu-site-verification" content="{{ . }}" />
<meta name="baidu-site-verification" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.sogou -}}
<meta name="sogou_site_verification" content="{{ . }}" />
<meta name="sogou_site_verification" content="{{- . -}}" />
{{- end -}}
{{- with site.Params.verification.so -}}
<meta name="360-site-verification" content="{{ . }}" />
<meta name="360-site-verification" content="{{- . -}}" />
{{- end -}}

View File

@@ -1,6 +1,6 @@
<nav>
<div class="navArtist">
<a href="/">{{ site.Title }}</a>
<a href="/">{{- site.Title -}}</a>
</div>
<div class="links">
{{- $index := 0 -}}
@@ -9,7 +9,7 @@
{{- $currentIndex = sub .Weight 1 -}}
{{- end -}}
{{- $menus := .Site.Menus.main -}}
{{- $len := len $menus }}
{{- $len := len $menus -}}
{{- range $menus -}}
{{- $url := .URL | relURL -}}
{{- if eq (add $index 1) $len -}}

View File

@@ -5,7 +5,7 @@
{{- with $analytics.google.id -}}
<script type="text/javascript">
window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());
gtag('config', '{{ . }}'{{ if $analytics.google.anonymizeIP }}, { 'anonymize_ip': true }{{ end }});
gtag('config', '{{- . -}}'{{- if $analytics.google.anonymizeIP -}}, { 'anonymize_ip': true }{{- end -}});
</script> {{- printf "https://www.googletagmanager.com/gtag/js?id=%v" . | dict "Async" true "Source" | partial "plugin/script.html" -}}
{{- end -}}
@@ -13,7 +13,7 @@
{{- with $analytics.fathom.id -}}
<script type="text/javascript">
window.fathom=window.fathom||function(){(fathom.q=fathom.q||[]).push(arguments);};
fathom('set', 'siteId', '{{ . }}');
fathom('set', 'siteId', '{{- . -}}');
fathom('trackPageview');
</script> {{- dict "Source" ($analytics.fathom.server | default "cdn.usefathom.com" | printf "https://%v/tracker.js") "Async" true "Attr" "id=fathom-script" | partial "plugin/script.html" -}}
{{- end -}}
@@ -24,7 +24,7 @@
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?{{ . }}";
hm.src = "https://hm.baidu.com/hm.js?{{- . -}}";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
@@ -36,10 +36,10 @@
<script
async
defer
data-website-id="{{ . }}"
src="{{ $analytics.umami.src }}"
{{ with $analytics.umami.data_host_url }}data-host-url="{{ . }}"{{ end }}
{{ with $analytics.umami.data_domains }}data-domains="{{ . }}"{{ end }}
data-website-id="{{- . -}}"
src="{{- $analytics.umami.src -}}"
{{- with $analytics.umami.data_host_url -}}data-host-url="{{- . -}}"{{- end -}}
{{- with $analytics.umami.data_domains -}}data-domains="{{- . -}}"{{- end -}}
></script>
{{- end -}}
@@ -48,8 +48,8 @@
<script
async
defer
data-domain="{{ . }}"
src="{{ $analytics.plausible.src }}"
data-domain="{{- . -}}"
src="{{- $analytics.plausible.src -}}"
></script>
{{- end -}}
@@ -58,7 +58,7 @@
<script
defer
src="https://static.cloudflareinsights.com/beacon.min.js"
data-cf-beacon='{"token": "{{ $analytics.cloudflare.token }}"}'
data-cf-beacon='{"token": "{{- $analytics.cloudflare.token -}}"}'
></script>
{{- end -}}
@@ -76,7 +76,7 @@
{{- end -}}
<script
defer
{{ with $attr }}{{ . | safeHTMLAttr }}{{ end }}
{{- with $attr -}}{{- . | safeHTMLAttr -}}{{- end -}}
src="https://cdn.splitbee.io/sb.js"
></script>
{{- end -}}

View File

@@ -37,26 +37,26 @@
rel="preload"
as="style"
onload="this.onload=null;this.rel='stylesheet'"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
href="{{- $href -}}"
{{- if .Crossorigin -}}crossorigin="anonymous"{{- end -}}{{- with $integrity -}}
integrity="{{- . -}}"
{{- end -}}{{- with .Attr -}}{{- . | safeHTMLAttr -}}{{- end -}}
/>
<noscript
><link
rel="stylesheet"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
href="{{- $href -}}"
{{- if .Crossorigin -}}crossorigin="anonymous"{{- end -}}{{- with $integrity -}}
integrity="{{- . -}}"
{{- end -}}{{- with .Attr -}}{{- . | safeHTMLAttr -}}{{- end -}}
/></noscript>
{{- else -}}
<link
rel="stylesheet"
href="{{ $href }}"
{{ if .Crossorigin }}crossorigin="anonymous"{{ end }}{{ with $integrity }}
integrity="{{ . }}"
{{ end }}{{ with .Attr }}{{ . | safeHTMLAttr }}{{ end }}
href="{{- $href -}}"
{{- if .Crossorigin -}}crossorigin="anonymous"{{- end -}}{{- with $integrity -}}
integrity="{{- . -}}"
{{- end -}}{{- with .Attr -}}{{- . | safeHTMLAttr -}}{{- end -}}
/>
{{- end -}}
{{- end -}}

View File

@@ -58,4 +58,4 @@ Disallow: /
User-agent: *
Allow: /
Sitemap: {{ "/sitemap.xml" | absURL }}
Sitemap: {{- "/sitemap.xml" | absURL -}}

View File

@@ -1 +1 @@
{{ now.Year }}
{{- now.Year -}}

View File

@@ -22,9 +22,9 @@
{{- $weeks := div (sub now.Unix .Lastmod.Unix) 604800 -}}
{{- $priority := sub 1 (div $weeks 10.0 ) -}}
{{- if ge .Sitemap.Priority $priority -}}
<priority>{{ .Sitemap.Priority }}</priority>
<priority>{{- .Sitemap.Priority -}}</priority>
{{- else -}}
<priority>{{ $priority }}</priority>
<priority>{{- $priority -}}</priority>
{{- end -}}
{{- end -}}
@@ -32,14 +32,14 @@
{{- range .Translations -}}
<xhtml:link
rel="alternate"
hreflang="{{ .Lang }}"
href="{{ .Permalink }}"
hreflang="{{- .Lang -}}"
href="{{- .Permalink -}}"
/>
{{- end -}}
<xhtml:link
rel="alternate"
hreflang="{{ .Lang }}"
href="{{ .Permalink }}"
hreflang="{{- .Lang -}}"
href="{{- .Permalink -}}"
/>
{{- end -}}
</url>