|
| 1 | +{{/* Group single-tag includes like: |
| 2 | + {{< include "acm/how-to/policies-intro" >}} |
| 3 | + {{< include "acm/how-to/policies-proxy-intro.md" >}} |
| 4 | + */}} |
| 5 | + |
| 6 | +{{ $short := .Shortcode }} |
| 7 | +{{ $site := .Site }} |
| 8 | + |
| 9 | +<h2>Usages of <code>{{ $short }}</code></h2> |
| 10 | + |
| 11 | +{{ $patQuoted := print `(?s)\{\{\s*(?:<|%)\s*` $short `\b[^}]*?(?:"[^"]+"|'[^']+')[^}]*?(?:%|>)\}\}` }} |
| 12 | + |
| 13 | +{{/* Accumulate: key -> dict(path -> Page) */}} |
| 14 | +{{ $byKey := dict }} |
| 15 | + |
| 16 | +{{ range $pg := $site.RegularPages }} |
| 17 | + {{ $src := readFile $pg.File.Path }} |
| 18 | + {{ $matches := findRE $patQuoted $src }} |
| 19 | + {{ if gt (len $matches) 0 }} |
| 20 | + {{ range $m := $matches }} |
| 21 | + {{/* first quoted string inside the tag */}} |
| 22 | + {{ $qs := findRE `(?s)"[^"]+"|'[^']+'` $m }} |
| 23 | + {{ if gt (len $qs) 0 }} |
| 24 | + {{ $raw := index $qs 0 }} |
| 25 | + {{ $key := replaceRE `^['"]|['"]$` "" $raw }} |
| 26 | + {{ if ne $key "" }} |
| 27 | + {{ $per := default (dict) (index $byKey $key) }} |
| 28 | + {{ if not (isset $per $pg.File.Path) }} |
| 29 | + {{ $per = merge $per (dict $pg.File.Path $pg) }} |
| 30 | + {{ $byKey = merge $byKey (dict $key $per) }} |
| 31 | + {{ end }} |
| 32 | + {{ end }} |
| 33 | + {{ end }} |
| 34 | + {{ end }} |
| 35 | + {{ end }} |
| 36 | +{{ end }} |
| 37 | + |
| 38 | +{{ $scratch := newScratch }} |
| 39 | +{{ $scratch.Set "__groups" (slice) }} |
| 40 | +{{ range $k, $per := $byKey }} |
| 41 | + {{ $scratch.Add "__groups" (dict "k" $k "per" $per "count" (len $per)) }} |
| 42 | +{{ end }} |
| 43 | + |
| 44 | +{{ $groups := default (slice) ($scratch.Get "__groups") }} |
| 45 | +{{ $groupsSorted := sort $groups "count" "desc" }} |
| 46 | + |
| 47 | +{{ range $g := $groupsSorted }} |
| 48 | + {{ $k := index $g "k" }} |
| 49 | + {{ $per := index $g "per" }} |
| 50 | + {{ $count := index $g "count" }} |
| 51 | + |
| 52 | + <h3 id="include-{{ urlize $k }}"><code>{{ $k }}</code> — used on {{ $count }} {{ if eq $count 1 }}page{{ else }}pages{{ end }}</h3> |
| 53 | + <ul> |
| 54 | + {{ if gt $count 0 }} |
| 55 | + {{ range $path, $p := $per }} |
| 56 | + <li><a href="{{ $p.Permalink }}">{{ $p.Title }}</a> — <small>{{ $p.File.Path }}</small></li> |
| 57 | + {{ end }} |
| 58 | + {{ else }} |
| 59 | + <li><em>No pages found</em></li> |
| 60 | + {{ end }} |
| 61 | + </ul> |
| 62 | +{{ end }} |
0 commit comments