Add canonifyAssetsURLs option

This commit is contained in:
mark
2023-07-26 17:13:53 +02:00
parent e8bba05213
commit b845e210b7
6 changed files with 24 additions and 8 deletions

View File

@@ -4,6 +4,7 @@
description = "Hinode is a clean documentation and blog theme for your Hugo site based on Bootstrap 5." description = "Hinode is a clean documentation and blog theme for your Hugo site based on Bootstrap 5."
enableDarkMode = true enableDarkMode = true
modes = ["light", "dark"] modes = ["light", "dark"]
canonifyAssetsURLs = false
# toml-docs-end main # toml-docs-end main
# toml-docs-start modules # toml-docs-start modules

View File

@@ -15,6 +15,7 @@
--> -->
{{- $validRatios := slice "1x1" "4x3" "16x9" "21x9" -}} {{- $validRatios := slice "1x1" "4x3" "16x9" "21x9" -}}
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $ratio := .ratio -}} {{- $ratio := .ratio -}}
{{- $url := .url -}} {{- $url := .url -}}
{{- $mode := false -}} {{- $mode := false -}}
@@ -68,6 +69,7 @@
<!-- Generate a image set of type webp --> <!-- Generate a image set of type webp -->
{{- define "partials/image-scaled.html " -}} {{- define "partials/image-scaled.html " -}}
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $img := .img -}} {{- $img := .img -}}
{{- $ratio := .ratio -}} {{- $ratio := .ratio -}}
{{- $imgset := "" -}} {{- $imgset := "" -}}
@@ -98,8 +100,12 @@
{{- $scaled = $img.Fit (printf "%s webp" $dim) -}} {{- $scaled = $img.Fit (printf "%s webp" $dim) -}}
{{- end -}} {{- end -}}
{{- $scaled = $scaled | resources.Copy (replace $img.RelPermalink $clean (printf "-%s.webp" $dim)) -}} {{- $scaled = $scaled | resources.Copy (replace $img.RelPermalink $clean (printf "-%s.webp" $dim)) -}}
{{- if $absoluteURL -}}
{{- $imgset = printf "%s, %s %sw" $imgset $scaled.Permalink (index $widths $index) -}}
{{- else -}}
{{- $imgset = printf "%s, %s %sw" $imgset $scaled.RelPermalink (index $widths $index) -}} {{- $imgset = printf "%s, %s %sw" $imgset $scaled.RelPermalink (index $widths $index) -}}
{{- end -}} {{- end -}}
{{- end -}}
{{- $imgset = strings.TrimPrefix ", " $imgset -}} {{- $imgset = strings.TrimPrefix ", " $imgset -}}
{{- end -}} {{- end -}}
@@ -108,6 +114,7 @@
<!-- Define the img with optional caption --> <!-- Define the img with optional caption -->
{{- define "partials/image-definition.html" -}} {{- define "partials/image-definition.html" -}}
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $ratio := .ratio -}} {{- $ratio := .ratio -}}
{{- $url := .url -}} {{- $url := .url -}}
{{- $outerClass := .outerClass -}} {{- $outerClass := .outerClass -}}
@@ -125,7 +132,11 @@
{{- $img := partial "utilities/GetImage.html" (dict "url" $url) -}} {{- $img := partial "utilities/GetImage.html" (dict "url" $url) -}}
{{- if $img -}} {{- if $img -}}
{{- $fallback := partial "partials/image-default.html" (dict "img" $img "ratio" $ratio) -}} {{- $fallback := partial "partials/image-default.html" (dict "img" $img "ratio" $ratio) -}}
{{- if $absoluteURL -}}
{{- $fallbackURL = $fallback.Permalink -}}
{{- else -}}
{{- $fallbackURL = $fallback.RelPermalink -}} {{- $fallbackURL = $fallback.RelPermalink -}}
{{- end -}}
{{- $imgset = partial "partials/image-scaled.html " (dict "img" $img "ratio" $ratio) -}} {{- $imgset = partial "partials/image-scaled.html " (dict "img" $img "ratio" $ratio) -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@@ -93,6 +93,7 @@
</li> </li>
{{- end -}} {{- end -}}
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $supportedFlags := slice "true" "false" -}} {{- $supportedFlags := slice "true" "false" -}}
{{- $id := printf "navbar-collapse-%d" 0 -}} {{- $id := printf "navbar-collapse-%d" 0 -}}
@@ -205,7 +206,7 @@
<!-- Insert the brand logo or name --> <!-- Insert the brand logo or name -->
<a class="navbar-brand mx-auto" href="{{ site.Home.RelPermalink }}"> <a class="navbar-brand mx-auto" href="{{ site.Home.RelPermalink }}">
{{- if $logo -}} {{- if $logo -}}
<img src="{{ $logo }}" alt="{{ $title }} logo" height="30"> <img src="{{if $absoluteURL }}{{ absURL $logo }}{{ else }}{{ $logo }}{{ end }}" alt="{{ $title }} logo" height="30">
{{- else -}} {{- else -}}
<span class="fw-bold">{{ $title }}</span> <span class="fw-bold">{{ $title }}</span>
{{- end -}} {{- end -}}

