feat(prefs): imgur & reddit link replacers
This commit is contained in:
parent
a451755d2b
commit
c53b8d4d8a
2 changed files with 17 additions and 0 deletions
|
@ -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}/")
|
||||
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue