From 54a41716c696d7db302e41d00ec56cb1bd5303e1 Mon Sep 17 00:00:00 2001 From: Ben Goldsworthy Date: Wed, 4 Jun 2025 17:45:38 +0200 Subject: [PATCH] use partial for referenced ``s --- layouts/_default/baseof.html | 85 ++------------------- layouts/partials/head/references.html | 54 +++++++++++++ layouts/partials/util/get_licence_link.html | 46 +++++++++++ 3 files changed, 108 insertions(+), 77 deletions(-) create mode 100644 layouts/partials/head/references.html create mode 100644 layouts/partials/util/get_licence_link.html diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index c7fe82e..c6e1a55 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,8 +1,7 @@ - + {{ partialCached "copying.html" . }} - - - - - - - {{- with .Site.Params.keyfile -}} - - {{- end -}} - - + + {{- partialCached "head/references.html" ( dict "sc" $ "pc" . ) -}} - - {{ with .OutputFormats.Get "rss" -}} + {{- with .OutputFormats.Get "rss" -}} - {{- end }} - - - - {{- $mainStylesheet := resources.Get "css/main.scss" }} - {{- $mainStylesheet := $mainStylesheet | css.Sass | resources.Fingerprint }} - - {{- $printStylesheet := resources.Get "css/print.scss" }} - {{- $printStylesheet := $printStylesheet | css.Sass | resources.Fingerprint }} - - {{- $feedsStylesheet := resources.Get "css/feeds.scss" }} - {{- $feedsStylesheet := $feedsStylesheet | css.Sass }} - - + {{- end -}} {{- if .Param "math" -}} {{- partialCached "head/math.html" . -}} {{- end -}} @@ -113,10 +45,9 @@ - {{ block "header" . -}} + {{- block "header" . -}} {{- partialCached "header/site-header.html" . -}} - {{- end }} - + {{- end -}}
+ +{{- if ( not ( isset . "sc" ) ) -}} + {{- errorf "No site context received" -}} +{{- end -}} + +{{- if ( not ( isset . "pc" ) ) -}} + {{- errorf "No page context received (%q)" .sc.Page.File.Dir -}} +{{- end -}} + + + + + + +{{- range .sc.Site.Params.meLinks -}} + +{{- end -}} + +{{- with .sc.Site.Params.keyfile -}} + +{{- end -}} diff --git a/layouts/partials/util/get_licence_link.html b/layouts/partials/util/get_licence_link.html new file mode 100644 index 0000000..0546d46 --- /dev/null +++ b/layouts/partials/util/get_licence_link.html @@ -0,0 +1,46 @@ +{{- /* + Returns the URL for a given licence, either from the site data or from a defined URL. + + @params licences_data Site data of licences, indexed by SPDX IDs. + @params licence Licence identifier. + @params licence_link Manually-defined licence URL. Optional. + */ +-}} + + + +{{- if ( not ( isset . "licences_data" ) ) -}} + {{- errorf "No licence data passed to partial" -}} +{{- end -}} + +{{- if ( not ( isset . "licence" ) ) -}} + {{- errorf "No licence requested in partial" -}} +{{- end -}} + + + +{{- $licences_data := .licences_data -}} +{{- $licence := .licence -}} +{{- $licence_link := .licence_link -}} + +{{- $final_licence_link := "" -}} + + + +{{- if ( index $licences_data $licence ) -}} + {{- if eq ( index $licences_data $licence ) $licence_link -}} + {{- warnf "Redundant license link '%s' defined, it already exists in the site data" ( index $licences_data $licence ) -}} + {{- $final_licence_link = ( index $licences_data $licence ) -}} + {{- else -}} + {{- if ( and ( $licence_link ) ( not ( eq ( index $licences_data $licence ) $licence_link ) ) ) -}} + {{- warnf "Licence '%s' has a different link ('%s') defined in the site data, using '%s' instead" $licence ( index $licences_data $licence ) $licence_link -}} + {{- end -}} + {{- $final_licence_link = $licence_link -}} + {{- end -}} + +{{- else if $licence_link -}} + {{- warnidf "licence-link-not-in-site-data" "License link '%s' for licence '%s' should be in the site data, unless it's rarely used" $licence_link $licence -}} + {{- $final_licence_link = $licence_link -}} +{{- end -}} + +{{- return $final_licence_link -}}