View File

@@ -1,3 +1,4 @@
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $filename := .filename | default "js/main.bundle.js" -}} {{- $filename := .filename | default "js/main.bundle.js" -}}
{{- $match := .match | default "{js/*.js,js/vendor/**.js}" -}} {{- $match := .match | default "{js/*.js,js/vendor/**.js}" -}}
{{- $page := .page -}} {{- $page := .page -}}
@@ -25,9 +26,9 @@
{{- if gt (len $js.Content) 0 -}} {{- if gt (len $js.Content) 0 -}}
{{- if not hugo.IsProduction -}} {{- if not hugo.IsProduction -}}
<script src="{{ $js.RelPermalink }}"></script> <script src="{{ if $absoluteURL }}{{ $js.Permalink }}{{ else }}{{ $js.RelPermalink }}{{ end }}"></script>
{{ else -}} {{ else -}}
{{ $js = $js | minify | fingerprint -}} {{ $js = $js | minify | fingerprint -}}
<script src="{{ $js.RelPermalink }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous"></script> <script src="{{ if $absoluteURL }}{{ $js.Permalink }}{{ else }}{{ $js.RelPermalink }}{{ end }}" integrity="{{ $js.Data.Integrity }}" crossorigin="anonymous"></script>
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}

View File

@@ -1,10 +1,11 @@
<!-- Source: https://davelage.com/posts/hugo-favicons/ --> <!-- Source: https://davelage.com/posts/hugo-favicons/ -->
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{ if .Site.Params.favicon.logo -}} {{ if .Site.Params.favicon.logo -}}
{{ $favicon := resources.Get .Site.Params.favicon.logo -}} {{ $favicon := resources.Get .Site.Params.favicon.logo -}}
{{ range $i := .Site.Params.favicon.sizes -}} {{ range $i := .Site.Params.favicon.sizes -}}
{{ $image := $favicon.Resize (printf "%dx%d CatmullRom" $i $i) -}} {{ $image := $favicon.Resize (printf "%dx%d CatmullRom" $i $i) -}}
<link rel="icon" type="image/png" sizes="{{$i}}x{{$i}}" href="{{ $image.RelPermalink }}"> <link rel="icon" type="image/png" sizes="{{$i}}x{{$i}}" href="{{ if $absoluteURL }}{{ $image.Permalink }}{{ else }}{{ $image.RelPermalink }}{{ end }}">
{{ end -}} {{ end -}}
{{ $image := $favicon.Resize "180x CatmullRom" -}} {{ $image := $favicon.Resize "180x CatmullRom" -}}
<link rel="apple-touch-icon" sizes="180x180" href="{{ $image.RelPermalink }}"> <link rel="apple-touch-icon" sizes="180x180" href="{{ if $absoluteURL }}{{ $image.Permalink }}{{ else }}{{ $image.RelPermalink }}{{ end }}">
{{ end -}} {{ end -}}

View File

@@ -1,3 +1,4 @@
{{- $absoluteURL := site.Params.main.canonifyAssetsURLs | default false -}}
{{- $source := .source | default "scss/app.scss" -}} {{- $source := .source | default "scss/app.scss" -}}
{{- $target := .target | default "css/main.css" -}} {{- $target := .target | default "css/main.css" -}}
{{- $page := .page -}} {{- $page := .page -}}
@@ -43,8 +44,8 @@
{{- end -}} {{- end -}}
{{- if not hugo.IsProduction -}} {{- if not hugo.IsProduction -}}
<link rel="stylesheet" href="{{ $css.RelPermalink }}"> <link rel="stylesheet" href="{{ if $absoluteURL }}{{ $css.Permalink }}{{ else }}{{ $css.RelPermalink }}{{ end }}">
{{- else -}} {{- else -}}
{{- $css = $css | fingerprint | resources.PostProcess -}} {{- $css = $css | fingerprint | resources.PostProcess -}}
<link rel="stylesheet" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}" crossorigin="anonymous"> <link rel="stylesheet" href="{{ if $absoluteURL }}{{ $css.Permalink }}{{ else }}{{ $css.RelPermalink }}{{ end }}" integrity="{{ $css.Data.Integrity }}" crossorigin="anonymous">
{{- end -}} {{- end -}}