diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 26 |
1 files changed, 26 insertions, 0 deletions
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 |