123456789101112131415161718192021222324252627282930313233343536 |
- {{/* Table Shortcode for Wowchemy. */}}
- {{/* Load a CSV table from page dir falling back back to remote URL */}}
- {{/* Defaults to expecting a comma-separated CSV with a header row. */}}
- {{ $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 }}
- <table class="table">
- {{ if $useHeaderRow }}
- {{ $headerRow := index $rows 0 }}
- {{ $rows = after 1 $rows }}
- <tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
- {{ end }}
- {{ range $rows }}
- <tr>
- {{ range . }}
- {{ if (findRE "^\\d+$" .) }}
- <td data-table-dtype="number">{{ . }}</td>
- {{ else }}
- <td data-table-dtype="text">{{ . | markdownify | emojify }}</td>
- {{ end }}
- {{ end }}
- </tr>
- {{ end }}
- {{ if $caption }}
- <caption>{{ $caption | markdownify | emojify }}</caption>
- {{ end }}
- </table>
|