-
Notifications
You must be signed in to change notification settings - Fork 187
/
search-index.json
56 lines (53 loc) · 2.28 KB
/
search-index.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
---
layout:
---
{% capture json %}
[
{% for post in site.posts %}
{
"title":"{{ post.title }}",
"href":"{{ post.url }}",
"author":"{{ post.author | join: ', ' }}",
"date":"{{ post.date | date_to_long_string }}",
"loopid":"post-{{ forloop.index }}",
"category":"{{ post.categories }}"
},
{% endfor %}
{% for page in site.pages %}{% unless page.redirect_to %}
{
"title":"{{ page.title }}",
"href":"{{ page.url }}",
"loopid":"page-{{ forloop.index }}",
"category":"{{ page.categories }}",
{% capture _ %} Capturing the generated content will prevent whitespace from being rendered
{% assign parent_dirs=page.url | replace_first: '/', '' | split: '/' %}
{% assign current_dir = site.data.breadcrumbs %}
{% assign breadcrumbs = '' %}
{% if parent_dirs.empty %}
Show just a slash to indicate the site root for empty breadcrumbs
{% assign breadcrumbs = '/' %}
{% else %}
{% for dir in parent_dirs %}
Unless overridden, the "pretty" name will be the URL/directory name
{% assign pretty_name = dir %}
{% unless forloop.last %} The last iteration is the current page, which we don't want in breadcrumbs
Traverse the tree of breadcrumb segment overrides
{% assign current_dir = current_dir[dir] %}
{% if current_dir.name %} Override the pretty name if one is present in the data file
{% assign pretty_name = current_dir.name %}
{% endif %}
Append the chosen name for this segment
{% assign breadcrumbs = breadcrumbs | append: pretty_name %}
{% unless forloop.rindex0 <= 1 %} Append a separator if this isn't the last segment
{% assign breadcrumbs = breadcrumbs | append: " > " %}
{% endunless %}
{% endunless %}
{% endfor %}
{% endif %}
{% endcapture %}
"breadcrumbs":"{{ breadcrumbs }}"
},
{% endunless %}{% endfor %}
false
]
{% endcapture %}{{ json | replace:" "," " | replace:" "," " | replace:" "," " | replace:" "," " }}