Skip to content

Commit

Permalink
Fixed title search and truncating if larger than 13 words (#2561)
Browse files Browse the repository at this point in the history
Fixes #2459

Signed-off-by: George Araujo <george.gcac@gmail.com>
  • Loading branch information
george-gca authored Jul 10, 2024
1 parent cb0375c commit e7d5c2f
Showing 1 changed file with 18 additions and 37 deletions.
55 changes: 18 additions & 37 deletions _includes/scripts/search.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
// add the home and posts menu items
ninja.data = [
{%- for page in site.pages -%}
{%- if page.permalink == '/' -%}{%- assign about_title = page.title -%}{%- endif -%}
{%- if page.permalink == '/' -%}{%- assign about_title = page.title | strip -%}{%- endif -%}
{%- endfor -%}
{
id: "nav-{{ about_title | slugify }}",
title: "{{ about_title }}",
title: "{{ about_title | truncatewords: 13 }}",
section: "Navigation",
handler: () => {
window.location.href = "{{ '/' | relative_url }}";
Expand All @@ -44,11 +44,11 @@
{%- for child in p.children -%}
{%- unless child.title == 'divider' -%}
{
{%- assign title = child.title | escape -%}
{%- assign title = child.title | escape | strip -%}
{%- if child.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = child.url -%}{%- endif -%}
id: "dropdown-{{ title | slugify }}",
title: "{{ title }}",
description: "{{ child.description | strip_html | strip_newlines | escape }}",
title: "{{ title | truncatewords: 13 }}",
description: "{{ child.description | strip_html | strip_newlines | escape | strip }}",
section: "Dropdown",
handler: () => {
window.location.href = "{{ url | relative_url }}";
Expand All @@ -59,11 +59,11 @@
{%- else -%}
{
{%- assign title = p.title | escape -%}
{%- assign title = p.title | escape | strip -%}
{%- if p.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = p.url -%}{%- endif -%}
id: "nav-{{ title | slugify }}",
title: "{{ title }}",
description: "{{ p.description | strip_html | strip_newlines | escape }}",
title: "{{ title | truncatewords: 13 }}",
description: "{{ p.description | strip_html | strip_newlines | escape | strip }}",
section: "Navigation",
handler: () => {
window.location.href = "{{ url | relative_url }}";
Expand All @@ -74,17 +74,17 @@
{%- endfor -%}
{%- for post in site.posts -%}
{
{%- assign title = post.title | escape -%}
{%- assign title = post.title | escape | strip -%}
id: "post-{{ title | slugify }}",
{% if post.redirect == blank %}
title: "{{ title }}",
title: "{{ title | truncatewords: 13 }}",
{% elsif post.redirect contains '://' %}
// TODO: fix the svg icon position for external posts
title: '{{ title }} <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>',
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 }}",
title: "{{ title | truncatewords: 13 }}",
{% endif %}
description: "{{ post.description | strip_html | strip_newlines | escape }}",
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
section: "Posts",
handler: () => {
{% if post.redirect == blank %}
Expand All @@ -97,37 +97,18 @@
},
},
{%- endfor -%}
{%- assign news = site.news | reverse -%}
{%- for item in news -%}
{
{%- if item.inline -%}
{%- assign title = item.content | remove: '<p>' | remove: '</p>' | escape | strip -%}
{%- else -%}
{%- assign title = item.title | escape -%}
{%- endif -%}
id: "news-{{ title | slugify }}",
title: '{{ title | emojify }}',
description: "{{ item.description | strip_html | strip_newlines | escape }}",
section: "News",
{%- unless item.inline -%}
handler: () => {
window.location.href = "{{ item.url | relative_url }}";
},
{%- endunless -%}
},
{%- endfor -%}
{%- for collection in site.collections -%}
{%- if collection.label != 'news' and collection.label != 'posts' -%}
{%- if collection.label != 'posts' -%}
{%- for item in collection.docs -%}
{
{%- if item.inline -%}
{%- assign title = item.content | remove: '<p>' | remove: '</p>' | escape | strip -%}
{%- assign title = item.content | strip_html | strip_newlines | escape | strip -%}
{%- else -%}
{%- assign title = item.title | escape -%}
{%- assign title = item.title | strip_html | strip_newlines | escape | strip -%}
{%- endif -%}
id: "{{ collection.label }}-{{ title | slugify }}",
title: '{{ title | emojify }}',
description: "{{ item.description | strip_html | strip_newlines | escape }}",
title: '{{ title | emojify | truncatewords: 13 }}',
description: "{{ item.description | strip_html | strip_newlines | escape | strip }}",
section: "{{ collection.label | capitalize }}",
{%- unless item.inline -%}
handler: () => {
Expand Down

0 comments on commit e7d5c2f

Please sign in to comment.