-
Notifications
You must be signed in to change notification settings - Fork 70
/
search.json
132 lines (113 loc) · 4.89 KB
/
search.json
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
---
---
{%- comment -%}
Output from this page is a JSON structure that is used by the search function,
which is implemented using:
https://blog.webjeda.com/instant-jekyll-search/
The output from this page needs to be valid JSON in a structure like:
[
{
"title": "Some title",
"url": "URL to page",
"step": "The step(s) in the lifecycle the doc applies to",
"categories": "Best Practices or Lesson"
},
{
...
}
]
Take care of quoting and commas especially. There's no comma after the
last item in a list
The search results appear to be ordered by how they appear in this JSON
document, so the lessons are placed first as there's a lot fewer of them. If
they are second then they tend to get hidden a bit.
{%- endcomment -%}
[
{%- comment %}+++ Start of the Lesson list generation +++
The following is specific to the lessons. Given the number of lessons,
first find the documents that are in that lesson number, then select the
index document and slides document from those documents.
To get the steps, look at each tag and compare it with a life cycle step,
if it matches, then add it to a list of steps. Finally write out the steps.
The list of lifecycle steps is defined in _config.yml and is available as
site.life_cycle_steps
It's all a bit cumbersome, but seems to work pretty well.
{%- endcomment -%}
{%- assign num_lessons=10 %}
{% for lesson_id in (1..num_lessons) %}
{
{%- assign lesson_tag = lesson_id | prepend: '00' | slice: -2, 2 %}
{%- assign lesson_tag = '/lessons/' | append: lesson_tag | append: '_' -%}
{%- comment -%}
Select the docs that are part of a specific lesson then
select the index document and the slides document from that
set of documents
{%- endcomment -%}
{%- assign lesson_docs = site.lessons | where_exp:"item","item.id contains lesson_tag" %}
{%- assign lesson_slides = lesson_docs | where_exp: "item", "item.id contains '/slides'" %}
{%- assign lesson_slides = lesson_slides.first %}
{%- assign lesson_index = lesson_docs | where_exp: "item", "item.id contains '/index'" %}
{%- assign lesson_index = lesson_index.first %}
{%- assign lesson_url = site.baseurl | append: lesson_index.url %}
{%- assign lesson_steps = '' %}
{%- for tag in lesson_index.tags %}
{% assign ltag = tag | downcase %}
{%- for step in site.life_cycle_steps %}
{%- if ltag == step %}
{%- assign lesson_steps = lesson_steps | append: step | append: ',' %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{%- assign lesson_steps = lesson_steps | split: ',' | compact %}
"title": {{ lesson_slides.title | jsonify }},
"url": {{ lesson_url | jsonify }},
"tags": {{ lesson_index.tags | join: ', ' | jsonify }},
"categories": {{ lesson_index.categories | join: ', ' | jsonify }},
"step": {{ lesson_steps | join: ', ' | jsonify }},
"organization" : {{ lesson_index.organization | jsonify }}
},
{%- endfor %}
{%- comment %} --- End of Lesson list generation --- {%- endcomment %}
{%- comment %} +++ Start of Best Practice list generation +++ {%- endcomment %}
{%- assign the_collection = "bestpractices" %}
{%- for item in site[ the_collection ] %}
{%- if item.step != "NA" %}
{%- if item.step != nil %}
{%- if item.title != "How to write a Best Practice file" %}
{%- assign item_category = item.categories | join: ',' %}
{%- if item_category == '' or item_category == nil %}
{%- assign item_category = 'Best Practice' %}
{%- endif %}
{
"title" : {{ item.title | jsonify }},
"url" : "{{ site.baseurl }}{{ item.url }}",
"step" : {{ item.step | join: ', ' | jsonify }},
"tags" : {{ item.tags | join: ', ' | jsonify }},
"categories" : {{ item_category | jsonify }},
"organization" : {{ item.organization | jsonify }}
},
{%- endif %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- comment %} --- End of Best Practice list generation --- {%- endcomment %}
{%- comment %} +++ Start of Video list generation +++ {%- endcomment %}
{%- assign the_collection = "videos" %}
{%- for item in site[ the_collection ] %}
{%- if item.step != "NA" %}
{%- if item.step != nil %}
{%- assign item_category = item.categories | join: ',' %}
{
"title" : {{ item.title | jsonify }},
"url" : "{{ site.baseurl }}{{ item.url }}",
"step" : {{ item.step | join: ', ' | jsonify }},
"tags" : {{ item.tags | join: ', ' | jsonify }},
"categories" : {{ item_category | jsonify }},
"organization" : {{ item.organization | jsonify }}
},
{%- endif %}
{%- endif %}
{%- endfor %}
{%- comment %} --- End of Video list generation --- {%- endcomment %}
{} {%- comment %} Dummy entry, does nothing except ensure no comma at the end {%- endcomment %}
]