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

Add link replacements for Medium and Imgur #1117

Open
wants to merge 9 commits into
base: guest_accounts
Choose a base branch
from
10 changes: 10 additions & 0 deletions src/formatters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ 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|io)"

mediumRegex = re"([a-zA-Z0-9_.-]+\.)?medium\.com"

wwwRegex = re"https?://(www[0-9]?\.)?"
m3u8Regex = re"""url="(.+.m3u8)""""
Expand Down Expand Up @@ -68,6 +72,12 @@ 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 "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}/")
Expand Down
8 changes: 8 additions & 0 deletions src/prefs_impl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ genPrefs:
replaceReddit(input, ""):
"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:
Expand Down