From c53b8d4d8a2e9e37722eaee57369c082387550ba Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Mon, 20 May 2024 13:01:40 +0000 Subject: [PATCH] feat(prefs): imgur & reddit link replacers --- src/formatters.nim | 9 +++++++++ src/prefs_impl.nim | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/formatters.nim b/src/formatters.nim index 3630917..ed17c80 100644 --- a/src/formatters.nim +++ b/src/formatters.nim @@ -21,6 +21,9 @@ 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)" + mediumRegex = re"([a-zA-Z0-9_.-]+\.)?medium\.com" + wwwRegex = re"https?://(www[0-9]?\.)?" m3u8Regex = re"""url="(.+.m3u8)"""" userPicRegex = re"_(normal|bigger|mini|200x200|400x400)(\.[A-z]+)$" @@ -69,6 +72,12 @@ 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" 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 8e2ac8f..053647d 100644 --- a/src/prefs_impl.nim +++ b/src/prefs_impl.nim @@ -107,6 +107,14 @@ genPrefs: "Reddit -> Teddit/Libreddit" placeholder: "Teddit hostname" + replaceImgur(input, ""): + "Imgur -> Rimgo" + placeholder: "Rimgo hostname" + + replaceMedium(input, ""): + "Medium -> Scribe" + placeholder: "Scribe hostname" + iterator allPrefs*(): Pref = for k, v in prefList: for pref in v: