diff options
author | Paul Duncan <pabs@pablotron.org> | 2021-10-25 11:00:19 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2021-10-25 11:00:19 -0400 |
commit | 8c38dc207a917a8df51c3bf50e3ba189d916d5cd (patch) | |
tree | 911d000e4ac2eec39844fce143ea1d1634f3a87a /themes/hugo-pt2021 | |
parent | 070809dbea45e9d9c31d13fe5069c2f9671c0847 (diff) | |
download | pablotron.org-8c38dc207a917a8df51c3bf50e3ba189d916d5cd.tar.bz2 pablotron.org-8c38dc207a917a8df51c3bf50e3ba189d916d5cd.zip |
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
Diffstat (limited to 'themes/hugo-pt2021')
-rw-r--r-- | themes/hugo-pt2021/layouts/shortcodes/table.html | 35 |
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 -}}' |