/
api-topics.html
53 lines (52 loc) · 2.16 KB
/
api-topics.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{{- partial "core/set-env.html" . -}}
{{- $list := (where .Site.Pages "Section" "topics") -}}
{{- $length := len $list -}}
{
"version" : "https://jsonfeed.org/version/1",
"content" : "topics",
"type" : "list",
"title" : "Topics | {{- .Site.Title -}}",
"home_page_url" : "{{- .Site.BaseURL -}}",
"count" : "{{- $length -}}",
"items" : [
{{- range $topic := $list.ByTitle -}}
{{- with $topic -}}
{
"slug" : "{{- with .File -}}{{- .Path | replaceRE "^topics/([^/]+).*" "$1" -}}{{- end -}}",
"title" : "{{- .Title -}}",
"summary" : "{{- .Params.summary -}}",
{{- if .Params.aliases -}}
"aliases" : {
{{- $aliaslen := .Params.aliases | len -}}
{{- $.Scratch.Set "aliascount" 1 -}}
{{- range $i, $e := .Params.aliases -}}
{{- with $e -}}
{{- $aliascount := $.Scratch.Get "aliascount" -}}
{{- if eq $aliascount $aliaslen -}}
"{{- $i -}}" : "{{- $e -}}"
{{- else -}}
"{{- $i -}}" : "{{- $e -}}",
{{- end -}}
{{- $.Scratch.Add "aliascount" 1 -}}
{{- end -}}
{{- end -}}
},
{{- end -}}
{{- if .Params.weight -}}
"weight" : "{{- .Params.weight -}}",
{{- end -}}
"branch" : {{- $.Scratch.Get "branch" | jsonify -}},
"filename" : {{- with .File -}}{{- .LogicalName | jsonify -}}{{- end -}},
"filepath" : {{- with .File -}}{{- .Path | jsonify -}}{{- end -}},
"filepathURL" : {{- with .File -}}{{- printf "https://github.com/%s/%s/blob/%s/content/%s" $.Site.Params.git_org $.Site.Params.git_repo ($.Scratch.Get "branch") .Path | jsonify -}}{{- end -}},
"editpathURL" : {{- with .File -}}{{- printf "https://github.com/%s/%s/edit/%s/content/%s" $.Site.Params.git_org $.Site.Params.git_repo ($.Scratch.Get "branch") .Path | jsonify -}}{{- end -}},
"length" : {{- $length -}},
"iterator" : "{{- $.Scratch.Get "i" -}}"
}
{{- $.Scratch.Add "i" 1 -}}
{{- $iterator := $.Scratch.Get "i" -}}
{{- if not (eq $length $iterator) -}}, {{- end -}}
{{- end -}}
{{- end -}}
]
}