utterance / utterances

:crystal_ball: A lightweight comments widget built on GitHub issues
https://utteranc.es
MIT License
8.66k stars 567 forks source link

Utterances will not match to URLs exactly #661

Open ericswpark opened 8 months ago

ericswpark commented 8 months ago

I have two blog sections on my website:

The first link is for the English version of my website, while the second one is for the Korean version. As the audience for these two blogs speak different languages, it makes sense to separate the comments section as well.

However, Utterances is mixing the two comment sections, even though I'm using the url mapping option. For example, see: https://ericswpark.com/blog/2020/2020-10-11-porting-samsungs-galaxy-note-3-neo/ Even though the blog is in the English version, it is pulling up the Korean comment section with the issue title of https://ericswpark.com/ko/blog/2020/2020-10-11-porting-samsungs-galaxy-note-3-neo/

Duncanma commented 6 months ago

I think this is because GitHub is not doing an exact string match on issues... you can try the query yourself

https://github.com/ericswpark/ericswpark.github.io-comments/issues?q=is%3Aissue+in%3Atitle+%22https%3A%2F%2Fericswpark.com%2Fblog%2F2020%2F2020-10-11-porting-samsungs-galaxy-note-3-neo%2F%22+

To see that it returns the /ko/ ones when searching with the non-ko URL.

I'm also thinking it is treating the / and - characters as whitespace... so it is really searching for any issues with the following strings

https ericswpark.com blog 2020 2020 10 11 porting samsungs galaxy note 3 neo

To fix, I would say it might work if the URL was condensed into a single string both when the 1st issue is posted and when searching.... so something like "ericswpark.comblog202020201011portingsamsungsgalaxynote3neo"

Or a hash of the URL? a MD5 hash of the non-ko post would be 40b39569eb54ed2e4e29175a9343914c and the ko one would be cd1d3eb3b0ff6da17ac4c0924bda8ab7

ericswpark commented 5 months ago

I think the OP should have some hash of the URL that utterances could compare against, to make sure that the correct thread is fetched.

ericswpark commented 5 months ago

Think I found the relevant part:

https://github.com/utterance/utterances/blob/9e79bdaaa48c0b83d224c58f132db317785103cd/src/github.ts#L133

This function should check if the response returned from the GitHub API has a matching title:

Screenshot 2023-12-11 at 3 47 50 PM

ericswpark commented 5 months ago

Actually, seems like title matching is already done: Screenshot 2023-12-11 at 3 50 27 PM https://github.com/utterance/utterances/blob/9e79bdaaa48c0b83d224c58f132db317785103cd/src/github.ts#L151 https://github.com/utterance/utterances/blob/9e79bdaaa48c0b83d224c58f132db317785103cd/src/github.ts#L156

So the only change needed is to not blindly return the first result when none of the titles match, and seems like there's already a PR open for that: #496