2 Commits

Author SHA1 Message Date
Salastil 85a03a575e Regex fixes, nre is not compiling 2026-05-15 17:05:46 -04:00
Salastil a78d4655cd Add cashtag filter option 2026-05-15 16:52:01 -04:00
5 changed files with 15 additions and 18 deletions
+3 -3
View File
@@ -1,4 +1,4 @@
import std/[algorithm, unicode, re, strutils, strformat, options, nre] import std/[algorithm, unicode, re, strutils, strformat, options]
import jsony import jsony
import utils, slices import utils, slices
import ../types/user as userType import ../types/user as userType
@@ -8,7 +8,7 @@ let
unRegex = re.re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})" unRegex = re.re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})"
unReplace = "$1<a href=\"/$2\">@$2</a>" unReplace = "$1<a href=\"/$2\">@$2</a>"
htRegex = nre.re"""(*U)(^|[^\w-_.?])([#$])([\w_]*+)(?!</a>|">|#)""" htRegex = re.re"(^|[^a-zA-Z0-9_-_.?])([#$])([a-zA-Z0-9_]+)"
htReplace = "$1<a href=\"/search?f=tweets&q=%23$3\">$2$3</a>" htReplace = "$1<a href=\"/search?f=tweets&q=%23$3\">$2$3</a>"
proc expandUserEntities(user: var User; raw: RawUser) = proc expandUserEntities(user: var User; raw: RawUser) =
@@ -29,7 +29,7 @@ proc expandUserEntities(user: var User; raw: RawUser) =
user.bio = orig.replacedWith(replacements, 0 .. orig.len) user.bio = orig.replacedWith(replacements, 0 .. orig.len)
.replacef(unRegex, unReplace) .replacef(unRegex, unReplace)
.replace(htRegex, htReplace) .replacef(htRegex, htReplace)
proc getBanner(user: RawUser): string = proc getBanner(user: RawUser): string =
if user.profileBannerUrl.len > 0: if user.profileBannerUrl.len > 0:
+8 -12
View File
@@ -438,7 +438,7 @@ proc parseTweet(js: JsonNode; jsCard: JsonNode = newJNull();
result.retweet = some parseGraphTweet(rt) result.retweet = some parseGraphTweet(rt)
return return
if jsCard.kind != JNull and jsCard{"rest_id"}.getStr.allCharsInSet({'0'..'9'}): if jsCard.kind != JNull:
let name = jsCard{"name"}.getStr let name = jsCard{"name"}.getStr
if "poll" in name: if "poll" in name:
if "image" in name: if "image" in name:
@@ -498,17 +498,13 @@ proc parseGraphTweet(js: JsonNode): Tweet =
if bindingArray.kind == JArray: if bindingArray.kind == JArray:
var bindingObj: seq[(string, JsonNode)] var bindingObj: seq[(string, JsonNode)]
for item in bindingArray: for item in bindingArray:
if item{"key"}.getStr == "_omit_link_":
jsCard = newJNull()
break
bindingObj.add((item{"key"}.getStr, item{"value"})) bindingObj.add((item{"key"}.getStr, item{"value"}))
if jsCard.kind != JNull: # Create a new card object with flattened structure
# Create a new card object with flattened structure jsCard = %*{
jsCard = %*{ "name": legacyCard{"name"},
"name": legacyCard{"name"}, "url": legacyCard{"url"},
"url": legacyCard{"url"}, "binding_values": %bindingObj
"binding_values": %bindingObj }
}
var replyId = 0 var replyId = 0
with restId, js{"reply_to_results", "rest_id"}: with restId, js{"reply_to_results", "rest_id"}:
@@ -530,7 +526,7 @@ proc parseGraphTweet(js: JsonNode): Tweet =
) )
) )
if jsCard.kind != JNull and jsCard{"rest_id"}.getStr.allCharsInSet({'0'..'9'}): if jsCard.kind != JNull:
let name = jsCard{"name"}.getStr let name = jsCard{"name"}.getStr
if "poll" in name: if "poll" in name:
if "image" in name: if "image" in name:
+1 -1
View File
@@ -16,7 +16,7 @@ let
unRegex = re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})" unRegex = re"(^|[^A-z0-9-_./?])@([A-z0-9_]{1,15})"
unReplace = "$1<a href=\"/$2\">@$2</a>" unReplace = "$1<a href=\"/$2\">@$2</a>"
htRegex = re"(^|[^\w-_./?])([#$]|)([\w_]+)" htRegex = re"(^|[^a-zA-Z0-9_-_.?])([#$]|)([a-zA-Z0-9_]+)"
htReplace = "$1<a href=\"/search?f=tweets&q=%23$3\">$2$3</a>" htReplace = "$1<a href=\"/search?f=tweets&q=%23$3\">$2$3</a>"
type type
+1 -1
View File
@@ -8,7 +8,7 @@ const
"media", "images", "twimg", "videos", "media", "images", "twimg", "videos",
"native_video", "consumer_video", "spaces", "native_video", "consumer_video", "spaces",
"links", "news", "quote", "mentions", "links", "news", "quote", "mentions",
"replies", "retweets", "nativeretweets" "replies", "retweets", "nativeretweets", "cashtags"
] ]
emptyQuery* = "include:nativeretweets" emptyQuery* = "include:nativeretweets"
+2 -1
View File
@@ -15,7 +15,8 @@ const toggles = {
"links": "Links", "links": "Links",
"images": "Images", "images": "Images",
"quote": "Quotes", "quote": "Quotes",
"spaces": "Spaces" "spaces": "Spaces",
"cashtags": "Cashtags"
}.toOrderedTable }.toOrderedTable
proc renderSearch*(): VNode = proc renderSearch*(): VNode =