table.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. {{/* Table Shortcode for Wowchemy. */}}
  2. {{/* Load a CSV table from page dir falling back back to remote URL */}}
  3. {{/* Defaults to expecting a comma-separated CSV with a header row. */}}
  4. {{ $src := .Get "path" }}
  5. {{ $delimiter := .Get "delimiter" | default "," }}
  6. {{ $useHeaderRow := (eq (lower (.Get "header")) "true") | default true }}
  7. {{ $caption := .Get "caption" }}
  8. {{ $is_remote := strings.HasPrefix $src "http" }}
  9. {{ if not $is_remote }}
  10. {{ $src = path.Join "content" $.Page.File.Dir $src }}
  11. {{ end }}
  12. {{ $rows := getCSV $delimiter $src }}
  13. <table class="table">
  14. {{ if $useHeaderRow }}
  15. {{ $headerRow := index $rows 0 }}
  16. {{ $rows = after 1 $rows }}
  17. <tr> {{ range $headerRow }} <th>{{ . | markdownify | emojify }}</th> {{ end }} </tr>
  18. {{ end }}
  19. {{ range $rows }}
  20. <tr>
  21. {{ range . }}
  22. {{ if (findRE "^\\d+$" .) }}
  23. <td data-table-dtype="number">{{ . }}</td>
  24. {{ else }}
  25. <td data-table-dtype="text">{{ . | markdownify | emojify }}</td>
  26. {{ end }}
  27. {{ end }}
  28. </tr>
  29. {{ end }}
  30. {{ if $caption }}
  31. <caption>{{ $caption | markdownify | emojify }}</caption>
  32. {{ end }}
  33. </table>