mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-05 18:14:12 +00:00
Resolves following Hugo issue: INFO deprecated: data.GetCSV was deprecated in Hugo v0.123.0 and will be removed in a future release. use resources.Get or resources.GetRemote with transform.Unmarshal.
53 lines
1.6 KiB
HTML
53 lines
1.6 KiB
HTML
{{/* Table Shortcode for Hugo Blox Builder. */}}
|
|
{{/* Load a CSV table from page dir falling back to remote URL */}}
|
|
{{/* Defaults to expecting a comma-separated CSV with a header row. */}}
|
|
|
|
{{/*
|
|
Docs: https://docs.hugoblox.com/content/writing-markdown-latex/#csv-table
|
|
|
|
Parameters
|
|
----------
|
|
src :
|
|
Path or url to the csv table. Path is relative to the folder where the shortcode is called.
|
|
delimiter : default ","
|
|
Field delimiter.
|
|
header : default "true"
|
|
If "true", the first row is rendered as the header.
|
|
caption : optional
|
|
Caption for the table.
|
|
*/}}
|
|
|
|
{{ $src := .Get "path" }}
|
|
{{ $delimiter := .Get "delimiter" | default "," }}
|
|
{{ $useHeaderRow := (eq (lower (.Get "header")) "true") | default true }}
|
|
{{ $caption := .Get "caption" }}
|
|
|
|
{{ $is_remote := strings.HasPrefix $src "http" }}
|
|
{{ $rows := transform.Unmarshal (dict "delimiter" $delimiter) (.Page.Resources.Get $src).Content }}
|
|
|
|
<table class="table">
|
|
{{ if $useHeaderRow }}
|
|
{{ $headerRow := index $rows 0 }}
|
|
{{ $rows = after 1 $rows }}
|
|
<thead>
|
|
<tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
|
|
</thead>
|
|
{{ end }}
|
|
<tbody>
|
|
{{ range $rows }}
|
|
<tr>
|
|
{{ range . }}
|
|
{{ if (findRE "^\\d+$" .) }}
|
|
<td data-table-dtype="number">{{ . }}</td>
|
|
{{ else }}
|
|
<td data-table-dtype="text">{{ . | markdownify | emojify }}</td>
|
|
{{ end }}
|
|
{{ end }}
|
|
</tr>
|
|
{{ end }}
|
|
</tbody>
|
|
{{ if $caption }}
|
|
<caption>{{ $caption | markdownify | emojify }}</caption>
|
|
{{ end }}
|
|
</table>
|