Three packs: breadcrumbs, author box and series #28

Merged
jcoffey-dev merged 1 commits from packs/breadcrumbs-author-series into main 2026-10-14 21:24:53 +00:00
21 changed files with 422 additions and 3 deletions

No files matched your search

+10 -2
View File
@@ -27,6 +27,10 @@ Content-Security-Policy as the site's own.
file.
- `remove` takes the pack's files out and forgets it.
- `list` also names the packs that come with HotDog CMS:
- **author-box**: who wrote an article, at its end, with a photo, bio
and links, from `data/authors.yaml`;
- **breadcrumbs**: a Home › Articles › This page trail above a page's
title, and the same trail for search engines;
- **calendar**: events, an upcoming-events section and a feed people
subscribe to (see [events.md](events.md));
- **changelog**: release notes, a page per release and all of them on
@@ -53,6 +57,8 @@ Content-Security-Policy as the site's own.
- **recipes**: ingredients, steps, times and servings;
- **related-posts**: at the end of an article, the ones sharing the most
tags with it;
- **series**: articles in parts, with "Part 2 of 5", every part listed
and links to the previous and next part;
- **share-links**: plain share links for Mastodon, Bluesky, LinkedIn and
email, with no tracking;
- **shop**: a product catalog with a page per product, each Buy button
@@ -66,8 +72,10 @@ Content-Security-Policy as the site's own.
**Search engines.** The faq, location-and-hours, team, recipes, jobs and shop
packs are also written as schema.org data (FAQPage, LocalBusiness, Person,
Recipe, JobPosting, Product), which search engines use for richer results. A pack can't carry
the `<script type="application/ld+json">` that holds it, so HotDog CMS
Recipe, JobPosting, Product), and so is the breadcrumbs pack's trail
(BreadcrumbList, on every page once the pack is installed), which search
engines use for richer results. A pack can't carry the
`<script type="application/ld+json">` that holds it, so HotDog CMS
builds it (`pageData` in templates) and the starter's `partials/schema.html`
writes it. Sites started before HotDog CMS 0.2 can add the same two lines to
theirs:
+13
View File
@@ -196,6 +196,19 @@ draws one beside each page. Search indexes carry the headings too (`h`, as
`[anchor, text]` pairs), so a search box can send someone to the section a
word is in rather than the top of the page.
## Where a page sits
`trail .` is the way down to a page: every page at an address above it that
exists, from the home page, then the page itself (none for the home page).
`series .` is the parts of the series a page is in (`series:` in front
matter, the same in each part), in reading order: by `part:` when every part
has one, otherwise oldest first; none when the page isn't in a series of two
or more. The breadcrumbs and series packs are built on them.
```
{{ range trail . }}<a href="{{ .Href }}">{{ .Title }}</a> › {{ end }}
```
## Navigation trees
`nav "docs-nav" .` reads a navigation tree from `data/docs-nav.yaml` and
+4
View File
@@ -270,6 +270,10 @@ func funcs(s *site.Site, a *Assets, md *site.Markdown, icons Icons) template.Fun
"closed": func(v any) bool { return closed(s, v) },
// related . 3: pages in the same collection sharing the most tags.
"related": func(p *site.Page, n int) []*site.Page { return related(s, p, n) },
// trail .: the pages above this one, from the home page, then it.
"trail": func(p *site.Page) []*site.Page { return trail(s, p) },
// series .: the parts of the series this page is in, in reading order.
"series": func(p *site.Page) []*site.Page { return series(s, p) },
// headings .Content: the h2 and h3 headings, for a table of contents.
"headings": headings,
"sectionContext": func(p *site.Page, sec site.Section, i int) SectionContext {
+94
View File
@@ -38,6 +38,11 @@ func pageData(s *site.Site, p *site.Page) []map[string]any {
}
}
}
if hasPack(s, "breadcrumbs") {
if d := breadcrumbData(s, p); d != nil {
out = append(out, d)
}
}
layout := p.Layout
if layout == "" && p.Collection != "" {
layout = s.Config.Collections[p.Collection].Layout
@@ -516,3 +521,92 @@ func plainText(md string) string {
s = mdUnderline.ReplaceAllString(s, "$1$2")
return strings.Join(strings.Fields(s), " ")
}
func hasPack(s *site.Site, name string) bool {
for _, p := range s.Config.Packs {
if p.Name == name {
return true
}
}
return false
}
// trail is the way down to a page from the home page: every page at an
// address above it that exists (/, /docs/, /docs/install/), then the page.
// The home page and the 404 page have none.
func trail(s *site.Site, p *site.Page) []*site.Page {
if p.Path == "/" || p.Kind == site.KindError {
return nil
}
var out []*site.Page
parts := strings.Split(strings.Trim(p.Path, "/"), "/")
for i := 0; i < len(parts); i++ {
at := "/" + strings.Join(parts[:i], "/")
if i > 0 {
at += "/"
}
if q := s.PageAt(at); q != nil && q != p && q.RedirectTo == "" {
out = append(out, q)
}
}
return append(out, p)
}
// breadcrumbData is the trail as a BreadcrumbList, for a page with a trail
// of its own (more than the home page and itself is not needed: Home > About
// is still a trail).
func breadcrumbData(s *site.Site, p *site.Page) map[string]any {
t := trail(s, p)
if len(t) < 2 || p.NoIndex {
return nil
}
items := make([]any, len(t))
for i, q := range t {
items[i] = map[string]any{"@type": "ListItem", "position": i + 1, "name": q.Title, "item": q.Permalink}
}
d := ldBase("BreadcrumbList")
d["itemListElement"] = items
return d
}
// series is every page in p's collection with the same series: in front
// matter as p, in reading order: by part: when every one has a number, else
// oldest first. A page that isn't in a series, or is its only part, has none.
func series(s *site.Site, p *site.Page) []*site.Page {
name := str(p.Params["series"])
if name == "" || p.Collection == "" {
return nil
}
var parts []*site.Page
numbered := true
for _, q := range s.Collection(p.Collection) {
if (q.Draft && q != p) || !strings.EqualFold(str(q.Params["series"]), name) {
continue
}
if _, ok := partNumber(q); !ok {
numbered = false
}
parts = append(parts, q)
}
if len(parts) < 2 {
return nil
}
sort.SliceStable(parts, func(i, j int) bool {
a, b := parts[i], parts[j]
if numbered {
x, _ := partNumber(a)
y, _ := partNumber(b)
return x < y
}
if !a.Date.Equal(b.Date) {
return a.Date.Before(b.Date)
}
return strings.ToLower(a.Title) < strings.ToLower(b.Title)
})
return parts
}
func partNumber(p *site.Page) (float64, bool) {
n, err := strconv.ParseFloat(str(p.Params["part"]), 64)
return n, err == nil
}
+42
View File
@@ -191,6 +191,36 @@ func TestBundledPacksBuildAndPass(t *testing.T) {
"changelog/feed.xml": {"1.1.1", "1.0.0"},
"index.html": {`href="/changelog/1-1-1/">1.1.1`, `href="/changelog/1-1-0/">1.1.0`, "Closed a hole.", "Every release"},
}},
{"breadcrumbs", []page{
{"content/recipes/_index.md", "---\ntitle: Recipes\nsummary: All of them.\n---\n"},
{"content/recipes/bread/_index.md", "---\ntitle: Bread\nsummary: Loaves.\n---\n"},
{"content/recipes/bread/rye.md", "---\ntitle: Dark rye\ndate: 2026-10-01\nsummary: A dense loaf.\n---\nRye.\n"},
}, map[string][]string{
"recipes/bread/rye/index.html": {`<nav class="crumbs" aria-label="Breadcrumb">`, `<li><a href="/">Home</a></li><li><a href="/recipes/">Recipes</a></li><li><a href="/recipes/bread/">Bread</a></li><li><span aria-current="page">Dark rye</span></li>`, `"@type":"BreadcrumbList"`, `"position":4`, `"item":"https://example.org/recipes/bread/"`, "packs/breadcrumbs/breadcrumbs."},
"about/index.html": {`<li><a href="/">Home</a></li><li><span aria-current="page">About</span></li>`},
}},
{"author-box", []page{
{"data/authors.yaml", "sam:\n name: Sam Rivera\n role: Head baker\n bio: Bakes from **4am**.\n photo: /media/a.png\n photo_alt: Sam at the oven\n page: /about/\n links:\n - { name: Mastodon, url: \"https://example.social/@sam\" }\nana:\n name: Ana Lopez\nme:\n name: Your Name\n role: Owner\n"},
{"content/articles/one.md", "---\ntitle: One\ndate: 2026-10-01\nsummary: One.\nauthor: sam\n---\nOne.\n"},
{"content/articles/two.md", "---\ntitle: Two\ndate: 2026-10-02\nsummary: Two.\nauthors: [sam, Ana Lopez]\n---\nTwo.\n"},
{"content/articles/three.md", "---\ntitle: Three\ndate: 2026-10-03\nsummary: Three.\n---\nThree.\n"},
}, map[string][]string{
"articles/one/index.html": {`aria-label="About the author"`, `src="/media/a.png" alt="Sam at the oven"`, `<a href="/about/" rel="author">Sam Rivera</a>`, "· Head baker", "<strong>4am</strong>", `href="https://example.social/@sam">Mastodon`, "packs/author-box/author-box."},
"articles/two/index.html": {`aria-label="About the authors"`, "Sam Rivera", `<span class="ab-photo ab-initial" aria-hidden="true">A</span>`, "Ana Lopez"},
"articles/three/index.html": {"Your Name", "· Owner"},
}},
{"series", []page{
{"content/articles/a.md", "---\ntitle: Starter\ndate: 2026-09-01\nsummary: A.\nseries: Sourdough basics\n---\nA.\n"},
{"content/articles/b.md", "---\ntitle: Feeding\ndate: 2026-09-08\nsummary: B.\nseries: Sourdough basics\n---\nB.\n"},
{"content/articles/c.md", "---\ntitle: Baking\ndate: 2026-09-15\nsummary: C.\nseries: sourdough basics\n---\nC.\n"},
{"content/articles/x.md", "---\ntitle: Ovens two\ndate: 2026-08-01\nsummary: X.\nseries: Ovens\npart: 2\n---\nX.\n"},
{"content/articles/y.md", "---\ntitle: Ovens one\ndate: 2026-08-20\nsummary: Y.\nseries: Ovens\npart: 1\n---\nY.\n"},
{"content/articles/alone.md", "---\ntitle: Alone\ndate: 2026-07-01\nsummary: Z.\nseries: Just me\n---\nZ.\n"},
}, map[string][]string{
"articles/b/index.html": {"Part 2 of 3</span> in <span class=\"series-name\">Sourdough basics</span>", `<li><a href="/articles/a/">Starter</a></li><li><span aria-current="page">Feeding</span></li><li><a href="/articles/c/">Baking</a></li>`, `class="series-prev" href="/articles/a/"`, `class="series-next" href="/articles/c/"`, "packs/series/series."},
"articles/a/index.html": {"Part 1 of 3"},
"articles/x/index.html": {"Part 2 of 2", `class="series-prev" href="/articles/y/"`},
}},
}
for _, c := range cases {
t.Run(c.pack, func(t *testing.T) {
@@ -204,6 +234,18 @@ func TestBundledPacksBuildAndPass(t *testing.T) {
os.MkdirAll(filepath.Join(dir, "static", "media"), 0o755)
os.WriteFile(filepath.Join(dir, "static", "media", "a.png"), picture, 0o644)
os.WriteFile(filepath.Join(dir, "static", "media", "b.png"), picture, 0o644)
if c.pack == "breadcrumbs" {
for _, l := range []string{"page.html", "article.html", "list.html"} {
lp := filepath.Join(dir, "layouts", l)
raw, _ := os.ReadFile(lp)
os.WriteFile(lp, []byte(strings.Replace(string(raw), "<h1", `{{ template "breadcrumbs" . }}<h1`, 1)), 0o644)
}
}
if c.pack == "author-box" || c.pack == "series" {
lp := filepath.Join(dir, "layouts", "article.html")
raw, _ := os.ReadFile(lp)
os.WriteFile(lp, []byte(strings.Replace(string(raw), "{{ .Content }}", `{{ .Content }}{{ template "`+c.pack+`" . }}`, 1)), 0o644)
}
if c.pack == "changelog" {
lp := filepath.Join(dir, "partials", "footer.html")
raw, _ := os.ReadFile(lp)
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Coffey Labs LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+12
View File
@@ -0,0 +1,12 @@
# Author box pack
Who wrote an article, at its end: a photo (or their initial), their name and
role, a short bio and their links, from `data/authors.yaml`.
hotdog-cms pack add author-box
Add `{{ template "author-box" . }}` to `layouts/article.html` after
`{{ .Content }}`. An article shows the author its front matter names
(`author: sam`, or `authors: [sam, ana]`); without one, the author whose name
is the site's `author:`, so a site with one writer needs no front matter.
Authors with a `page:` link to it, so the box pairs well with the team pack.
+14
View File
@@ -0,0 +1,14 @@
/* The author box pack. Colors come from the theme's variables. */
.author-box { margin: 40px 0 0; display: grid; gap: 14px; }
.ab-person { display: flex; gap: 18px; align-items: flex-start; padding: 20px 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.ab-photo { flex: none; width: 72px; height: 72px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); background: var(--accent-soft); }
.ab-initial { display: grid; place-items: center; font-size: 1.8rem; font-weight: 750; color: var(--accent); }
.ab-text { min-width: 0; }
.ab-label { margin: 0; color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.ab-name { margin: 2px 0 0; font-weight: 700; font-size: 1.1rem; }
.ab-role { color: var(--muted); font-weight: 500; font-size: .95rem; }
.ab-bio { margin-top: 6px; }
.ab-bio > :first-child { margin-top: 0; }
.ab-bio > :last-child { margin-bottom: 0; }
.ab-links { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: .92rem; }
@media (max-width: 520px) { .ab-person { flex-direction: column; } }
+28
View File
@@ -0,0 +1,28 @@
name: author-box
version: 1.0.0
title: Author box
description: Who wrote an article, at its end, with a photo or initial, a short bio and their links.
license: MIT
author: Coffey Labs LLC
notes: |
Write who your authors are in data/authors.yaml, one entry per person,
under a short id:
sam:
name: Sam Rivera
role: Head baker
bio: Sam has baked here since 2019 and runs the Saturday bread class.
photo: /media/sam.webp # optional; otherwise their initial
photo_alt: Sam at the oven
page: /people/sam-rivera/ # optional: their page on this site
links:
- { name: Mastodon, url: "https://example.social/@sam" }
Then add this line to layouts/article.html, after {{ .Content }}:
{{ template "author-box" . }}
An article shows the author its front matter names (author: sam, or
authors: [sam, ana] for more than one). Without one, it shows the author
whose name is the site's author: in site.yaml, so a site with one writer
needs no front matter at all.
+22
View File
@@ -0,0 +1,22 @@
{{/* Who wrote this page, from data/authors.yaml: the ones its front matter names
(author: or authors:, by id or name), else the site's author. */}}
{{ with index .Site.Data "authors" }}{{ $all := . }}
{{ $want := list }}{{ with $.Params.authors }}{{ if kindIs "list" . }}{{ $want = . }}{{ else }}{{ $want = list . }}{{ end }}{{ else }}{{ with $.Params.author }}{{ $want = list . }}{{ else }}{{ with $.Site.Config.Author }}{{ $want = list . }}{{ end }}{{ end }}{{ end }}
{{ $people := list }}
{{ range $want }}{{ $w := print . }}{{ with index $all $w }}{{ $people = append $people . }}{{ else }}{{ range $id, $a := $all }}{{ if eq (print $a.name) $w }}{{ $people = append $people $a }}{{ end }}{{ end }}{{ end }}{{ end }}
{{ with $people }}
<link rel="stylesheet" href="{{ asset "packs/author-box/author-box.css" }}">
<aside class="author-box" aria-label="About the author{{ if gt (len .) 1 }}s{{ end }}">
{{ range $a := . }}
<div class="ab-person">
{{ with .photo }}<img class="ab-photo" src="{{ . }}" alt="{{ default "" $a.photo_alt }}" loading="lazy" width="72" height="72">{{ else }}<span class="ab-photo ab-initial" aria-hidden="true">{{ upper (printf "%.1s" (print $a.name)) }}</span>{{ end }}
<div class="ab-text">
<p class="ab-label">Written by</p>
<p class="ab-name">{{ with .page }}<a href="{{ . }}" rel="author">{{ $a.name }}</a>{{ else }}{{ .name }}{{ end }}{{ with .role }} <span class="ab-role">· {{ . }}</span>{{ end }}</p>
{{ with .bio }}<div class="ab-bio">{{ markdownify . }}</div>{{ end }}
{{ with .links }}<ul class="ab-links">{{ range . }}<li><a href="{{ .url }}">{{ .name }}</a></li>{{ end }}</ul>{{ end }}
</div>
</div>
{{ end }}
</aside>
{{ end }}{{ end }}
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Coffey Labs LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+13
View File
@@ -0,0 +1,13 @@
# Breadcrumbs pack
A trail above a page's title, from the home page down to the page:
**Home › Recipes › Bread › Rye**. Each step links to the page at that
address, so a visitor deep in a site can get back up, and search engines show
the trail in results instead of the bare address.
hotdog-cms pack add breadcrumbs
Then add `{{ template "breadcrumbs" . }}` to the layouts that should show it.
The search engine data (BreadcrumbList) is written for every page once the
pack is installed. The docs pack has a trail of its own, so leave it out of
the docs layouts.
+8
View File
@@ -0,0 +1,8 @@
/* The breadcrumbs pack. Colors come from the theme's variables. */
.crumbs { margin: 0 0 14px; font-size: .9rem; color: var(--muted); }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 0; }
.crumbs li { display: inline-flex; align-items: baseline; min-width: 0; }
.crumbs li + li::before { content: "\203A"; margin: 0 8px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs [aria-current] { color: var(--text); max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+19
View File
@@ -0,0 +1,19 @@
name: breadcrumbs
version: 1.0.0
title: Breadcrumbs
description: A "Home › Articles › This page" trail above a page's title, and the same trail for search engines.
license: MIT
author: Coffey Labs LLC
notes: |
Add this line to the layouts that should show the trail, such as
layouts/page.html and layouts/article.html, above the page's title:
{{ template "breadcrumbs" . }}
The trail is the pages above this one, by address: /recipes/bread/rye/
shows Home › Recipes › Bread › Rye when /recipes/ and /recipes/bread/
exist. It isn't shown on the home page.
Search engines get the trail too (BreadcrumbList), on every page, as long
as the pack is installed and partials/schema.html has the pageData line
(see docs/packs.md).
@@ -0,0 +1,9 @@
{{/* The trail from the home page down to this one: Home › Articles › This page. */}}
{{ $t := trail . }}{{ if gt (len $t) 1 }}
<link rel="stylesheet" href="{{ asset "packs/breadcrumbs/breadcrumbs.css" }}">
<nav class="crumbs" aria-label="Breadcrumb">
<ol>
{{ range $i, $p := $t }}{{ if eq $p.Path $.Path }}<li><span aria-current="page">{{ $p.Title }}</span></li>{{ else }}<li><a href="{{ $p.Href }}">{{ $p.Title }}</a></li>{{ end }}{{ end }}
</ol>
</nav>
{{ end }}
+1 -1
View File
@@ -5,5 +5,5 @@ package packs
import "embed"
//go:embed all:calendar all:changelog all:contact-forms all:docs all:downloads all:faq all:gallery all:jobs all:location-and-hours all:menu-and-prices all:payment-links all:podcast all:portfolio all:recipes all:related-posts all:share-links all:shop all:table-of-contents all:tables all:team all:testimonials
//go:embed all:author-box all:breadcrumbs all:calendar all:changelog all:contact-forms all:docs all:downloads all:faq all:gallery all:jobs all:location-and-hours all:menu-and-prices all:payment-links all:podcast all:portfolio all:recipes all:related-posts all:series all:share-links all:shop all:table-of-contents all:tables all:team all:testimonials
var FS embed.FS
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 Coffey Labs LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+12
View File
@@ -0,0 +1,12 @@
# Series pack
Articles written in parts. Each part shows where it falls ("Part 2 of 5 in
Sourdough basics"), lists every part with the one you're reading marked, and
links to the previous and next part.
hotdog-cms pack add series
Give the articles the same `series:` in their front matter (and `part:`
numbers if they shouldn't simply go oldest first), and add
`{{ template "series" . }}` to `layouts/article.html`. Add `series` to
`taxonomies:` in `site.yaml` for a page per series, which the box links to.
+10
View File
@@ -0,0 +1,10 @@
/* The series pack. Colors come from the theme's variables. */
.series { margin: 24px 0; padding: 16px 20px; border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); background: var(--surface); }
.series-head { margin: 0; font-weight: 650; }
.series-where { color: var(--accent); }
.series-list { margin: 10px 0 0; padding-left: 1.4em; display: grid; gap: 4px; }
.series-list [aria-current] { font-weight: 650; }
.series-nav { display: flex; justify-content: space-between; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.series-nav a { display: grid; gap: 2px; font-weight: 600; text-decoration: none; max-width: 48%; }
.series-nav a span { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.series-next { margin-left: auto; text-align: right; }
+29
View File
@@ -0,0 +1,29 @@
name: series
version: 1.0.0
title: Series
description: Articles in parts, with "Part 2 of 5", every part listed, and links to the previous and next part.
license: MIT
author: Coffey Labs LLC
notes: |
Give every article in a series the same series: in its front matter:
---
title: "Sourdough basics: feeding your starter"
date: 2027-01-12
series: Sourdough basics
part: 2 # optional; without it, parts go oldest first
---
Then add this line to layouts/article.html, where the box should go
(above {{ .Content }}, or after it):
{{ template "series" . }}
It shows only on articles in a series of two parts or more. Parts are in
the order of their part: numbers when every part has one, otherwise oldest
first.
To give each series a page listing its parts, add series to taxonomies:
in site.yaml (taxonomies: [tags, series]); the box then links the series'
name to it. Leave commas out of series names if you do, since a comma
separates values there.
+19
View File
@@ -0,0 +1,19 @@
{{/* The series this article is part of: where it falls, every part, and the parts either side. */}}
{{ $parts := series . }}{{ if $parts }}
{{ $here := 0 }}{{ $prev := false }}{{ $next := false }}{{ $last := false }}{{ $found := false }}
{{ range $i, $p := $parts }}{{ if $found }}{{ if not $next }}{{ $next = $p }}{{ end }}{{ else if eq $p.Path $.Path }}{{ $found = true }}{{ $here = add $i 1 }}{{ $prev = $last }}{{ else }}{{ $last = $p }}{{ end }}{{ end }}
{{ $name := print .Params.series }}{{ $url := termURL "series" $name }}
<link rel="stylesheet" href="{{ asset "packs/series/series.css" }}">
<aside class="series" aria-label="Series: {{ $name }}">
<p class="series-head"><span class="series-where">Part {{ $here }} of {{ len $parts }}</span> in {{ if $url }}<a href="{{ $url }}">{{ $name }}</a>{{ else }}<span class="series-name">{{ $name }}</span>{{ end }}</p>
<ol class="series-list">
{{ range $parts }}<li>{{ if eq .Path $.Path }}<span aria-current="page">{{ .Title }}</span>{{ else }}<a href="{{ .Href }}">{{ .Title }}</a>{{ end }}</li>{{ end }}
</ol>
{{ if or $prev $next }}
<nav class="series-nav" aria-label="Other parts">
{{ with $prev }}<a class="series-prev" href="{{ .Href }}"><span>Previous part</span>{{ .Title }}</a>{{ end }}
{{ with $next }}<a class="series-next" href="{{ .Href }}"><span>Next part</span>{{ .Title }}</a>{{ end }}
</nav>
{{ end }}
</aside>
{{ end }}