Skip to content

Commit a7b1f8c

Browse files
authored
Re-add ability to exclude posts from search (alshedivat#3089)
Earlier there was a tag in the `_config.yml` file to exclude the posts from the search results. I could no longer find that option and hence modified the `search.liquid.js` file. It basically checks if the `posts_in_search` tag is true or not.
1 parent 485e22f commit a7b1f8c

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ navbar_fixed: true
5252
footer_fixed: true
5353
search_enabled: true
5454
socials_in_search: true
55+
posts_in_search: true
5556
bib_search: true
5657

5758
# Dimensions

_scripts/search.liquid.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,32 @@ ninja.data = [
5252
{%- endif -%}
5353
{%- endif -%}
5454
{%- endfor -%}
55-
{%- for post in site.posts -%}
56-
{
57-
{%- assign title = post.title | escape | strip -%}
58-
id: "post-{{ title | slugify }}",
59-
{% if post.redirect == blank %}
60-
title: "{{ title | truncatewords: 13 }}",
61-
{% elsif post.redirect contains '://' %}
62-
title: '{{ title | truncatewords: 13 }} <svg width="1.2rem" height="1.2rem" top=".5rem" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg"><path d="M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9" class="icon_svg-stroke" stroke="#999" stroke-width="1.5" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg>',
63-
{% else %}
64-
title: "{{ title | truncatewords: 13 }}",
65-
{% endif %}
66-
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
67-
section: "Posts",
68-
handler: () => {
55+
{%- if site.posts_in_search -%}
56+
{%- for post in site.posts -%}
57+
{
58+
{%- assign title = post.title | escape | strip -%}
59+
id: "post-{{ title | slugify }}",
6960
{% if post.redirect == blank %}
70-
window.location.href = "{{ post.url | relative_url }}";
61+
title: "{{ title | truncatewords: 13 }}",
7162
{% elsif post.redirect contains '://' %}
72-
window.open("{{ post.redirect }}", "_blank");
63+
title: '{{ title | truncatewords: 13 }} <svg width="1.2rem" height="1.2rem" top=".5rem" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg"><path d="M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9" class="icon_svg-stroke" stroke="#999" stroke-width="1.5" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg>',
7364
{% else %}
74-
window.location.href = "{{ post.redirect | relative_url }}";
65+
title: "{{ title | truncatewords: 13 }}",
7566
{% endif %}
67+
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
68+
section: "Posts",
69+
handler: () => {
70+
{% if post.redirect == blank %}
71+
window.location.href = "{{ post.url | relative_url }}";
72+
{% elsif post.redirect contains '://' %}
73+
window.open("{{ post.redirect }}", "_blank");
74+
{% else %}
75+
window.location.href = "{{ post.redirect | relative_url }}";
76+
{% endif %}
77+
},
7678
},
77-
},
78-
{%- endfor -%}
79+
{%- endfor -%}
80+
{%- endif -%}
7981
{%- for collection in site.collections -%}
8082
{%- if collection.label != 'posts' -%}
8183
{%- for item in collection.docs -%}

0 commit comments

Comments
 (0)