use partial for referenced <link>s

This commit is contained in:
Ben Goldsworthy 2025-06-04 17:45:38 +02:00
parent fd6fc99ab0
commit 54a41716c6
No known key found for this signature in database
3 changed files with 108 additions and 77 deletions

View file

@ -1,8 +1,7 @@
<!doctype html>
<!DOCTYPE html>
{{ partialCached "copying.html" . }}
<html
class="h-card"
lang="en-gb"
@ -22,87 +21,20 @@
{{- partialCached "head/title.html" ( slice .Site.Title .Site.Params.tagline ) .Site.Title .Site.Params.tagline -}}
{{- end -}}
<link
rel="license"
href="{{ block "head-license" . }}https://creativecommons.org/publicdomain/zero/1.0/{{ end }}"
/>
<link
class="u-url u-uid"
rel="me"
href="{{ .Site.Home.Permalink }}"
/>
<link
class="u-email"
rel="me"
href="mailto:me+bg@bengoldsworthy.net"
/>
<link
class="u-url"
rel="me"
href="https://github.com/Rumperuu"
/>
<link
class="u-url"
rel="me"
href="https://news.ycombinator.com/user?id=Rumperuu"
/>
<link
class="u-logo"
rel="icon"
sizes="192x192"
href="/images/icon.png"
/>
{{- with .Site.Params.keyfile -}}
<link
class="u-key"
rel="author"
href="{{ . }}"
/>
{{- end -}}
<!-- References -->
{{- partialCached "head/references.html" ( dict "sc" $ "pc" . ) -}}
<link
rel="canonical"
href="{{ .Permalink }}"
href="{{- .Permalink -}}"
/>
{{ with .OutputFormats.Get "rss" -}}
{{- with .OutputFormats.Get "rss" -}}
<link
rel="{{ .Rel }}"
type="{{ .MediaType.Type | html }}"
href="{{ .RelPermalink }}"
title="{{ $.Site.Title | safeHTML }}"
/>
{{- end }}
<link
href="/css/sanitize.css"
rel="stylesheet"
/>
{{- $mainStylesheet := resources.Get "css/main.scss" }}
{{- $mainStylesheet := $mainStylesheet | css.Sass | resources.Fingerprint }}
<link
rel="stylesheet"
type="text/css"
href="{{ $mainStylesheet.Permalink }}"
integrity="{{ $mainStylesheet.Data.Integrity | html }}"
/>
{{- $printStylesheet := resources.Get "css/print.scss" }}
{{- $printStylesheet := $printStylesheet | css.Sass | resources.Fingerprint }}
<link
rel="stylesheet"
media="print"
href="{{ $printStylesheet.Permalink }}"
integrity="{{ $printStylesheet.Data.Integrity | html }}"
/>
{{- $feedsStylesheet := resources.Get "css/feeds.scss" }}
{{- $feedsStylesheet := $feedsStylesheet | css.Sass }}
<link
rel="stylesheet"
href="{{ $feedsStylesheet.Permalink }}"
/>
{{- end -}}
{{- if .Param "math" -}}
{{- partialCached "head/math.html" . -}}
{{- end -}}
@ -113,10 +45,9 @@
</head>
<body class="site-container site-container{{ block "main-class" . }}layouts-default-baseof{{ end }}">
{{ block "header" . -}}
{{- block "header" . -}}
{{- partialCached "header/site-header.html" . -}}
{{- end }}
{{- end -}}
<article
class="{{ block "article-class" . }}h-entry{{ end }}site-content site-content{{ block "main-class" . }}{{ end }}"

View file

@ -0,0 +1,54 @@
{{- /*
Displays comments for an item
@params pc Page context
@params sc Site context
*/
-}}
<!-- Validation -->
{{- 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 -}}
<!-- Rendering -->
<link
rel="license"
href="{{- partialCached "util/get_licence_link.html" ( dict "licences_data" .sc.Site.Data.licences "licence" .sc.Site.Params.licence "licence_link" .sc.Site.Params.licence_link ) -}}"
/>
<link
class="u-url u-uid"
rel="me"
href="{{- .sc.Site.Home.Permalink -}}"
/>
<link
class="u-email"
rel="me"
href="mailto:{{- .sc.Site.Params.author.email -}}"
/>
{{- range .sc.Site.Params.meLinks -}}
<link
class="u-url"
rel="me"
href="{{ . }}"
/>
{{- end -}}
<link
class="u-logo"
rel="icon"
sizes="192x192"
href="/images/icon.png"
/>
{{- with .sc.Site.Params.keyfile -}}
<link
class="u-key"
rel="author"
href="{{- . -}}"
/>
{{- end -}}

View file

@ -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.
*/
-}}
<!-- Validation -->
{{- if ( not ( isset . "licences_data" ) ) -}}
{{- errorf "No licence data passed to partial" -}}
{{- end -}}
{{- if ( not ( isset . "licence" ) ) -}}
{{- errorf "No licence requested in partial" -}}
{{- end -}}
<!-- Variable assignment -->
{{- $licences_data := .licences_data -}}
{{- $licence := .licence -}}
{{- $licence_link := .licence_link -}}
{{- $final_licence_link := "" -}}
<!-- Rendering -->
{{- 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 -}}