From 8c38dc207a917a8df51c3bf50e3ba189d916d5cd Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 25 Oct 2021 11:00:19 -0400 Subject: themes/hugo-pt2021/layouts/shortcodes/table.html: add table config search path (table, page, site, default), add pure array table support, use data-th_id and data-td_id instead of data-id and data-col_id, respectively --- themes/hugo-pt2021/layouts/shortcodes/table.html | 35 +++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'themes/hugo-pt2021/layouts/shortcodes') diff --git a/themes/hugo-pt2021/layouts/shortcodes/table.html b/themes/hugo-pt2021/layouts/shortcodes/table.html index 707b469..6fa778b 100644 --- a/themes/hugo-pt2021/layouts/shortcodes/table.html +++ b/themes/hugo-pt2021/layouts/shortcodes/table.html @@ -119,8 +119,24 @@ You can also configure alignment on a per-column or per-cell basis, and you can override the `class` attribute for individual cells. */}} -{{/* get config from site params (default to bulma) */}} -{{- $config := default (dict "data_prefix" "" "table_base_css" "table" "cell_align_left" "has-text-left" "cell_align_center" "has-text-centered" "cell_align_justify" "has-text-justified" "cell_align_right" "has-text-right") $.Site.Params.table_shortcode -}} +{{/* get table config + +the search config path is: +1. table "config" property (see below) +2. "table_config" dictionary in page front matter +3. "table_config" dictionary in site params +4. default values (defaults to bulma classes) + +*/}} +{{/* set default config */}} +{{- $config := (dict "data_prefix" "" "table_base_css" "table" "cell_align_left" "has-text-left" "cell_align_center" "has-text-centered" "cell_align_justify" "has-text-justified" "cell_align_right" "has-text-right") -}} +{{- if index $.Page.Params "table_config" -}} + {{/* use table config from page front matter */}} + {{- $config = $.Params.table_shortcode -}} +{{- else if index $.Site.Params "table_config" -}} + {{/* use table config from site config */}} + {{- $config = $.Site.Params.table_shortcode -}} +{{- end -}} {{/* get data prefix */}} {{- $dp := $config.data_prefix | safeHTMLAttr -}} @@ -135,6 +151,17 @@ you can override the `class` attribute for individual cells. {{- $table = (index $.Page.Params "tables" (.Get 0)) -}} {{- end -}} +{{/* handle pure array table */}} +{{- if reflect.IsSlice $table -}} + {{/* convert table to map { "cols": cols", "rows": rows } */}} + {{- $table = (dict "cols" (index $table 0) "rows" (last (sub (len $table) 1) $table)) -}} +{{- end -}} + +{{- if (index $table "config") -}} + {{/* use config from table */}} + {{- $config = $table.config -}} +{{- end -}} + {{- $col.name -}} @@ -311,7 +338,7 @@ you can override the `class` attribute for individual cells. class='{{- $css -}}' data-{{- $dp -}}td_x='{{- $x -}}' - data-{{- $dp -}}col_id='{{- $col.id -}}' + data-{{- $dp -}}td_id='{{- $col.id -}}' {{- if gt $colspan 1 -}} colspan='{{- $colspan -}}' -- cgit v1.2.3