Skip to content

Commit

Permalink
feat(shortcode): support Hugo v0.123 deprecation of GetCSV
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gcushen committed Mar 3, 2024
1 parent cee6e1e commit 07fe0da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
13 changes: 7 additions & 6 deletions modules/blox-bootstrap/layouts/shortcodes/table.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{/* Table Shortcode for Hugo Blox Builder. */}}
{{/* Load a CSV table from page dir falling back back to remote URL */}}
{{/* Load a CSV table from page dir falling back to remote URL */}}
{{/* Defaults to expecting a comma-separated CSV with a header row. */}}

{{/*
Expand All @@ -23,17 +23,17 @@
{{ $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 }}
{{ $rows := transform.Unmarshal (dict "delimiter" $delimiter) (.Page.Resources.Get $src).Content }}

<table class="table">
{{ if $useHeaderRow }}
{{ $headerRow := index $rows 0 }}
{{ $rows = after 1 $rows }}
<tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
<thead>
<tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
</thead>
{{ end }}
<tbody>
{{ range $rows }}
<tr>
{{ range . }}
Expand All @@ -45,6 +45,7 @@
{{ end }}
</tr>
{{ end }}
</tbody>
{{ if $caption }}
<caption>{{ $caption | markdownify | emojify }}</caption>
{{ end }}
Expand Down
22 changes: 17 additions & 5 deletions modules/blox-tailwind/layouts/shortcodes/table.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
{{/* Table Shortcode for Hugo Blox Builder. */}}
{{/* Load a CSV table from page dir falling back back to remote URL */}}
{{/* 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" }}
{{ if not $is_remote }}
{{ $src = path.Join "content" $.Page.File.Dir $src }}
{{ end }}
{{ $rows := getCSV $delimiter $src }}
{{ $rows := transform.Unmarshal (dict "delimiter" $delimiter) (.Page.Resources.Get $src).Content }}

<table class="table-auto">
{{ if $useHeaderRow }}
Expand Down

0 comments on commit 07fe0da

Please sign in to comment.