Exclude weeknotes from front page
This commit is contained in:
parent
056ae9d058
commit
2220b539ea
51
blog/content/posts/excluding-weeknotes-from-main-page.md
Normal file
51
blog/content/posts/excluding-weeknotes-from-main-page.md
Normal file
@ -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.
|
||||
<!--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 }}
|
||||
<div class="pa3 pa4-ns w-100 w-70-ns center">
|
||||
{{/* Use $section_name to get the section title. Use "with" to only show it if it exists */}}
|
||||
{{ with $.Site.GetPage "section" $section_name }}
|
||||
<h1 class="flex-none">
|
||||
{{ $.Param "recent_copy" | default (i18n "recentTitle" .) }}
|
||||
</h1>
|
||||
{{ end }}
|
||||
|
||||
{{ $n_posts := $.Param "recent_posts_number" | default 3 }}
|
||||
|
||||
<section class="w-100 mw8">
|
||||
{{/* Range through the first $n_posts items of the section */}}
|
||||
{{ range (first $n_posts $section) }}
|
||||
<div class="relative w-100 mb4">
|
||||
{{ .Render "summary-with-image" }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</section>
|
||||
...
|
||||
```
|
||||
|
||||
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!
|
@ -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?_"
|
||||
|
75
blog/layouts/index.html
Normal file
75
blog/layouts/index.html
Normal file
@ -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" }}
|
||||
<article class="cf ph3 ph5-l pv3 pv4-l f4 tc-l center measure-wide lh-copy {{ $.Param "text_color" | default "mid-gray" }}">
|
||||
{{ .Content }}
|
||||
</article>
|
||||
{{/* 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 }}
|
||||
<div class="pa3 pa4-ns w-100 w-70-ns center">
|
||||
{{/* Use $section_name to get the section title. Use "with" to only show it if it exists */}}
|
||||
{{ with $.Site.GetPage "section" $section_name }}
|
||||
<h1 class="flex-none">
|
||||
{{ $.Param "recent_copy" | default (i18n "recentTitle" .) }}
|
||||
</h1>
|
||||
{{ end }}
|
||||
|
||||
{{ $n_posts := $.Param "recent_posts_number" | default 3 }}
|
||||
|
||||
<section class="w-100 mw8">
|
||||
{{/* Range through the first $n_posts items of the section */}}
|
||||
{{ range (first $n_posts $section) }}
|
||||
<div class="relative w-100 mb4">
|
||||
{{ .Render "summary-with-image" }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</section>
|
||||
|
||||
{{ if ge $section_count (add $n_posts 1) }}
|
||||
<section class="w-100">
|
||||
<h1 class="f3">{{ i18n "more" }}</h1>
|
||||
{{/* 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)) }}
|
||||
<h2 class="f5 fw4 mb4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "ml3" "mr3" }}">
|
||||
<a href="{{ .RelPermalink }}" class="link black dim">
|
||||
{{ .Title }}
|
||||
</a>
|
||||
</h2>
|
||||
{{ end }}
|
||||
|
||||
{{/* Add a link to the latest weeknotes */}}
|
||||
{{ if ge (len $weeknotes) 1 }}
|
||||
<h1 class="f3">Weeknotes</h1>
|
||||
{{ range (first 4 $weeknotes) }}
|
||||
<h2 class="f5 fw4 mb4 dib {{ cond (eq $.Site.Language.LanguageDirection "rtl") "ml3" "mr3" }}">
|
||||
<a href="{{ .RelPermalink }}" class="link black dim">
|
||||
{{ .Title }}
|
||||
</a>
|
||||
</h2>
|
||||
{{ 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 }}
|
||||
<a href="{{ .RelPermalink }}" class="link db f6 pa2 br3 bg-mid-gray white dim w4 tc">{{ i18n "allTitle" . }}</a>
|
||||
{{ end }}
|
||||
</section>
|
||||
{{ end }}
|
||||
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{end}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user