diff --git a/layouts/_default/_markup/render-heading.html b/layouts/_default/_markup/render-heading.html new file mode 100644 index 0000000..4b2ed19 --- /dev/null +++ b/layouts/_default/_markup/render-heading.html @@ -0,0 +1,9 @@ +{{- /* + Heading render hook. + Emits . +*/ -}} +{{- $label := i18n "AnchorLabel" | default "Anchor" -}} + + {{- .Text | safeHTML -}} + + diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html new file mode 100644 index 0000000..5de3bfb --- /dev/null +++ b/layouts/_default/_markup/render-image.html @@ -0,0 +1,44 @@ +{{- /* + Image render hook. + Emits with loading="lazy" decoding="async". When the source resolves + to a Page Resource, derives a responsive srcset via images.Process/Resize + and sets intrinsic width/height to reduce CLS. +*/ -}} +{{- $src := .Destination -}} +{{- $alt := .Text -}} +{{- $title := .Title -}} +{{- $isExternal := or (strings.HasPrefix $src "http:") (strings.HasPrefix $src "https:") (strings.HasPrefix $src "//") -}} +{{- $resource := false -}} +{{- if and (not $isExternal) .Page -}} + {{- with .Page.Resources.GetMatch $src -}} + {{- if eq .ResourceType "image" -}} + {{- $resource = . -}} + {{- end -}} + {{- end -}} +{{- end -}} +{{- if $resource -}} + {{- $orig := $resource -}} + {{- $w := $orig.Width -}} + {{- $h := $orig.Height -}} + {{- $widths := slice 480 768 1200 1600 -}} + {{- $srcset := slice -}} + {{- range $widths -}} + {{- if le . $w -}} + {{- $img := $orig.Resize (printf "%dx" .) -}} + {{- $srcset = $srcset | append (printf "%s %dw" $img.RelPermalink .) -}} + {{- end -}} + {{- end -}} + {{- $srcset = $srcset | append (printf "%s %dw" $orig.RelPermalink $w) -}} + {{ . }} +{{- else -}} + {{ . }} +{{- end -}} diff --git a/layouts/_default/_markup/render-inline.html b/layouts/_default/_markup/render-inline.html index bf904a2..98c6f6e 100644 --- a/layouts/_default/_markup/render-inline.html +++ b/layouts/_default/_markup/render-inline.html @@ -1,8 +1,7 @@ +{{- /* + Inline render hook. + Trust assumption: inline content is authored markdown (LaTeX math source); + safeHTML preserves $...$ delimiters for client-side KaTeX processing. +*/ -}} {{- $text := .Text | strings.TrimSpace -}} -{{- if and (hasPrefix $text "$") (hasSuffix $text "$") (not (hasPrefix $text "$$")) -}} - {{/* Inline math - output directly without wrapping */}} - {{ $text | safeHTML }} -{{- else -}} - {{/* Regular inline text */}} - {{ $text | safeHTML }} -{{- end -}} +{{ $text | safeHTML }} diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html index d09802f..39b3abc 100644 --- a/layouts/_default/_markup/render-link.html +++ b/layouts/_default/_markup/render-link.html @@ -1,15 +1,16 @@ +{{- /* + Link render hook. + Hugo's render-link context provides resolved URLs; no manual BaseURL prepend needed. +*/ -}} {{- $url := .Destination -}} {{- $isExternal := or (strings.HasPrefix $url "http:") (strings.HasPrefix $url "https:") -}} -{{- $fullUrl := $url -}} -{{- if and (not $isExternal) (strings.HasPrefix $url "/") -}} - {{- $fullUrl = printf "%s%s" (.Page.Site.BaseURL | strings.TrimSuffix "/") $url -}} -{{- end -}} - - - {{- with .Text }}{{ . }}{{ end -}} - -{{- /* chomp trailing newline */ -}} + {{- if $isInternalAbsolute }} data-internal-link="{{ $url }}" class="internal-link"{{ end -}} +>{{- with .Text }}{{ . | safeHTML }}{{ end -}} +{{- /* + Note: .Text is rendered inline content (may contain emphasis tags etc.); + safeHTML preserves those tags. +*/ -}} diff --git a/layouts/_default/_markup/render-paragraph.html b/layouts/_default/_markup/render-paragraph.html index 95d8e0e..fda6721 100644 --- a/layouts/_default/_markup/render-paragraph.html +++ b/layouts/_default/_markup/render-paragraph.html @@ -1,11 +1,14 @@ -{{- $content := .Inner | strings.TrimSpace -}} +{{- /* + Paragraph render hook. + Trust assumption: math branches emit raw markdown ($$...$$ / $...$) so + client-side KaTeX can process it; safeHTML is intentional there. + Default branch lets Hugo's auto-escaping handle authored content. +*/ -}} +{{- $content := .Text | strings.TrimSpace -}} {{- if and (hasPrefix $content "$$") (hasSuffix $content "$$") -}} - {{/* Block math - output directly without

wrapper */}} {{ $content | safeHTML }} {{- else if and (hasPrefix $content "$") (hasSuffix $content "$") (not (strings.Contains $content "\n")) (not (strings.Contains $content " ")) -}} - {{/* Single inline math expression - output directly without

wrapper */}} {{ $content | safeHTML }} {{- else -}} - {{/* All other content including paragraphs with inline math - wrap in

and let KaTeX process */}}

{{ $content }}

{{- end -}} diff --git a/layouts/partials/recent-posts-grid.html b/layouts/partials/recent-posts-grid.html index 72d98d2..b601f9f 100644 --- a/layouts/partials/recent-posts-grid.html +++ b/layouts/partials/recent-posts-grid.html @@ -1,29 +1,29 @@
- {{ $recentPosts := first 6 (where site.RegularPages "Type" "posts") }} - {{ range $recentPosts }} -
+ {{- $sections := site.Params.mainSections | default (slice "posts") -}} + {{- $recentPosts := first 6 (where site.RegularPages "Section" "in" $sections) -}} + {{- range $recentPosts }} +

{{ .Title }}

{{ .Summary | plainify | truncate 200 }}
- {{ end }} + {{- end }}
diff --git a/layouts/shortcodes/cite.html b/layouts/shortcodes/cite.html index acf9e96..27fb2f8 100644 --- a/layouts/shortcodes/cite.html +++ b/layouts/shortcodes/cite.html @@ -1,21 +1,24 @@ +{{- /* + Citation shortcode. + Usage: {{< cite "key" "references.bib" "apa" "false" >}} + Stores citation state on .Page.Store (Hugo 0.85+). +*/ -}} {{- $citationKey := .Get 0 | default "" -}} {{- $bibFile := .Get 1 | default "references.bib" -}} -{{- $existingNum := .Page.Scratch.Get (printf "citation-%s-num" $citationKey) -}} +{{- $existingNum := .Page.Store.Get (printf "citation-%s-num" $citationKey) -}} {{- if $existingNum -}} - {{- $citationId := printf "citation-%s" $citationKey -}} {{- $existingCitation := index (.Page.Store.Get "citations") $citationKey -}} {{ $existingNum }} {{- else -}} - {{- /* New citation - increment counter and store */ -}} - {{- $num := .Page.Scratch.Get "citeCounter" | default 0 -}} + {{- $num := .Page.Store.Get "citeCounter" | default 0 -}} {{- $num = add $num 1 -}} - {{- .Page.Scratch.Set "citeCounter" $num -}} - {{- .Page.Scratch.Set (printf "citation-%s-num" $citationKey) $num -}} + {{- .Page.Store.Set "citeCounter" $num -}} + {{- .Page.Store.Set (printf "citation-%s-num" $citationKey) $num -}} {{- $style := .Get 2 | default "apa" -}} {{- $showNotes := .Get 3 | default "false" -}} {{- $citationId := printf "citation-%s" $citationKey -}} - {{- printf `%d%d.` $citationKey $num $citationKey $bibFile $style $showNotes $citationId $citationId (.Site.Language.Lang | default "en") $citationKey $bibFile $style $showNotes $num $citationKey $bibFile $style | safeHTML -}} - {{- /* Store citation data for reuse */ -}} + {{- $lang := site.Language.Lang | default "en" -}} +{{ $num }}{{ $num }}. {{- $citations := .Page.Store.Get "citations" | default dict -}} {{- $citations = merge $citations (dict $citationKey (dict "id" $citationId "style" $style "bibFile" $bibFile)) -}} {{- .Page.Store.Set "citations" $citations -}} diff --git a/layouts/shortcodes/sidenote.html b/layouts/shortcodes/sidenote.html index 061da42..02b138e 100644 --- a/layouts/shortcodes/sidenote.html +++ b/layouts/shortcodes/sidenote.html @@ -1,7 +1,13 @@ -{{- $counter := .Page.Scratch.Get "sidenoteCounter" | default 0 -}} +{{- /* + Sidenote shortcode. + Usage: {{< sidenote >}}note text{{< /sidenote >}} + Tracks counter on .Page.Store (Hugo 0.85+). +*/ -}} +{{- $counter := .Page.Store.Get "sidenoteCounter" | default 0 -}} {{- $counter = add $counter 1 -}} -{{- .Page.Scratch.Set "sidenoteCounter" $counter -}} +{{- .Page.Store.Set "sidenoteCounter" $counter -}} {{- $letter := printf "%c" (add $counter 96) -}} {{- $content := .Inner | markdownify -}} {{- $cleanContent := $content | plainify -}} -{{- printf `%s%s.%s` $cleanContent $letter (.Site.Language.Lang | default "en") $letter $content | safeHTML -}} +{{- $lang := site.Language.Lang | default "en" -}} +{{ $letter }}{{ $letter }}.{{ $content }}