From ac3d249d64c586e8e000b45b7ca96773b2de61af Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 3 Feb 2017 16:17:20 -0800 Subject: Add links view --- lib/serve.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/serve.js b/lib/serve.js index f104e3a..f850302 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -124,6 +124,7 @@ Serve.prototype.path = function (url) { m = /^(\/?[^\/]*)(\/.*)?$/.exec(url) switch (m[1]) { case '/type': return this.type(m[2]) + case '/links': return this.links(m[2]) case '/static': return this.static(m[2]) case '/emoji': return this.emoji(m[2]) } @@ -236,6 +237,27 @@ Serve.prototype.type = function (path) { ) } +Serve.prototype.links = function (path) { + var q = this.query + var dest = path.substr(1) + var opts = { + dest: dest, + reverse: true, + values: true, + } + + pull( + this.app.sbot.links(opts), + this.renderThread(opts, null, q), + this.wrapMessages(), + this.wrapLinks(dest), + this.wrapPage('links: ' + dest), + this.respondSink(200, { + 'Content-Type': ctype('html') + }) + ) +} + Serve.prototype.vote = function (ext) { var self = this @@ -717,6 +739,20 @@ Serve.prototype.wrapType = function (type) { }) } +Serve.prototype.wrapLinks = function (dest) { + var self = this + return u.hyperwrap(function (thread, cb) { + cb(null, [ + h('section', + h('h3.feed-name', 'links: ', + h('a', {href: self.app.render.toUrl('/links/' + dest)}, + h('code', dest))) + ), + thread + ]) + }) +} + function rows(str) { return String(str).split(/[^\n]{70}|\n/).length } -- cgit v1.2.3