From cc931d02bbe2a9868e1659cd082afda104a37677 Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 20:03:26 -0500 Subject: [PATCH 1/7] Initial test of imgur redirect --- src/formatters.nim | 3 +++ src/prefs_impl.nim | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/formatters.nim b/src/formatters.nim index 3630917..2f6893d 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -68,6 +68,9 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = result = result.replace(rdRegex, prefs.replaceReddit) if prefs.replaceReddit in result and "/gallery/" in result: result = result.replace("/gallery/", "/comments/") + + if prefs.replaceImgur.len > 0 and "https://imgur.com" in result: + result = result.replace("imgur.com", prefs.replaceImgur) if absolute.len > 0 and "href" in result: result = result.replace("href=\"/", &"href=\"{absolute}/") diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 8e2ac8f..30fda5d 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -106,6 +106,26 @@ genPrefs: replaceReddit(input, ""): "Reddit -> Teddit/Libreddit" placeholder: "Teddit hostname" + + replaceImgur(input, ""): + "Imgur -> Rimgo" + placeholder: "Rimgo hostname" + + #replaceMedium(input, ""): + # "Medium -> Scribe" + # placeholder: "Scribe hostname" + + #replaceFandom(input, ""): + # "Fandom -> BreezeWiki" + # placeholder: "BreezeWiki hostname" + + #replaceQuora(input, ""): + # "Quora -> Quetre" + # placeholder: "Quetre hostname" + + #replaceIMDb(input, ""): + # "IMDb -> libremdb" + # placeholder: "libremdb hostname" iterator allPrefs*(): Pref = for k, v in prefList: From 1a804dc6e22dce427e825feddb3ee4e1d811f32a Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 20:24:39 -0500 Subject: [PATCH 2/7] Account for more Imgur domains --- src/formatters.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index 2f6893d..736c6b8 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -20,6 +20,8 @@ let # so v.redd.it links will not be replaced. # Images aren't supported due to errors from Teddit when the image # wasn't first displayed via a post on the Teddit instance. + + imgurRegex = re"(i|i.stack)\.)?imgur.com" wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" @@ -69,8 +71,8 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = if prefs.replaceReddit in result and "/gallery/" in result: result = result.replace("/gallery/", "/comments/") - if prefs.replaceImgur.len > 0 and "https://imgur.com" in result: - result = result.replace("imgur.com", prefs.replaceImgur) + if prefs.replaceImgur.len > 0 and "imgur.com" in result: + result = result.replace(imgurRegex, prefs.replaceImgur) if absolute.len > 0 and "href" in result: result = result.replace("href=\"/", &"href=\"{absolute}/") From 8670a71c30e564598a6ac6aced3630a206711c57 Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 20:28:21 -0500 Subject: [PATCH 3/7] Fix missing parentheses in Imgur regex --- src/formatters.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatters.nim b/src/formatters.nim index 736c6b8..0647505 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -21,7 +21,7 @@ let # Images aren't supported due to errors from Teddit when the image # wasn't first displayed via a post on the Teddit instance. - imgurRegex = re"(i|i.stack)\.)?imgur.com" + imgurRegex = re"((i|i.stack)\.)?imgur.com" wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" From 8a741f4d5f67dca971503b5649d5590a20289d5f Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 20:32:22 -0500 Subject: [PATCH 4/7] Account for imgur.io --- src/formatters.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/formatters.nim b/src/formatters.nim index 0647505..75ff17e 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -21,7 +21,7 @@ let # Images aren't supported due to errors from Teddit when the image # wasn't first displayed via a post on the Teddit instance. - imgurRegex = re"((i|i.stack)\.)?imgur.com" + imgurRegex = re"((i|i.stack)\.)?imgur.(com|io)" wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" From a5c6fe0ed3a3d418cf84c59b0e29a0bd35104b9e Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 20:52:28 -0500 Subject: [PATCH 5/7] Fix accounting for imgur.io --- src/formatters.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index 75ff17e..4f9e52e 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -21,7 +21,7 @@ let # Images aren't supported due to errors from Teddit when the image # wasn't first displayed via a post on the Teddit instance. - imgurRegex = re"((i|i.stack)\.)?imgur.(com|io)" + imgurRegex = re"((i|i.stack)\.)?imgur\.(com|io)" wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" @@ -71,7 +71,7 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = if prefs.replaceReddit in result and "/gallery/" in result: result = result.replace("/gallery/", "/comments/") - if prefs.replaceImgur.len > 0 and "imgur.com" in result: + if prefs.replaceImgur.len > 0 and "imgur" in result: result = result.replace(imgurRegex, prefs.replaceImgur) if absolute.len > 0 and "href" in result: From 4a6b998640715272e57a13aeec1aa759e71343da Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Mon, 13 Nov 2023 21:06:27 -0500 Subject: [PATCH 6/7] Add in link replacement for medium.com --- src/formatters.nim | 5 +++++ src/prefs_impl.nim | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/formatters.nim b/src/formatters.nim index 4f9e52e..bf479a1 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -22,6 +22,8 @@ let # wasn't first displayed via a post on the Teddit instance. imgurRegex = re"((i|i.stack)\.)?imgur\.(com|io)" + + mediumRegex = re"([a-zA-Z0-9_.-]+\.)?medium\.com" wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" @@ -73,6 +75,9 @@ proc replaceUrls*(body: string; prefs: Prefs; absolute=""): string = if prefs.replaceImgur.len > 0 and "imgur" in result: result = result.replace(imgurRegex, prefs.replaceImgur) + + if prefs.replaceMedium.len > 0 and "medium.com" in result: + result = result.replace(mediumRegex, prefs.replaceMedium) if absolute.len > 0 and "href" in result: result = result.replace("href=\"/", &"href=\"{absolute}/") diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 30fda5d..4eea252 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -111,9 +111,9 @@ genPrefs: "Imgur -> Rimgo" placeholder: "Rimgo hostname" - #replaceMedium(input, ""): - # "Medium -> Scribe" - # placeholder: "Scribe hostname" + replaceMedium(input, ""): + "Medium -> Scribe" + placeholder: "Scribe hostname" #replaceFandom(input, ""): # "Fandom -> BreezeWiki" From e6ff6281036af0c59ec1000042d961dbb7221160 Mon Sep 17 00:00:00 2001 From: Butter Cat Date: Tue, 14 Nov 2023 19:22:08 -0500 Subject: [PATCH 7/7] Remove commented out services --- src/prefs_impl.nim | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/prefs_impl.nim b/src/prefs_impl.nim index 4eea252..346cffa 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -114,18 +114,6 @@ genPrefs: replaceMedium(input, ""): "Medium -> Scribe" placeholder: "Scribe hostname" - - #replaceFandom(input, ""): - # "Fandom -> BreezeWiki" - # placeholder: "BreezeWiki hostname" - - #replaceQuora(input, ""): - # "Quora -> Quetre" - # placeholder: "Quetre hostname" - - #replaceIMDb(input, ""): - # "IMDb -> libremdb" - # placeholder: "libremdb hostname" iterator allPrefs*(): Pref = for k, v in prefList: