aboutsummaryrefslogtreecommitdiff
path: root/themes/hugo-pt2021/layouts/shortcodes
diff options
context:
space:
mode:
Diffstat (limited to 'themes/hugo-pt2021/layouts/shortcodes')
-rw-r--r--themes/hugo-pt2021/layouts/shortcodes/table.html35
1 files changed, 31 insertions, 4 deletions
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 -}}
+
<table
{{/* emit table ID */}}
{{- if $table.id -}}id='{{- $table.id -}}'{{- end -}}
@@ -180,7 +207,7 @@ you can override the `class` attribute for individual cells.
title='{{- default $col.name $col.tip -}}'
aria-label='{{- default $col.name $col.tip -}}'
data-{{- $dp -}}th_x='{{- $x -}}'
- data-{{- $dp -}}id='{{- $col.id -}}'
+ data-{{- $dp -}}th_id='{{- $col.id -}}'
>
{{- $col.name -}}
</th>
@@ -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 -}}'