From 2220b539ea9e6d61117bc72fe371b3544515e732 Mon Sep 17 00:00:00 2001 From: Jack Jackson Date: Sun, 6 Apr 2025 21:20:30 -0700 Subject: [PATCH] Exclude weeknotes from front page --- .../excluding-weeknotes-from-main-page.md | 51 +++++++++++++ blog/content/posts/how-to-reach-agreement.md | 2 +- blog/layouts/index.html | 75 +++++++++++++++++++ 3 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 blog/content/posts/excluding-weeknotes-from-main-page.md create mode 100644 blog/layouts/index.html diff --git a/blog/content/posts/excluding-weeknotes-from-main-page.md b/blog/content/posts/excluding-weeknotes-from-main-page.md new file mode 100644 index 0000000..6d95ec5 --- /dev/null +++ b/blog/content/posts/excluding-weeknotes-from-main-page.md @@ -0,0 +1,51 @@ +--- +title: "Excluding Weeknotes From Main Page" +date: 2025-04-06T21:18:49-07:00 +tags: + - Meta + - Tech-Snippets + +--- +I just went to write up a new [weeknotes]({{< ref "/tags/weeknotes" >}}) post, and noticed that that would have meant that all three previewed posts on my main page would have been weeknotes. That simply will not do! So into the depths of Hugo layouts I ventured once more. + +The relevant part of the original layout looks like[^line-numbers] this: + +``` +... +{{ $section := where $.Site.RegularPages "Section" "in" $section_name }} +{{ $section_count := len $section }} +{{ if ge $section_count 1 }} +
+ {{/* Use $section_name to get the section title. Use "with" to only show it if it exists */}} + {{ with $.Site.GetPage "section" $section_name }} +

+ {{ $.Param "recent_copy" | default (i18n "recentTitle" .) }} +

+ {{ end }} + + {{ $n_posts := $.Param "recent_posts_number" | default 3 }} + +
+ {{/* Range through the first $n_posts items of the section */}} + {{ range (first $n_posts $section) }} +
+ {{ .Render "summary-with-image" }} +
+ {{ end }} +
+... +``` + +Although the [where function](https://gohugo.io/functions/collections/where) does have a pretty good selection of operators, there's no `not` or `not intersection` - so, although it's possible to [filter to all members which have a particular slice-term contained in some other slice](https://gohugo.io/functions/collections/where/#intersection-comparison), it's not immediately possible to find all members that _don't_ have a given value in a slice-term. Thankfully, [later in the same docs](https://gohugo.io/functions/collections/where/#inequality-test) there's a link to [`collections/complement`](https://gohugo.io/functions/collections/complement/), which does exactly what I want. The final result was: + +``` +... +{{ $section_original := where $.Site.RegularPages "Section" "in" $section_name }} +{{ $weeknotes := where $section_original "Params.tags" "intersect" (slice "Weeknotes") }} +{{ $section := complement $weeknotes $section_original }} +... +``` + +Since I don't want those weeknotes to be undiscoverable, though, I also added a dedicated section for them on the homepage. Pretty happy with how that turned out! + +[^line-numbers]: Hmm, note to self for a TODO - automatically adding line-numbers into monospace blocks would be nice! diff --git a/blog/content/posts/how-to-reach-agreement.md b/blog/content/posts/how-to-reach-agreement.md index 138a9ce..57d0564 100644 --- a/blog/content/posts/how-to-reach-agreement.md +++ b/blog/content/posts/how-to-reach-agreement.md @@ -40,7 +40,7 @@ Part of agreeing on a goal is agreeing on the context in which it exists - the e T_subbed_K - clarify definitions, reduce to illustrative examples -[^favourite-laws]: They are, in no particular order: [Ashby's](https://en.wikipedia.org/wiki/Variety_(cybernetics)#Law_of_requisite_variety), [Sturgeon's](https://en.wikipedia.org/wiki/Sturgeon%27s_law), [Brandolini's](https://en.wikipedia.org/wiki/Brandolini%27s_law), [Hyrum's](https://en.wikipedia.org/wiki/API#Hyrums), [Goodhart's](https://en.wikipedia.org/wiki/Goodhart%27s_law), [Hoftstadter's](https://en.wikipedia.org/wiki/Hofstadter%27s_law), and [Conway's](https://en.wikipedia.org/wiki/Conway%27s_law), along with the differently-named [Chesterton's](https://en.wikipedia.org/wiki/G._K._Chesterton#Chesterton's_fence) +[^favourite-laws]: They are, in no particular order: [Ashby's](https://en.wikipedia.org/wiki/Variety_(cybernetics)#Law_of_requisite_variety), [Sturgeon's](https://en.wikipedia.org/wiki/Sturgeon%27s_law), [Brandolini's](https://en.wikipedia.org/wiki/Brandolini%27s_law), [Hyrum's](https://en.wikipedia.org/wiki/API#Hyrums), [Goodhart's](https://en.wikipedia.org/wiki/Goodhart%27s_law), [Hoftstadter's](https://en.wikipedia.org/wiki/Hofstadter%27s_law), and [Conway's](https://en.wikipedia.org/wiki/Conway%27s_law), along with the differently-named [Chesterton's](https://en.wikipedia.org/wiki/G._K._Chesterton#Chesterton's_fence). And, while writing this article, I came across [this excellent page](https://hacker-laws.com/) which collects many of the best. [^own-your-own-information]: which - I'm increasingly realizing as I get older and more ~~cynical~~ realistic - was a mistake. Own the information that you create, in such a way that it is portable when you are no longer convenient to the organization providing you with hosting - and recognize that "_an index of useful information_" is itself useful information! [^eponymous-dish]: for similar reasons, if I'm eating at a new restaurant and they have a dish named after the establishment, that's usually my default first choice - though I might there be being a sucker for a subtle priming technique... [^what-is-a-policy]: In my original formulation of this observation, it applied to technical decision-making and system designs. However, I believe it applies to any decision of the form "_What should we do in order to achieve some goal?_" diff --git a/blog/layouts/index.html b/blog/layouts/index.html new file mode 100644 index 0000000..d1f8265 --- /dev/null +++ b/blog/layouts/index.html @@ -0,0 +1,75 @@ +{{/* Copy-pasted from ananke's base `index.html`, with an addition to filter-out "weeknotes" that I don't want to show up on the homepage */}} +{{/* See the post made in the same commit for explanation */}} + +{{ define "main" }} +
+ {{ .Content }} +
+ {{/* Define a section to pull recent posts from. For Hugo 0.20 this will default to the section with the most number of pages. */}} + {{ $mainSections := .Site.Params.mainSections | default (slice "post") }} + + {{/* Check to see if the section is defined for ranging through it */}} + {{range ($mainSections)}} + {{/* Derive the section name */}} + {{ $section_name := . }} + {{/* Create a variable with that section to use in multiple places. */}} + {{ $section_original := where $.Site.RegularPages "Section" "in" $section_name }} + {{ $weeknotes := where $section_original "Params.tags" "intersect" (slice "Weeknotes") }} + {{ $section := complement $weeknotes $section_original }} + {{ $section_count := len $section }} + {{ if ge $section_count 1 }} +
+ {{/* Use $section_name to get the section title. Use "with" to only show it if it exists */}} + {{ with $.Site.GetPage "section" $section_name }} +

+ {{ $.Param "recent_copy" | default (i18n "recentTitle" .) }} +

+ {{ end }} + + {{ $n_posts := $.Param "recent_posts_number" | default 3 }} + +
+ {{/* Range through the first $n_posts items of the section */}} + {{ range (first $n_posts $section) }} +
+ {{ .Render "summary-with-image" }} +
+ {{ end }} +
+ + {{ if ge $section_count (add $n_posts 1) }} +
+

{{ i18n "more" }}

+ {{/* Now, range through the next four after the initial $n_posts items. Nest the requirements, "after" then "first" on the outside */}} + {{ range (first 4 (after $n_posts $section)) }} +

+ + {{ .Title }} + +

+ {{ end }} + + {{/* Add a link to the latest weeknotes */}} + {{ if ge (len $weeknotes) 1 }} +

Weeknotes

+ {{ range (first 4 $weeknotes) }} +

+ + {{ .Title }} + +

+ {{ end }} + {{ end }} + + {{/* As above, Use $section_name to get the section title, and URL. Use "with" to only show it if it exists */}} + {{ with $.Site.GetPage "section" $section_name }} + {{ i18n "allTitle" . }} + {{ end }} +
+ {{ end }} + +
+ {{ end }} + {{ end }} +{{end}} +