From b31a718136bfc81509533ecc09a3e7f3c27a4a6b Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 16 Aug 2025 22:12:15 +0200 Subject: fix: set rel=alternate for individual pages --- README.md | 20 ++++++++++++++++++++ layouts/partials/head.html | 19 ++++++++++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 172d47d..c216cf9 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,26 @@ Tastefejl is a fork of the [Typo] Hugo theme, with the following changes: * Removed the copy buttons for code blocks because they could obscure the code and also behaved wrongly on horizontal scrolling. +* Fixed that individual blog posts didn't have `rel=alternate` links. `homeCollection` is now also linked as the RSS feed of the home page. + Tip: Hugo by default also generates an RSS entry for the home page disable this in `hugo.toml` with: + + ```toml + [outputs] + home = ['html'] + section = ['html'] + taxonomy = ['html'] + term = ['html'] + ``` + + And then reenable this in `content/posts/_index.md` for posts with: + + ``` + +++ + title = "Posts" + outputs = ["HTML", "RSS"] + +++ + ``` + * Removed [Simple Icons] because I don't want to plaster brands on my website and at one point a 50MB .html file was committed (I filtered the git history to reduce the size of the repository.) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e437156..55a2077 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -17,9 +17,22 @@ {{ end }} -{{ with .OutputFormats.Get "rss" -}} -{{ printf `` .Rel .MediaType.Type .Permalink site.Title | safeHTML }} -{{ end }} +{{- define "outputFormats" -}} + {{- range .OutputFormats }} + {{ printf `` .Rel .MediaType.Type .Permalink $.Site.Title | safeHTML }} + {{- end }} +{{- end -}} + +{{ if .IsHome -}} + {{ with .Site.GetPage (site.Params.homeCollection | default "") -}} + {{ template "outputFormats" . }} + {{ end }} +{{ else -}} + {{ template "outputFormats" . }} + {{ with .Parent -}} + {{ template "outputFormats" . }} + {{- end }} +{{- end }} {{- if .IsHome -}} -- cgit v1.2.3