From 678bce09b58899d8689acf40946b9985db7a9ada Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 8 Dec 2017 12:28:31 -0800 Subject: Render blog messages --- lib/serve.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index c100f40..c858a1b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -326,6 +326,7 @@ Serve.prototype.path = function (url) { case '/npm': return this.npm(m[2]) case '/npm-prebuilds': return this.npmPrebuilds(m[2]) case '/npm-readme': return this.npmReadme(m[2]) + case '/markdown': return this.markdown(m[2]) } return this.respond(404, 'Not found') } @@ -2143,6 +2144,31 @@ Serve.prototype.npmReadme = function (url) { ) } +Serve.prototype.markdown = function (url) { + var self = this + var id = decodeURIComponent(url.substr(1)) + var blobs = self.app.sbot.blobs + return pull( + ph('section', {}, [ + ph('h3', [ + ph('a', {href: '/links/' + id}, id.substr(0, 8) + '…') + ]), + u.readNext(function (cb) { + blobs.size(id, function (err, size) { + if (size == null) return cb(null, self.askWantBlobsForm([id])) + pull(blobs.get(id), pull.collect(function (err, chunks) { + if (err) return cb(null, ph('div', u.renderError(err).outerHTML)) + var text = Buffer.concat(chunks).toString() + cb(null, ph('blockquote', self.app.render.markdown(text))) + })) + }) + }) + ]), + self.wrapPage('markdown'), + self.respondSink(200) + ) +} + // wrap a binary source and render it or turn into an embed Serve.prototype.wrapBinary = function (opts) { var self = this -- cgit v1.2.3