diff options
-rw-r--r-- | lib/serve.js | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/lib/serve.js b/lib/serve.js index 507fe72..0dd403a 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -123,6 +123,7 @@ Serve.prototype.path = function (url) { } m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { + case '/type': return this.type(m[2]) case '/static': return this.static(m[2]) case '/emoji': return this.emoji(m[2]) } @@ -212,6 +213,29 @@ Serve.prototype.search = function (ext) { ) } +Serve.prototype.type = function (path) { + var q = this.query + var type = path.substr(1) + var opts = { + reverse: !q.forwards, + lt: Number(q.lt) || Date.now(), + gt: Number(q.gt) || -Infinity, + limit: Number(q.limit) || 12, + type: type, + } + + pull( + this.app.sbot.messagesByType(opts), + this.renderThreadPaginated(opts, null, q), + this.wrapMessages(), + this.wrapType(type), + this.wrapPage('type: ' + type), + this.respondSink(200, { + 'Content-Type': ctype('html') + }) + ) +} + Serve.prototype.vote = function (ext) { var self = this @@ -457,7 +481,7 @@ Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { return pull( paginate( function onFirst(msg, cb) { - var num = feedId ? msg.value.sequence : msg.timestamp + var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { link({ lt: num, @@ -474,7 +498,7 @@ Serve.prototype.renderThreadPaginated = function (opts, feedId, q) { }, this.app.render.renderFeeds(), function onLast(msg, cb) { - var num = feedId ? msg.value.sequence : msg.timestamp + var num = feedId ? msg.value.sequence : msg.timestamp || msg.ts if (q.forwards) { link({ lt: null, @@ -672,6 +696,20 @@ Serve.prototype.wrapChannel = function (channel) { }) } +Serve.prototype.wrapType = function (type) { + var self = this + return u.hyperwrap(function (thread, cb) { + cb(null, [ + h('section', + h('h3.feed-name', + h('a', {href: self.app.render.toUrl('/type/' + type)}, + h('code', type), 's')) + ), + thread + ]) + }) +} + function rows(str) { return String(str).split(/[^\n]{70}|\n/).length } |