Files
FixIt/layouts/_markup/render-table.html
T
Cell 7a2c04cba7 feat(assets): add table auto-numbering and sorting support
- Add CSS counter-based table auto-numbering with i18n support
- Add client-side table sorting with numeric/string/date detection
- Support per-table opt-out via Markdown attributes (number=false, sort=false)
- Add table caption support via {caption="..."} attribute
- Extract table styles from _content.scss to dedicated _table.scss
- Add TableConfig TypeScript interface
- Register table-sort script via .Store.hasTableSort for lazy loading
2026-09-01 02:06:56 +08:00

71 lines
2.2 KiB
HTML

{{- /*
Custom table render hook for FixIt theme.
- Wraps tables in a scrollable container
- Supports auto-numbering via CSS counters (config: params.table.number)
- Supports client-side sorting (config: params.table.sort)
- Supports table captions via Markdown attribute {caption="..."}
- Per-table override via Markdown attributes (e.g., {number=false, sort=false})
See https://gohugo.io/render-hooks/tables/
*/ -}}
{{- $pageConfig := dict "Page" .Page "Key" "table" | partial "function/param.html" | merge .Attributes -}}
{{- $config := .Attributes | merge $pageConfig -}}
{{- $caption := .Attributes.caption -}}
{{- $attrs := "" -}}
{{- if $config.number }}
{{- $attrs = printf "%s data-table-numbered" $attrs }}
{{- end -}}
{{- if $config.sort }}
{{- $attrs = printf "%s data-sortable" $attrs }}
{{- .Page.Store.Set "hasTableSort" true }}
{{- end -}}
{{- range $k, $v := .Attributes }}
{{- if and $v (ne $k "number") (ne $k "caption") (ne $k "sort") }}
{{- $attrs = printf "%s %s=%q" $attrs $k $v }}
{{- end }}
{{- end -}}
{{- $attrs = partial "function/trim.html" $attrs -}}
<div class="table-wrapper">
<table {{ $attrs | safeHTMLAttr }}>
{{- if or $config.number $caption }}
<caption>
{{- if $config.number }}<span class="table-number" data-i18n-table="{{ T `assets.table` }}"></span>{{ end -}}
{{- with $caption }}<span class="table-caption">{{ . }}</span>{{ end -}}
</caption>
{{- end -}}
<thead>
{{- range .THead }}
<tr>
{{- range . }}
<th
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
{{- end -}}
>
{{- .Text -}}
</th>
{{- end }}
</tr>
{{- end }}
</thead>
<tbody>
{{- range .TBody }}
<tr>
{{- range . }}
<td
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
{{- end -}}
>
{{- .Text -}}
</td>
{{- end }}
</tr>
{{- end }}
</tbody>
</table>
</div>
{{- /* EOF */ -}}