Minor fixes for deprecated Hugo API calls

This commit is contained in:
Thanwer 2026-05-10 14:00:25 +02:00
parent 9a998f4ac9
commit fb6395efc5
4 changed files with 131 additions and 0 deletions

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
{{/* Cache params once for all partials */}}
{{ $params := partial "params-helper.html" . }}
{{ $dataTheme := "" }}
{{ if and (ne $params.colorTheme "auto") (eq $params.enableColorThemeSwitcher false) }}
{{ $dataTheme = $params.colorTheme }}
{{ end }}
<html lang="{{ site.Params.locale | default site.Language.Locale }}" data-theme="{{ $dataTheme }}">
<head>
{{ block "head" . }}
{{ partial "head/head.html" . }}
{{ end }}
</head>
<body>
<a class="skip-main" href="#main">{{ i18n "skipToContent" }}</a>
<div class="container">
<header class="common-header">
{{ block "header" . }}
{{ partial "head/header.html" . }}
{{ end }}
</header>
<main id="main" tabindex="-1">
{{ block "main" . }}{{ end }}
</main>
{{ block "footer" . }}
{{ partial "footer.html" . }}
{{ end }}
</div>
</body>
</html>

59
layouts/_default/rss.xml Normal file
View File

@ -0,0 +1,59 @@
{{- $pctx := . -}}
{{- if .IsHome -}}{{ $pctx = site }}{{- end -}}
{{- $pages := where (where $pctx.RegularPages ".Params.disable_feed" "!=" true) "Params.private" "!=" true -}}
{{- $limit := site.Config.Services.RSS.Limit -}}
{{- if ge $limit 1 -}}
{{- $pages = $pages | first $limit -}}
{{- end -}}
{{- printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title>{{ with .Site.Params.feedTitle }}{{ . }}{{ else }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Site.BaseURL }}</link>
<description>Recent blog posts on {{ .Site.Title }}</description>
{{ with .Site.Params.copyright }}
<copyright>{{ . }}</copyright>{{ end }}
<generator>Hugo (https://gohugo.io)</generator>
{{ with .Site.Language.Locale }}
<language>{{.}}</language>{{end}}
{{ with .Site.Params.author.name }}
<managingEditor>{{ with $.Site.Params.author.email }}{{ . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}{{ end }}</managingEditor>{{ end }}
{{ with .Site.Params.author.name }}
<webMaster>{{ with $.Site.Params.author.email }}{{ . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}{{ end }}</webMaster>{{ end }}
{{ if not .Date.IsZero }}
<lastBuildDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 Z0700" | safeHTML }}</lastBuildDate>{{ end }}
{{ with .OutputFormats.Get "RSS" }}
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}{{ end }}
{{ range $index, $page := $pages }}
<item>
<title>{{ .Title }}</title>
<link>{{ .Permalink }}</link>
<pubDate>{{ .Date.Format "Mon, 02 Jan 2006 15:04:05 Z0700" | safeHTML }}</pubDate>
{{ with .Site.Params.author.name }}
<author>{{ with $.Site.Params.author.email }}{{ . }}{{ with $.Site.Params.author.name }} ({{ . }}){{ end }}{{ end }}</author>{{ end }}
{{ $cover := "" }}
{{ with $page.Params.cover }}
{{ $res := $page.Resources.GetMatch . }}
{{ if $res }}
{{ $cover = $res.Permalink }}
{{ else }}
{{ $cover = . | absURL }}
{{ end }}
{{ end }}
{{ if $cover }}
<media:content url="{{ $cover }}" medium="image" />
<media:title>Cover Image</media:title>
{{ end }}
<description>
{{ .Summary | plainify | htmlEscape }}
</description>
<guid isPermaLink="true">{{ .Permalink }}</guid>
</item>
{{ end }}
</channel>
</rss>

View File

@ -0,0 +1,24 @@
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range where .Data.Pages "Params.private" "!=" true }}
{{- if .Permalink -}}
<url>
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
<xhtml:link
rel="alternate"
hreflang="{{ .Language.Label }}"
href="{{ .Permalink }}"
/>{{ end }}
<xhtml:link
rel="alternate"
hreflang="{{ .Language.Label }}"
href="{{ .Permalink }}"
/>{{ end }}
</url>
{{- end -}}
{{ end }}
</urlset>

View File

@ -0,0 +1,15 @@
<ul class="language-select">
{{ $pageLang := .Page.Lang}}
{{ $translations := .AllTranslations }}
{{ if not .IsTranslated }}
{{ $translations = site.Home.AllTranslations }}
{{ end }}
{{ range $translations }}
{{ if eq .Lang $pageLang }}
<li>{{ .Language.Label }}</li>
{{ else }}
<li><a href="{{ .RelPermalink }}">{{ .Language.Label }}</a></li>
{{ end }}
{{ end }}
</ul>