porcellis.com

ref: master

layouts/_partials/dispatch-numbers.html


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{{- /*
  Returns a map of TranslationKey -> dispatch number.

  Numbers are derived from date order (oldest first) so no front matter is
  required, and translations of the same post share a number because pages are
  grouped by TranslationKey across every language.

  The result is language-independent, so callers should use partialCached with
  a constant key to compute it once per build:

      {{ $nums := partialCached "dispatch-numbers.html" . "dispatch-numbers" }}
      {{ $no := index $nums .TranslationKey }}
*/ -}}
{{- $pages := slice -}}
{{- range .Site.Home.AllTranslations -}}
  {{- range where .Site.RegularPages "Section" "blog" -}}
    {{- $pages = $pages | append . -}}
  {{- end -}}
{{- end -}}

{{- $byKey := dict -}}
{{- range $pages -}}
  {{- $byKey = merge $byKey (dict .TranslationKey .) -}}
{{- end -}}

{{- $unique := slice -}}
{{- range $key, $page := $byKey -}}
  {{- $unique = $unique | append $page -}}
{{- end -}}

{{- $nums := dict -}}
{{- range $i, $page := sort $unique "Date" -}}
  {{- $nums = merge $nums (dict $page.TranslationKey (add $i 1)) -}}
{{- end -}}

{{- return $nums -}}