show index, user list
This commit is contained in:
parent
4dd24757f6
commit
cf9a26b0cb
|
@ -0,0 +1 @@
|
||||||
|
<p>welcome to the twtxt list. this is an openly available list of users of <a href="https://github.com/buckket/twtxt">twtxt</a>, the decentralized microblogging tool. this will poll every submitted user every 5 minutes to update its view.</p>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<ul>
|
||||||
|
{{# users }}
|
||||||
|
<li><a href="/users/{{ username }}">{{ username }}</a> <a href="{{ url }}">feed</a></li>
|
||||||
|
{{/ users }}
|
||||||
|
</ul>
|
|
@ -4,6 +4,8 @@ import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl,
|
||||||
const
|
const
|
||||||
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
||||||
errorTemplate*: string = staticRead "./templates/error.mustache"
|
errorTemplate*: string = staticRead "./templates/error.mustache"
|
||||||
|
indexTemplate*: string = staticRead "./templates/index.mustache"
|
||||||
|
usersTemplate*: string = staticRead "./templates/users.mustache"
|
||||||
|
|
||||||
let
|
let
|
||||||
db = open("data/twtxt.db", nil, nil, nil)
|
db = open("data/twtxt.db", nil, nil, nil)
|
||||||
|
@ -53,9 +55,23 @@ settings:
|
||||||
|
|
||||||
routes:
|
routes:
|
||||||
get "/":
|
get "/":
|
||||||
try:
|
renderMustache("home", indexTemplate, newContext())
|
||||||
raise newException(ValueError, "yolo")
|
|
||||||
except:
|
get "/users":
|
||||||
fail()
|
var
|
||||||
|
users = db.getAllRows(sql"select username, url from users")
|
||||||
|
ctx = newContext()
|
||||||
|
userList = newSeq[Context]()
|
||||||
|
|
||||||
|
for user in users.items():
|
||||||
|
var c = newContext()
|
||||||
|
c["username"] = user[0]
|
||||||
|
c["url"] = user[1]
|
||||||
|
|
||||||
|
userList.add c
|
||||||
|
|
||||||
|
ctx["users"] = userList
|
||||||
|
|
||||||
|
renderMustache "users", usersTemplate, ctx
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
Loading…
Reference in New Issue