From 07fe0da177765caea9f83b0412ca7e801893501e Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 3 Mar 2024 16:56:40 +0000 Subject: [PATCH] feat(shortcode): support Hugo v0.123 deprecation of GetCSV 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. --- .../layouts/shortcodes/table.html | 13 ++++++----- .../layouts/shortcodes/table.html | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/modules/blox-bootstrap/layouts/shortcodes/table.html b/modules/blox-bootstrap/layouts/shortcodes/table.html index bc04b34a..9d5106c8 100644 --- a/modules/blox-bootstrap/layouts/shortcodes/table.html +++ b/modules/blox-bootstrap/layouts/shortcodes/table.html @@ -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. */}} {{/* @@ -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 }} {{ if $useHeaderRow }} {{ $headerRow := index $rows 0 }} {{ $rows = after 1 $rows }} - {{ range $headerRow }} {{ end }} + + {{ range $headerRow }} {{ end }} + {{ end }} + {{ range $rows }} {{ range . }} @@ -45,6 +45,7 @@ {{ end }} {{ end }} + {{ if $caption }} {{ end }} diff --git a/modules/blox-tailwind/layouts/shortcodes/table.html b/modules/blox-tailwind/layouts/shortcodes/table.html index 9dedb7d6..37a5e651 100644 --- a/modules/blox-tailwind/layouts/shortcodes/table.html +++ b/modules/blox-tailwind/layouts/shortcodes/table.html @@ -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 }}
{{ . | markdownify | emojify }}
{{ . | markdownify | emojify }}
{{ $caption | markdownify | emojify }}
{{ if $useHeaderRow }}