Re-add ability to exclude posts from search (#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.
This commit is contained in:
Pranjal Aggarwal 2025-03-22 19:11:34 -06:00 committed by GitHub
parent 485e22fdf0
commit a7b1f8c1b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 19 deletions

View File

@ -52,6 +52,7 @@ navbar_fixed: true
footer_fixed: true footer_fixed: true
search_enabled: true search_enabled: true
socials_in_search: true socials_in_search: true
posts_in_search: true
bib_search: true bib_search: true
# Dimensions # Dimensions

View File

@ -52,30 +52,32 @@ ninja.data = [
{%- endif -%} {%- endif -%}
{%- endif -%} {%- endif -%}
{%- endfor -%} {%- endfor -%}
{%- for post in site.posts -%} {%- if site.posts_in_search -%}
{ {%- for post in site.posts -%}
{%- assign title = post.title | escape | strip -%} {
id: "post-{{ title | slugify }}", {%- assign title = post.title | escape | strip -%}
{% if post.redirect == blank %} id: "post-{{ title | slugify }}",
title: "{{ title | truncatewords: 13 }}",
{% elsif post.redirect contains '://' %}
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>',
{% else %}
title: "{{ title | truncatewords: 13 }}",
{% endif %}
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
section: "Posts",
handler: () => {
{% if post.redirect == blank %} {% if post.redirect == blank %}
window.location.href = "{{ post.url | relative_url }}"; title: "{{ title | truncatewords: 13 }}",
{% elsif post.redirect contains '://' %} {% elsif post.redirect contains '://' %}
window.open("{{ post.redirect }}", "_blank"); 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>',
{% else %} {% else %}
window.location.href = "{{ post.redirect | relative_url }}"; title: "{{ title | truncatewords: 13 }}",
{% endif %} {% endif %}
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
section: "Posts",
handler: () => {
{% if post.redirect == blank %}
window.location.href = "{{ post.url | relative_url }}";
{% elsif post.redirect contains '://' %}
window.open("{{ post.redirect }}", "_blank");
{% else %}
window.location.href = "{{ post.redirect | relative_url }}";
{% endif %}
},
}, },
}, {%- endfor -%}
{%- endfor -%} {%- endif -%}
{%- for collection in site.collections -%} {%- for collection in site.collections -%}
{%- if collection.label != 'posts' -%} {%- if collection.label != 'posts' -%}
{%- for item in collection.docs -%} {%- for item in collection.docs -%}