split the theme's fragments into a directory, keeping the file form
One file held every fragment, and it gained one per feature all session: figure, gallery, icon, three admonitions, details, aside, contents. A theme author overriding one had to copy the file or redefine into it, and a diff of the theme became a diff of everything. Both forms are supported, because a small theme is happier with one file and the contract should not force a directory on it. Parse order is embedded file, embedded directory, site file, site directory, and the last definition wins — so the directory overrides the file within one source and a site overrides the binary either way. Verified with a site root using both at once: its shortcodes.html supplied `icon`, its shortcodes/note.html supplied `note`, the embedded directory supplied the rest, and with the same name in both the directory won. The embedded theme ships the directory only, seven files, so nothing is defined twice. parseSet takes globs now and lost a branch doing it. Its old guard — a literal embedded name must exist — had to go, since shortcodes.html is deliberately absent; the replacement is stronger, failing at startup when a set matches nothing anywhere, which also catches a renamed base.html.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{{/* Admonitions. One template per kind, because a call renders through a template of its own name — the
|
||||
markup is the theme's and the engine supplies only the name, the arguments and the rendered body
|
||||
(ADR-0064). `.Body` is already HTML. A theme with no template for a kind renders nothing, and the
|
||||
engine writes the body out unwrapped rather than losing it. */}}
|
||||
{{define "note"}}<aside class="admonition note"><p class="admonition-title">{{with .Args.title}}{{.}}{{else}}{{t $.Lang "note"}}{{end}}</p>{{.Body}}</aside>{{end}}
|
||||
{{define "warn"}}<aside class="admonition warn"><p class="admonition-title">{{with .Args.title}}{{.}}{{else}}{{t $.Lang "warn"}}{{end}}</p>{{.Body}}</aside>{{end}}
|
||||
{{define "tip"}}<aside class="admonition tip"><p class="admonition-title">{{with .Args.title}}{{.}}{{else}}{{t $.Lang "tip"}}{{end}}</p>{{.Body}}</aside>{{end}}
|
||||
@@ -0,0 +1,2 @@
|
||||
{{/* A margin note: beside the text where there is room, in the flow where there is not. CSS only. */}}
|
||||
{{define "aside"}}<aside class="side">{{with .Args.title}}<p class="side-title">{{.}}</p>{{end}}{{.Body}}</aside>{{end}}
|
||||
@@ -0,0 +1,6 @@
|
||||
{{/* An expandable section, and tabs, from one template. `<details>` needs no script; siblings sharing a
|
||||
`group` become mutually exclusive through the native `name` attribute, which is what tabs are. A
|
||||
browser too old for grouping simply opens them independently — the content is never hidden. */}}
|
||||
{{define "details"}}<details{{with .Args.group}} name="{{.}}"{{end}}{{if .Args.open}} open{{end}}>
|
||||
<summary>{{with .Args.summary}}{{.}}{{else}}{{with $.Args.title}}{{.}}{{else}}{{t $.Lang "details"}}{{end}}{{end}}</summary>
|
||||
{{.Body}}</details>{{end}}
|
||||
@@ -0,0 +1,17 @@
|
||||
{{/* `sizes` is layout knowledge, so it belongs to whoever wrote the layout. Without it a browser assumes
|
||||
100vw and fetches the widest variant for a thumbnail, which makes the derivative pass cost bandwidth
|
||||
rather than save it. These values describe *this* stylesheet — a 32rem measure, two gallery columns
|
||||
above 36rem — and a theme that changes the layout must change them with it (ADR-0068). */}}
|
||||
{{define "figure" -}}
|
||||
<figure>
|
||||
{{- range .Pictures}}
|
||||
<img src="{{.Src}}"{{if .Srcset}} srcset="{{.Srcset}}" sizes="(min-width: 36rem) 32rem, 100vw"{{end}}{{if .Width}} width="{{.Width}}" height="{{.Height}}"{{end}} alt="{{$.Args.alt}}">
|
||||
{{- end}}
|
||||
{{- if not .Pictures}}
|
||||
<img src="{{.Args.src}}" alt="{{.Args.alt}}">
|
||||
{{- end}}
|
||||
{{- if .Args.caption}}
|
||||
<figcaption>{{.Args.caption}}</figcaption>
|
||||
{{- end}}
|
||||
</figure>
|
||||
{{- end}}
|
||||
@@ -0,0 +1,9 @@
|
||||
{{define "gallery" -}}
|
||||
{{if .Pictures -}}
|
||||
<div class="gallery">
|
||||
{{- range .Pictures}}
|
||||
<figure><img src="{{.Src}}"{{if .Srcset}} srcset="{{.Srcset}}" sizes="(min-width: 36rem) 16rem, 100vw"{{end}}{{if .Width}} width="{{.Width}}" height="{{.Height}}"{{end}} loading="lazy" decoding="async" alt=""></figure>
|
||||
{{- end}}
|
||||
</div>
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{/* One template for the whole set: which names exist is the theme's business, never the engine's
|
||||
(ADR-0063). Unicode here, so the reference theme ships no sprite, no font and no asset — a theme
|
||||
wanting drawn icons redefines this block and emits <use> against its own sprite. An unknown name
|
||||
renders nothing, which is how a theme says so, and the engine puts the author's text back. */}}
|
||||
{{define "icon"}}
|
||||
{{- if eq .Args.name "warn"}}⚠️
|
||||
{{- else if eq .Args.name "note"}}ℹ️
|
||||
{{- else if eq .Args.name "tip"}}💡
|
||||
{{- else if eq .Args.name "star"}}⭐
|
||||
{{- else if eq .Args.name "check"}}✅
|
||||
{{- else if eq .Args.name "cross"}}❌
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{/* A flat list with a level class per entry, so nesting is a CSS decision rather than a markup one: the
|
||||
engine supplies depth and the theme decides whether to indent (ADR-0065). An entry with no id is
|
||||
skipped rather than linked nowhere. */}}
|
||||
{{define "toc"}}
|
||||
{{- if .Headings}}<nav class="toc" aria-label="{{t .Lang "contents"}}">
|
||||
<p class="toc-title">{{t .Lang "contents"}}</p>
|
||||
<ol>
|
||||
{{- range .Headings}}{{if .ID}}
|
||||
<li class="toc-{{.Level}}"><a href="#{{.ID}}">{{.Text}}</a></li>
|
||||
{{- end}}{{end}}
|
||||
</ol></nav>
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
Reference in New Issue
Block a user