From b4f90ff416b5961136cb9ed59e4edbcdf02109c1 Mon Sep 17 00:00:00 2001 From: George <31376482+george-gca@users.noreply.github.com> Date: Sun, 2 Jun 2024 13:48:09 -0300 Subject: [PATCH] Fixes external blog posts in search (#2470) Fixes #2469. Separated `news` and `posts` from other collections in search, since it caused duplicated entries. Also to ensure they are in chronological reverse order. Signed-off-by: George Araujo --- _includes/scripts/search.liquid | 75 ++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 20 deletions(-) diff --git a/_includes/scripts/search.liquid b/_includes/scripts/search.liquid index ffd0a79a83c6..7fb303978b11 100644 --- a/_includes/scripts/search.liquid +++ b/_includes/scripts/search.liquid @@ -76,33 +76,68 @@ { {%- assign title = post.title | escape -%} id: "post-{{ title | slugify }}", - title: "{{ title }}", + {% if post.redirect == blank %} + title: "{{ title }}", + {% elsif post.redirect contains '://' %} + // TODO: fix the svg icon position for external posts + // title: '{{ title }} ', + title: "{{ title }}", + {% else %} + title: "{{ title }}", + {% endif %} description: "{{ post.description | strip_html | strip_newlines | escape }}", section: "Posts", handler: () => { - window.location.href = "{{ post.url | relative_url }}"; + {% 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 -%} + {%- assign news = site.news | reverse -%} + {%- for item in news -%} + { + {%- if item.inline -%} + {%- assign title = item.content | remove: '

' | remove: '

' | 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 -%} - {%- for item in collection.docs -%} - { - {%- if item.inline -%} - {%- assign title = item.content | remove: '

' | remove: '

' | escape | strip -%} - {%- else -%} - {%- assign title = item.title | escape -%} - {%- endif -%} - id: "{{ collection.label }}-{{ title | slugify }}", - title: '{{ title | emojify }}', - description: "{{ item.description | strip_html | strip_newlines | escape }}", - section: "{{ collection.label | capitalize }}", - {%- unless item.inline -%} - handler: () => { - window.location.href = "{{ item.url | relative_url }}"; - }, - {%- endunless -%} - }, - {%- endfor -%} + {%- if collection.label != 'news' and collection.label != 'posts' -%} + {%- for item in collection.docs -%} + { + {%- if item.inline -%} + {%- assign title = item.content | remove: '

' | remove: '

' | escape | strip -%} + {%- else -%} + {%- assign title = item.title | escape -%} + {%- endif -%} + id: "{{ collection.label }}-{{ title | slugify }}", + title: '{{ title | emojify }}', + description: "{{ item.description | strip_html | strip_newlines | escape }}", + section: "{{ collection.label | capitalize }}", + {%- unless item.inline -%} + handler: () => { + window.location.href = "{{ item.url | relative_url }}"; + }, + {%- endunless -%} + }, + {%- endfor -%} + {%- endif -%} {%- endfor -%} {%- if site.socials_in_search -%} {%- if site.email -%}