Make links clickable as well as @usernames
Turns: @reednj Yeah I was gonna work on that today http://foo.bar <b>foo</b> into: <a href="/users/reednj/0">@reednj</a> Yeah I was gonna work on that today <a href="http://foo.bar">http://foo.bar</a> <b>foo</b>
This commit is contained in:
parent
de62f04bf4
commit
edcddaedd8
|
@ -7,7 +7,7 @@
|
||||||
{{# tweets }}
|
{{# tweets }}
|
||||||
<div class="entries">
|
<div class="entries">
|
||||||
<a href="/users/{{ username }}/0">@{{ username }}</a> - {{ time }}
|
<a href="/users/{{ username }}/0">@{{ username }}</a> - {{ time }}
|
||||||
<p>{{ tweet }}</p>
|
<p>{{{ tweet }}}</p>
|
||||||
<small><a href="/tweet/{{ permalink }}">permalink</a></small>
|
<small><a href="/tweet/{{ permalink }}">permalink</a></small>
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
parse
|
|
@ -0,0 +1,32 @@
|
||||||
|
import strutils, ../twtxt
|
||||||
|
from htmlgen import nil
|
||||||
|
|
||||||
|
type
|
||||||
|
TweetData* = seq[string]
|
||||||
|
|
||||||
|
proc `$`*(t: TweetData): string = t.join ""
|
||||||
|
|
||||||
|
proc prettyfyTweet*(t: string): TweetData =
|
||||||
|
result = newSeq[string]()
|
||||||
|
|
||||||
|
var tweet = t.replace("<", "<").replace(">", ">")
|
||||||
|
|
||||||
|
for word in tokenize(tweet):
|
||||||
|
if word.isSep:
|
||||||
|
result.add word.token
|
||||||
|
else:
|
||||||
|
if word.token.startsWith "@":
|
||||||
|
let
|
||||||
|
username = word.token.substr 1
|
||||||
|
ahref = htmlgen.a(href="/users/" & username & "/0", word.token)
|
||||||
|
result.add ahref
|
||||||
|
elif word.token.startsWith "http":
|
||||||
|
let ahref = htmlgen.a(href=word.token, word.token)
|
||||||
|
result.add ahref
|
||||||
|
else:
|
||||||
|
result.add word.token
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
const inp = "@reednj Yeah I was gonna work on that today http://foo.bar <b>foo</b>"
|
||||||
|
|
||||||
|
echo inp.prettyfyTweet
|
|
@ -1,5 +1,5 @@
|
||||||
import asyncdispatch, db_sqlite, httpclient, jester, moustachu, os, shorturl,
|
import asyncdispatch, db_sqlite, httpclient, jester, moustachu, os, shorturl,
|
||||||
strutils, tables, templates/all, times, twtxt, typetraits
|
strutils, tables, templates/all, times, tweet/parse, twtxt, typetraits
|
||||||
|
|
||||||
let
|
let
|
||||||
db = open("data/twtxt.db", nil, nil, nil)
|
db = open("data/twtxt.db", nil, nil, nil)
|
||||||
|
@ -142,7 +142,7 @@ routes:
|
||||||
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
||||||
c["username"] = tweet[1]
|
c["username"] = tweet[1]
|
||||||
c["time"] = time
|
c["time"] = time
|
||||||
c["tweet"] = tweet[3]
|
c["tweet"] = $tweet[3].prettyfyTweet()
|
||||||
|
|
||||||
tweetList.add c
|
tweetList.add c
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ routes:
|
||||||
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
||||||
c["username"] = tweet[1]
|
c["username"] = tweet[1]
|
||||||
c["time"] = time
|
c["time"] = time
|
||||||
c["tweet"] = tweet[3]
|
c["tweet"] = $tweet[3].prettyfyTweet()
|
||||||
|
|
||||||
tweetList.add c
|
tweetList.add c
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ routes:
|
||||||
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
c["permalink"] = tweet[0].parseInt().encodeURLSimple()
|
||||||
c["username"] = tweet[1]
|
c["username"] = tweet[1]
|
||||||
c["time"] = time
|
c["time"] = time
|
||||||
c["tweet"] = tweet[3]
|
c["tweet"] = $tweet[3].prettyfyTweet()
|
||||||
|
|
||||||
tweetList.add c
|
tweetList.add c
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue