Skip to content

Commit 6779656

Browse files
authored
Merge pull request #73 from layer5io/exam
enhance and enrich json index
2 parents 459c631 + 0c8f073 commit 6779656

File tree

8 files changed

+87
-68
lines changed

8 files changed

+87
-68
lines changed

layouts/list.json.json

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,75 +2,9 @@
22
{
33
"total": {{ len .Pages }},
44
"data": [
5-
{{- $pages := .Pages -}}
6-
{{- range $i, $p := $pages }}
5+
{{- range $i, $p := .Pages }}
76
{{- if $i }},{{ end }}
8-
9-
{{- $ctx := partial "resolve-tenant.html" $p -}}
10-
{{- $uuid := $ctx.uuid -}}
11-
12-
{{- $children := $p.Pages }}
13-
14-
{{- /* Prepend the orgId to the parent Learning Path's banner path. */ -}}
15-
{{- $banner_url := "" -}}
16-
{{- if $p.Params.Banner -}}
17-
{{- $banner_url = printf "%s/%s" $uuid $p.Params.Banner | absURL -}}
18-
{{- end -}}
19-
20-
21-
{{ $level := $p.Params.level }}
22-
{{ if $level }}
23-
{{- /* Validate the level parameter */ -}}
24-
{{- if not (in (slice "beginner" "intermediate" "advanced") $level) }}
25-
{{ warnf "Invalid value for 'level': %s. Expected one of 'beginner', 'intermediate', or 'advanced' in %s " $level $p.File.Path }}
26-
{{ $level = "beginner" }}
27-
{{ end }}
28-
{{- end }}
29-
30-
31-
{
32-
33-
"id": {{ partial "id.html" $p }},
34-
"level": {{ or $level "beginner" | jsonify }},
35-
"slug": {{ or $p.Slug $p.File.ContentBaseName | jsonify }},
36-
"org_id": {{ $uuid | jsonify }},
37-
"type": {{ $p.Params.Type | jsonify }} ,
38-
"visibility": {{ or $p.Params.Visibility "public" | jsonify }},
39-
"status": {{ or $p.Params.Status "ready" | jsonify }},
40-
41-
{{- /* Metadata for the Learning Path */ -}}
42-
43-
"metadata": {
44-
"title": {{ $p.Title | jsonify }},
45-
"description": {{ $p.Description | jsonify }},
46-
"banner": {{ $banner_url | jsonify }},
47-
"permalink": {{ $p.Permalink | jsonify }},
48-
"categories": {{ $p.Params.Categories | jsonify }},
49-
"tags": {{ $p.Params.Tags | jsonify }},
50-
"courses": [
51-
{{- range $j, $c := $children }}
52-
{{- if $j }},{{ end }}
53-
54-
{{- /* Prepend the orgId to the nested Course's banner path. */ -}}
55-
{{- $course_banner_url := "" -}}
56-
{{- if $c.Params.Banner -}}
57-
{{- $course_banner_url = printf "%s/%s" $uuid $c.Params.Banner | absURL -}}
58-
{{- end -}}
59-
60-
{
61-
"title": {{ $c.Title | jsonify }},
62-
"slug": {{ or $c.Slug $c.File.ContentBaseName | jsonify }},
63-
"id": {{ partial "id.html" $c }},
64-
"level": {{ $c.Params.level | jsonify }},
65-
"description": {{ $c.Description | jsonify }},
66-
"weight": {{ $c.Params.Order | jsonify}},
67-
"banner": {{ $course_banner_url | jsonify }},
68-
"permalink": {{ $c.Permalink | jsonify }}
69-
}
70-
{{- end }}
71-
]
72-
}
73-
}
7+
{{ partial "learning-path.json.html" $p }}
748
{{- end }}
759
]
7610
}

layouts/partials/banner-url.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- $uuid := .uuid -}}
2+
{{- $banner := .banner -}}
3+
{{- if $banner -}}
4+
{{ printf "%s/%s" $uuid $banner | absURL }}
5+
{{- else -}}
6+
""
7+
{{- end -}}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
{{- $page := .page -}}
3+
{{- $uuid := .uuid -}}
4+
{{- $type := or $page.Params.Type "default" -}}
5+
{{- $banner_url := partial "banner-url.html" (dict "uuid" $uuid "banner" $page.Params.Banner) -}}
6+
7+
"title": {{ $page.Title | jsonify }},
8+
"slug": {{ or $page.Slug $page.File.ContentBaseName | jsonify }},
9+
"id": {{ partial "id.html" $page }},
10+
"level": {{ $page.Params.level | jsonify }},
11+
"description": {{ $page.Description | jsonify }},
12+
"weight": {{ $page.Params.Order | jsonify }},
13+
"banner": {{ $banner_url | jsonify }},
14+
"permalink": {{ $page.Permalink | jsonify }},
15+
"type": {{ $type | jsonify }}

layouts/partials/course.json.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
{{ partial "common-curricula-properties.html" . }},
4+
"modules": [
5+
{{- range $k, $m := .page.Pages }}
6+
{{- if $k }},{{ end }}
7+
{{ partial "module.json.html" (dict "page" $m "uuid" $.uuid) }}
8+
{{- end }}
9+
]
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{- /* learning-path.json.html */ -}}
3+
{{- $ctx := partial "resolve-tenant.html" . -}}
4+
{{- $uuid := $ctx.uuid -}}
5+
{{- $level := partial "validate-level.html" . -}}
6+
{{- $banner_url := partial "banner-url.html" (dict "uuid" $uuid "banner" .Params.Banner) -}}
7+
8+
{
9+
"id": {{ partial "id.html" . }},
10+
"level": {{ (trim $level " \n\r\t") | jsonify }},
11+
"slug": {{ or .Slug .File.ContentBaseName | jsonify }},
12+
"org_id": {{ $uuid | jsonify }},
13+
"type": {{ .Params.Type | jsonify }},
14+
"visibility": {{ or .Params.Visibility "public" | jsonify }},
15+
"status": {{ or .Params.Status "ready" | jsonify }},
16+
"metadata": {
17+
"title": {{ .Title | jsonify }},
18+
"description": {{ .Description | jsonify }},
19+
"banner": {{ $banner_url | jsonify }},
20+
"permalink": {{ .Permalink | jsonify }},
21+
"categories": {{ .Params.Categories | jsonify }},
22+
"tags": {{ .Params.Tags | jsonify }},
23+
"total_courses": {{ len (where .Pages "Type" "course") }},
24+
25+
"courses": [
26+
{{- range $j, $c := .Pages }}
27+
{{- if $j }},{{ end }}
28+
{{ partial "course.json.html" (dict "page" $c "uuid" $uuid) }}
29+
{{- end }}
30+
]
31+
}
32+
}

layouts/partials/module.json.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{
3+
{{ partial "common-curricula-properties.html" . }},
4+
"pages": [
5+
{{- range $l, $p := .page.Pages }}
6+
{{- if $l }},{{ end }}
7+
{{ partial "page.json.html" (dict "page" $p "uuid" $.uuid) }}
8+
{{- end }}
9+
]
10+
}

layouts/partials/page.json.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
{
3+
{{ partial "common-curricula-properties.html" . }}
4+
}

layouts/partials/validate-level.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{- $level := .Params.level -}}
2+
{{- if in (slice "beginner" "intermediate" "advanced") $level -}}
3+
{{ $level }}
4+
{{- else -}}
5+
{{ warnf "Invalid level: %s in %s. Defaulting to beginner." $level .File.Path }}
6+
beginner
7+
{{- end -}}

0 commit comments

Comments
 (0)