mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-12 18:15:31 +00:00
feat: add Table shortcode to render a CSV (#2393)
This commit is contained in:
1 parent
18817339c3
commit
44819d4299
1 file changed
+36
@@ -0,0 +1,36 @@
|
||||
{{/* Table Shortcode for Wowchemy. */}}
|
||||
{{/* Load table from page dir falling back back to remote URL */}}
|
||||
{{/* Supports delimiter separated files. The default delimiter is ',' */}}
|
||||
|
||||
{{ $src := .Get "src" }}
|
||||
{{ $delimiter := .Get "delimiter" | default "," }}
|
||||
{{ $useHeaderRow := .Get "header" | default true }}
|
||||
{{ $caption := .Get "caption" }}
|
||||
|
||||
{{ $is_remote := strings.HasPrefix $src "http" }}
|
||||
{{ if not $is_remote }}
|
||||
{{ $src = path.Join "content" $.Page.File.Dir $src }}
|
||||
{{ end }}
|
||||
{{ $rows := getCSV $delimiter $src }}
|
||||
|
||||
<table>
|
||||
{{ if $useHeaderRow }}
|
||||
{{ $headerRow := index $rows 0 }}
|
||||
{{ $rows = after 1 $rows }}
|
||||
<tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
|
||||
{{ end }}
|
||||
{{ 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 }}
|
||||
{{ if $caption }}
|
||||
<caption>{{ $caption | markdownify | emojify }}</caption>
|
||||
{{ end }}
|
||||
</table>
|
||||
Reference in new issue
Block a user