diff --git a/src/templates/index.mustache b/src/templates/index.mustache new file mode 100644 index 0000000..1e1ffcb --- /dev/null +++ b/src/templates/index.mustache @@ -0,0 +1 @@ +

welcome to the twtxt list. this is an openly available list of users of twtxt, the decentralized microblogging tool. this will poll every submitted user every 5 minutes to update its view.

diff --git a/src/templates/users.mustache b/src/templates/users.mustache new file mode 100644 index 0000000..3949d3b --- /dev/null +++ b/src/templates/users.mustache @@ -0,0 +1,5 @@ + diff --git a/src/twtxtlist.nim b/src/twtxtlist.nim index f5a4fc2..4a14d66 100644 --- a/src/twtxtlist.nim +++ b/src/twtxtlist.nim @@ -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()