show index, user list

This commit is contained in:
Christine Dodrill 2016-02-06 08:27:31 -08:00
parent 4dd24757f6
commit cf9a26b0cb
3 changed files with 26 additions and 4 deletions

View File

@ -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>

View File

@ -0,0 +1,5 @@
<ul>
{{# users }}
<li><a href="/users/{{ username }}">{{ username }}</a> <a href="{{ url }}">feed</a></li>
{{/ users }}
</ul>

View File

@ -4,6 +4,8 @@ import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl,
const
baseTemplate*: string = staticRead "./templates/layout.mustache"
errorTemplate*: string = staticRead "./templates/error.mustache"
indexTemplate*: string = staticRead "./templates/index.mustache"
usersTemplate*: string = staticRead "./templates/users.mustache"
let
db = open("data/twtxt.db", nil, nil, nil)
@ -53,9 +55,23 @@ settings:
routes:
get "/":
try:
raise newException(ValueError, "yolo")
except:
fail()
renderMustache("home", indexTemplate, newContext())
get "/users":
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()