Skip to content

Commit e7d5c2f

Browse files
authored
Fixed title search and truncating if larger than 13 words (#2561)
Fixes #2459 Signed-off-by: George Araujo <[email protected]>
1 parent cb0375c commit e7d5c2f

File tree

1 file changed

+18
-37
lines changed

1 file changed

+18
-37
lines changed

_includes/scripts/search.liquid

+18-37
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
// add the home and posts menu items
2828
ninja.data = [
2929
{%- for page in site.pages -%}
30-
{%- if page.permalink == '/' -%}{%- assign about_title = page.title -%}{%- endif -%}
30+
{%- if page.permalink == '/' -%}{%- assign about_title = page.title | strip -%}{%- endif -%}
3131
{%- endfor -%}
3232
{
3333
id: "nav-{{ about_title | slugify }}",
34-
title: "{{ about_title }}",
34+
title: "{{ about_title | truncatewords: 13 }}",
3535
section: "Navigation",
3636
handler: () => {
3737
window.location.href = "{{ '/' | relative_url }}";
@@ -44,11 +44,11 @@
4444
{%- for child in p.children -%}
4545
{%- unless child.title == 'divider' -%}
4646
{
47-
{%- assign title = child.title | escape -%}
47+
{%- assign title = child.title | escape | strip -%}
4848
{%- if child.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = child.url -%}{%- endif -%}
4949
id: "dropdown-{{ title | slugify }}",
50-
title: "{{ title }}",
51-
description: "{{ child.description | strip_html | strip_newlines | escape }}",
50+
title: "{{ title | truncatewords: 13 }}",
51+
description: "{{ child.description | strip_html | strip_newlines | escape | strip }}",
5252
section: "Dropdown",
5353
handler: () => {
5454
window.location.href = "{{ url | relative_url }}";
@@ -59,11 +59,11 @@
5959
6060
{%- else -%}
6161
{
62-
{%- assign title = p.title | escape -%}
62+
{%- assign title = p.title | escape | strip -%}
6363
{%- if p.permalink contains "/blog/" -%}{%- assign url = "/blog/" -%} {%- else -%}{%- assign url = p.url -%}{%- endif -%}
6464
id: "nav-{{ title | slugify }}",
65-
title: "{{ title }}",
66-
description: "{{ p.description | strip_html | strip_newlines | escape }}",
65+
title: "{{ title | truncatewords: 13 }}",
66+
description: "{{ p.description | strip_html | strip_newlines | escape | strip }}",
6767
section: "Navigation",
6868
handler: () => {
6969
window.location.href = "{{ url | relative_url }}";
@@ -74,17 +74,17 @@
7474
{%- endfor -%}
7575
{%- for post in site.posts -%}
7676
{
77-
{%- assign title = post.title | escape -%}
77+
{%- assign title = post.title | escape | strip -%}
7878
id: "post-{{ title | slugify }}",
7979
{% if post.redirect == blank %}
80-
title: "{{ title }}",
80+
title: "{{ title | truncatewords: 13 }}",
8181
{% elsif post.redirect contains '://' %}
8282
// TODO: fix the svg icon position for external posts
83-
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>',
83+
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>',
8484
{% else %}
85-
title: "{{ title }}",
85+
title: "{{ title | truncatewords: 13 }}",
8686
{% endif %}
87-
description: "{{ post.description | strip_html | strip_newlines | escape }}",
87+
description: "{{ post.description | strip_html | strip_newlines | escape | strip }}",
8888
section: "Posts",
8989
handler: () => {
9090
{% if post.redirect == blank %}
@@ -97,37 +97,18 @@
9797
},
9898
},
9999
{%- endfor -%}
100-
{%- assign news = site.news | reverse -%}
101-
{%- for item in news -%}
102-
{
103-
{%- if item.inline -%}
104-
{%- assign title = item.content | remove: '<p>' | remove: '</p>' | escape | strip -%}
105-
{%- else -%}
106-
{%- assign title = item.title | escape -%}
107-
{%- endif -%}
108-
id: "news-{{ title | slugify }}",
109-
title: '{{ title | emojify }}',
110-
description: "{{ item.description | strip_html | strip_newlines | escape }}",
111-
section: "News",
112-
{%- unless item.inline -%}
113-
handler: () => {
114-
window.location.href = "{{ item.url | relative_url }}";
115-
},
116-
{%- endunless -%}
117-
},
118-
{%- endfor -%}
119100
{%- for collection in site.collections -%}
120-
{%- if collection.label != 'news' and collection.label != 'posts' -%}
101+
{%- if collection.label != 'posts' -%}
121102
{%- for item in collection.docs -%}
122103
{
123104
{%- if item.inline -%}
124-
{%- assign title = item.content | remove: '<p>' | remove: '</p>' | escape | strip -%}
105+
{%- assign title = item.content | strip_html | strip_newlines | escape | strip -%}
125106
{%- else -%}
126-
{%- assign title = item.title | escape -%}
107+
{%- assign title = item.title | strip_html | strip_newlines | escape | strip -%}
127108
{%- endif -%}
128109
id: "{{ collection.label }}-{{ title | slugify }}",
129-
title: '{{ title | emojify }}',
130-
description: "{{ item.description | strip_html | strip_newlines | escape }}",
110+
title: '{{ title | emojify | truncatewords: 13 }}',
111+
description: "{{ item.description | strip_html | strip_newlines | escape | strip }}",
131112
section: "{{ collection.label | capitalize }}",
132113
{%- unless item.inline -%}
133114
handler: () => {

0 commit comments

Comments
 (0)