Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions layouts/_default/_markup/render-heading.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- /*
Heading render hook.
Emits <hN id="…">…<a href="#…" class="anchor" aria-label="…">¶</a></hN>.
*/ -}}
{{- $label := i18n "AnchorLabel" | default "Anchor" -}}
<h{{ .Level }} id="{{ .Anchor | safeURL }}">
{{- .Text | safeHTML -}}
<a href="#{{ .Anchor | safeURL }}" class="anchor" aria-label="{{ $label }}">&para;</a>
</h{{ .Level }}>
44 changes: 44 additions & 0 deletions layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- /*
Image render hook.
Emits <img> 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) -}}
<img src="{{ $orig.RelPermalink }}"
{{- with $alt }} alt="{{ . }}"{{ end }}
{{- with $title }} title="{{ . }}"{{ end }}
width="{{ $w }}" height="{{ $h }}"
srcset="{{ delimit $srcset ", " }}"
sizes="(max-width: 768px) 100vw, 768px"
loading="lazy" decoding="async">
{{- else -}}
<img src="{{ $src | safeURL }}"
{{- with $alt }} alt="{{ . }}"{{ end }}
{{- with $title }} title="{{ . }}"{{ end }}
loading="lazy" decoding="async">
{{- end -}}
13 changes: 6 additions & 7 deletions layouts/_default/_markup/render-inline.html
Original file line number Diff line number Diff line change
@@ -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 }}
23 changes: 12 additions & 11 deletions layouts/_default/_markup/render-link.html
Original file line number Diff line number Diff line change
@@ -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 -}}

<a href="{{ $fullUrl | safeURL }}"
{{- $isInternalAbsolute := and (not $isExternal) (strings.HasPrefix $url "/") -}}
<a href="{{ $url | safeURL }}"
{{- with .Title }} title="{{ . }}"{{ end -}}
{{- if $isExternal }} rel="external" target="_blank"{{ end -}}
{{- if and (not $isExternal) (strings.HasPrefix $url "/") }} data-internal-link="{{ $url }}" class="internal-link"{{ end -}}
>
{{- with .Text }}{{ . }}{{ end -}}
</a>
{{- /* chomp trailing newline */ -}}
{{- if $isInternalAbsolute }} data-internal-link="{{ $url }}" class="internal-link"{{ end -}}
>{{- with .Text }}{{ . | safeHTML }}{{ end -}}</a>
{{- /*
Note: .Text is rendered inline content (may contain emphasis tags etc.);
safeHTML preserves those tags.
*/ -}}
11 changes: 7 additions & 4 deletions layouts/_default/_markup/render-paragraph.html
Original file line number Diff line number Diff line change
@@ -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 <p> 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 <p> wrapper */}}
{{ $content | safeHTML }}
{{- else -}}
{{/* All other content including paragraphs with inline math - wrap in <p> and let KaTeX process */}}
<p>{{ $content }}</p>
{{- end -}}
38 changes: 19 additions & 19 deletions layouts/partials/recent-posts-grid.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<div class="recent-posts-grid">
{{ $recentPosts := first 6 (where site.RegularPages "Type" "posts") }}
{{ range $recentPosts }}
<div class="recent-post-card"> <!-- Changed from post-card -->
{{- $sections := site.Params.mainSections | default (slice "posts") -}}
{{- $recentPosts := first 6 (where site.RegularPages "Section" "in" $sections) -}}
{{- range $recentPosts }}
<div class="recent-post-card">
<h3 class="post-title"><a href="{{ .Permalink | relURL }}" class="post-link">{{ .Title }}</a></h3>
<div class="post-meta">
<div class="post-date">{{ .Date.Format "Jan 2, 2006" }}</div>
{{ if .Params.tags }}
<div class="post-date">{{ time.Format "Jan 2, 2006" .Date }}</div>
{{- if .Params.tags }}
<div class="post-tags">
{{ $tagCount := len .Params.tags }}
{{ $maxTags := 2 }}
{{ $allTags := .Params.tags }}

