Skip to content

Commit 87bff35

Browse files
committed
fixing bug with rendering posts in search
Signed-off-by: Vanessa Sochat <[email protected]>
1 parent 30fbbba commit 87bff35

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Critical items to know are:
1414
- changed behaviour
1515

1616
## [master](https://github.com/vsoch/docsy-jekyll/tree/master)
17+
- bug that news items (posts) don't render in search (0.0.14)
1718
- minimum width of 150px for top right site name (0.0.13)
1819
- tags page and option to link to it from post/docs tags (0.0.12)
1920
- adding search endpoint tags to docs (0.0.11)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.13
1+
0.0.14

_posts/2019-06-29-welcome.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: "Welcome to MkDocs Jekyll"
3-
date: 2019-06-28 5:52:21 -0500
2+
title: "Welcome to MkDocs Jekyll"
3+
date: 2019-06-28 5:52:21 -0500
44
categories: jekyll update
55
badges:
66
- type: primary

assets/css/palette.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
layout: null
3+
excluded_in_search: true
4+
---
5+
16
.highlight pre {
27
border: none !important;
38
}

assets/js/search.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ excluded_in_search: true
6666
if (results.length) {
6767
var resultsHTML = "";
6868
results.forEach(function (result) {
69-
var item = window.data[result.ref],
69+
70+
var item = window.data[result.ref]
71+
if (item.title) {
7072
contentPreview = getPreview(query, item.content, 170),
7173
titlePreview = getPreview(query, item.title);
72-
73-
resultsHTML += "<li><h4><a href='{{ site.baseurl }}" + item.url.trim() + "'>" + titlePreview + "</a></h4><p><small>" + contentPreview + "</small></p></li>";
74+
resultsHTML += "<li><h4><a href='{{ site.baseurl }}" + item.url.trim() + "'>" + titlePreview + "</a></h4><p><small>" + contentPreview + "</small></p></li>";
75+
}
7476
});
7577

7678
searchResultsEl.innerHTML = resultsHTML;

pages/search.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@
2929
{% assign added = true %}
3030
{% endunless %}
3131
{% endfor %}
32+
{% for post in site.posts %}
33+
{% unless post.excluded_in_search %}
34+
{% if added %},{% endif %}
35+
{% assign added = false %}
36+
"{{ post.url | slugify }}": {
37+
"id": "{{ post.url | slugify }}",
38+
"title": "{{ post.title | xml_escape }}",
39+
"categories": "{{ post.categories | join: ", " | xml_escape }}",
40+
"url": " {{ post.url | xml_escape }}",
41+
"content": {{ post.content | strip_html | replace_regex: "[\s/\n]+"," " | strip | jsonify }}
42+
}
43+
{% assign added = true %}
44+
{% endunless %}
45+
{% endfor %}
3246
{% for post in site.pages %}
3347
{% unless post.excluded_in_search %}
3448
{% if added %},{% endif %}

0 commit comments

Comments
 (0)