Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues on Medium links in Search #2469

Closed
2 tasks done
strivn opened this issue Jun 2, 2024 · 2 comments · Fixed by #2470
Closed
2 tasks done

Issues on Medium links in Search #2469

strivn opened this issue Jun 2, 2024 · 2 comments · Fixed by #2470
Labels

Comments

@strivn
Copy link

strivn commented Jun 2, 2024

Have you checked that your issue isn't already filed?

  • I read through FAQ and searched through the past issues, none of which addressed my issue.
  • Yes, I have checked that this issue isn't already filed.

Bug description

Medium links in Search redirects to asset file instead of Medium and may be duplicated

How to reproduce the bug

Steps to reproduce:

  1. Use the template and add Medium link through _config.yml
  2. Launch the site, and use the search function to search for the post

Expected output:

  1. Link in search will redirect to the actual medium post, e.g. medium.com/user/medium-title
  2. Each medium post will be shown exactly once (no duplicates)

Actual output:

  1. Link in search will redirect to the actual medium post, e.g. example.github.io/medium-year/medium-title
  2. A medium post may be shown twice (duplicated)

What operating system are you using?

Not applicable (e.g. you're using GitHub Pages or other hosting)

Where are you seeing the problem on?

Deployed site

More info

Related to the question #2464

Example output:
image

@strivn strivn added the bug label Jun 2, 2024
@strivn
Copy link
Author

strivn commented Jun 2, 2024

I'm unfamiliar with Jekyll, but from what I've tested out, it seems that the duplicate issue originates in search.liquid looping over both site.collections and site.posts.

{%- for post in site.posts -%}
{
{%- assign title = post.title | escape -%}
id: "post-{{ title | slugify }}",
title: "{{ title }}",
description: "{{ post.description | strip_html | strip_newlines | escape }}",
section: "Posts",
handler: () => {
window.location.href = "{{ post.url | relative_url }}";
},
},
{%- endfor -%}

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

The cause seems to be due posts are also considered as collections. I'm not sure how to see exactly what site contains, but I assumed so because looking at external_posts.rb, posts are added into collections.

def create_document(site, source_name, url, content)
slug = content[:title].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
path = site.in_source_dir("_posts/#{slug}.md")
doc = Jekyll::Document.new(
path, { :site => site, :collection => site.collections['posts'] }
)
doc.data['external_source'] = source_name
doc.data['title'] = content[:title]
doc.data['feed_content'] = content[:content]
doc.data['description'] = content[:summary]
doc.data['date'] = content[:published]
doc.data['redirect'] = url
site.collections['posts'].docs << doc
end

Additionally, the function create_document in external_posts.rb doesn't seem to define the url as the external url and instead stores it in redirect. Since in search.liquid the url is used instead of redirect, search doesn't work as expected.


Hope this helps. Let me know if there's anything I can assist to fix (not sure about how best to approach). Thanks!

george-gca added a commit that referenced this issue Jun 2, 2024
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 <george.gcac@gmail.com>
@strivn
Copy link
Author

strivn commented Jun 2, 2024

Thanks!

JyotsnaT pushed a commit to JyotsnaT/jyotsnat.github.io that referenced this issue Jun 6, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
siril-teja pushed a commit to siril-teja/siril-teja.github.io-old that referenced this issue Jun 19, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
karapostK pushed a commit to karapostK/karapostK.github.io that referenced this issue Jul 4, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
Suraj-Bhor pushed a commit to Suraj-Bhor/suraj-bhor.github.io that referenced this issue Aug 13, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
meiqing-wang pushed a commit to meiqing-wang/meiqing-wang.github.io that referenced this issue Oct 13, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
avishekanand pushed a commit to avishekanand/al-folio-homepage that referenced this issue Oct 22, 2024
Fixes alshedivat#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 <george.gcac@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant