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

Search broken due to newline in news #2459

Closed
2 tasks done
CheariX opened this issue May 28, 2024 · 9 comments · Fixed by #2561
Closed
2 tasks done

Search broken due to newline in news #2459

CheariX opened this issue May 28, 2024 · 9 comments · Fixed by #2561
Assignees
Labels

Comments

@CheariX
Copy link
Contributor

CheariX commented May 28, 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

See my details in #2450

How to reproduce the bug

Add markdown link to an inline news article

Edit: Initially, I thought this issue is caused to due markdown. But I was wrong, it occurs if the content has more than one line.

Error messages and logs

No response

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?

Running locally with Docker

More info

I think my report in a closed PR was overlooked. Therefore I created this issue.

@CheariX CheariX added the bug label May 28, 2024
@george-gca
Copy link
Collaborator

I believe I fixed this in #2450. Also there isn't a comment from you there.

@CheariX
Copy link
Contributor Author

CheariX commented May 28, 2024

The following changes introduced in #2450 breaks search on my setup. ctrl-k is completly empty:

{%- if item.inline -%}
{%- assign title = item.content | remove: '<p>' | remove: '</p>' | escape | strip -%}
{%- else -%}
{%- assign title = item.title | escape -%}
{%- endif -%}

I used a markdown link like Link to [site](https://example.com) in my inline news, which causes this issue.
Instead, if a use HTML like Link to <a href="https://example.com">site</a> the search is working, but the HTML is escaped, which uglifies the search entry.

My suggestion would be to simple stay with the previous code. People can manually add site.title if they want to have a nicer looking title.

Another (untested) solution could be to remove all HTML, using strip_html. However I still think using site.title would be better since we don't know the length of the inline news. I could possible contain multiple paragraphs.

@george-gca
Copy link
Collaborator

I don't know if I get this. I tried the following changes:

image

And had this as a result:

image

Both in the search and in the page the text is fine. Are you sure you have the latest updates?

@CheariX
Copy link
Contributor Author

CheariX commented Jun 1, 2024

Okay, this error was a bit hard to reproduce. It was not the HTML Link, but a newline in my news.
I had an inline news using two lines.

The Browser's Error console quickly displayed the error.

Uncaught SyntaxError: '' string literal contains an unescaped line break localhost:8080:1171:238

When I removed the second line of my news, search worked again.

Additionally, I'm not very happy with the currenty mardown representation. For example, this news entry:

---
layout: post
date: 2024-06-01 10:00:00-0400
inline: true
related_posts: false
---

This news contains a [Link](https://example.com)

Produces:

grafik

Update: On upstream/master, I get a rendered Link. I don't know why, but anyways, i think it should not be rendered. The link is not intended to be clicked, and it is also hard to read.
grafik

I suggest to use strip_html | strip_newlines | escape for all three cases here (not only for the description).

{%- 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 }}",

Also, I do not like the dependence on the inline attribute since this attribute is specific to the news collection, so I'd remove the inline-check from this code.
My suggestion would be to check if page.title exists and, in that case, prefer to use page.title. Otherwise, use {%- assign title = item.content | strip_html | strip_newlines | escape -%}. Since page.title is used at multiple places, this approach seems more general to me.

What do you think?

@george-gca
Copy link
Collaborator

george-gca commented Jun 1, 2024

Update: On upstream/master, I get a rendered Link. I don't know why, but anyways, i think it should not be rendered. The link is not intended to be clicked, and it is also hard to read.

I agree that it is hard to read, but I am not sure if it should not be clicked. Think about this use case, what should happen if the user search for the news, and it is inline with a link? Should it only be read, or should be possible to click in it? But I don't think we should take the link and expand to the whole line either, because maybe the news has more than one link in it. I'd like to have more opinions on that matter. What do you think @pourmand1376, @alshedivat?

Also, I do not like the dependence on the inline attribute since this attribute is specific to the news collection, so I'd remove the inline-check from this code.

Idk, because if for some reason someone forgets to set page.title it would render a possibly very big content inside the search, while if someone set both the page.title and inline the page.title would simply be ignored. I think the error that it generates with inline is "less extreme" than by using the title like you said.

@CheariX
Copy link
Contributor Author

CheariX commented Jun 2, 2024

Update: On upstream/master, I get a rendered Link. I don't know why, but anyways, i think it should not be rendered. The link is not intended to be clicked, and it is also hard to read.

I agree that it is hard to read, but I am not sure if it should not be clicked. Think about this use case, what should happen if the user search for the news, and it is inline with a link? Should it only be read, or should be possible to click in it? But I don't think we should take the link and expand to the whole line either, because maybe the news has more than one link in it. I'd like to have more opinions on that matter. What do you think @pourmand1376?

In my humble opinion, the ideal behavior would be to visit the news page. If it is an inline news, all other inline news should become invisible through the use of CSS or JavaScript. Similarly, I imagine searching for BibTeX and papers.

Also, I do not like the dependence on the inline attribute since this attribute is specific to the news collection, so I'd remove the inline-check from this code.

Idk, because if for some reason someone forgets to set page.title it would render a possibly very big content inside the search, while if someone set both the page.title and inline the page.title would simply be ignored. I think the error that it generates with inline is "less extreme" than by using the title like you said.

Well, if someone forgets it, would that be a user error? We could also apply something like truncatewords: 50.
I just found newline_to_br. Use it for displaying longer entries like this:

grafik

If page.title and inline are both set, page.title should take precedence; or at least, this is what I would expect.

@george-gca
Copy link
Collaborator

Ok I will take a closer look at this.

@CheariX CheariX changed the title Search broken due to markdown in news Search broken due to newline in news Jun 29, 2024
@george-gca george-gca self-assigned this Jul 8, 2024
@sim642
Copy link
Contributor

sim642 commented Jul 9, 2024

I suggest to use strip_html | strip_newlines | escape for all three cases here (not only for the description).

I use markdown links in inline news and also changed to these filters to not have HTML source being shown as search entries.

@george-gca
Copy link
Collaborator

Just tested your suggestion @CheariX, and it won't work. If the title is not defined, it is generated automatically from the filename apparently. For example, for the 1st news it generated Announcement_1 even though the title is not defined in the front matter. So I will keep the inline solution.

I will add the strip_html | strip_newlines | escape to the title, it makes sense. Also I will add truncatewords: 10 for all the titles.

george-gca added a commit that referenced this issue Jul 10, 2024
Fixes #2459

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
meiqing-wang pushed a commit to meiqing-wang/meiqing-wang.github.io that referenced this issue Oct 13, 2024
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.

3 participants