{{ range $index, $tag := .Params.tags }}
{{ if lt $index $maxTags }}
<span class="tag">{{ . }}</span>
{{ else if eq $index $maxTags }}
{{ $remainingTags := after $maxTags $allTags }}
{{- $tagCount := len .Params.tags -}}
{{- $maxTags := 2 -}}
{{- $allTags := .Params.tags -}}
{{- range $index, $tag := .Params.tags }}
{{- if lt $index $maxTags }}
<span class="tag">{{ $tag }}</span>
{{- else if eq $index $maxTags }}
{{- $remainingTags := after $maxTags $allTags -}}
<span class="tag tag-more" data-tooltip="{{ delimit $remainingTags ", " }}">+{{ sub $tagCount $maxTags }}</span>
{{ break }}
{{ end }}
{{ end }}
{{- break -}}
{{- end -}}
{{- end }}
</div>
{{ end }}
{{- end }}
</div>
<div class="post-summary">{{ .Summary | plainify | truncate 200 }}</div>
</div>
{{ end }}
{{- end }}
</div>
19 changes: 11 additions & 8 deletions layouts/shortcodes/cite.html
Original file line number Diff line number Diff line change
@@ -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 -}}
<sup class="citation-ref" data-citation-key="{{ $citationKey }}" title="{{ $existingCitation }}">{{ $existingNum }}</sup>
{{- 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 `<sup class="citation-ref" data-citation-key="%s">%d</sup><span class="citation-marker" data-citation-key="%s" data-bib-file="%s" data-citation-style="%s" data-show-notes="%s" data-citation-id="%s"></span><span class="sidenote sidenote-hidden citation-sidenote" id="%s" lang="%s" data-citation-key="%s" data-bib-file="%s" data-citation-style="%s" data-show-notes="%s"><sup class="citation-sup">%d.</sup><span class="citation citation-inline" data-citation-key="%s" data-bib-file="%s" data-citation-style="%s"></span></span>` $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" -}}
<sup class="citation-ref" data-citation-key="{{ $citationKey }}">{{ $num }}</sup><span class="citation-marker" data-citation-key="{{ $citationKey }}" data-bib-file="{{ $bibFile }}" data-citation-style="{{ $style }}" data-show-notes="{{ $showNotes }}" data-citation-id="{{ $citationId }}"></span><span class="sidenote sidenote-hidden citation-sidenote" id="{{ $citationId }}" lang="{{ $lang }}" data-citation-key="{{ $citationKey }}" data-bib-file="{{ $bibFile }}" data-citation-style="{{ $style }}" data-show-notes="{{ $showNotes }}"><sup class="citation-sup">{{ $num }}.</sup><span class="citation citation-inline" data-citation-key="{{ $citationKey }}" data-bib-file="{{ $bibFile }}" data-citation-style="{{ $style }}"></span></span>
{{- $citations := .Page.Store.Get "citations" | default dict -}}
{{- $citations = merge $citations (dict $citationKey (dict "id" $citationId "style" $style "bibFile" $bibFile)) -}}
{{- .Page.Store.Set "citations" $citations -}}
Expand Down
12 changes: 9 additions & 3 deletions layouts/shortcodes/sidenote.html
Original file line number Diff line number Diff line change
@@ -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 `<sup class="sidenote-ref" title="%s">%s</sup><span class="sidenote sidenote-hidden" lang="%s"><sup class="sidenote-sup">%s.</sup>%s</span>` $cleanContent $letter (.Site.Language.Lang | default "en") $letter $content | safeHTML -}}
{{- $lang := site.Language.Lang | default "en" -}}
<sup class="sidenote-ref" title="{{ $cleanContent }}">{{ $letter }}</sup><span class="sidenote sidenote-hidden" lang="{{ $lang }}"><sup class="sidenote-sup">{{ $letter }}.</sup>{{ $content }}</span>