From 2eb748d24d3ee0d13f990d2b7eab167a1b41b930 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 20 Sep 2017 10:43:25 -1000 Subject: Render npm package readmes --- lib/serve.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'lib/serve.js') diff --git a/lib/serve.js b/lib/serve.js index 5ebfa47..c162e42 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -201,8 +201,9 @@ Serve.prototype.wantBlobs = function (cb) { if (!ids.every(u.isRef)) return cb(new Error('bad blob ids ' + ids.join(','))) var done = multicb({pluck: 1}) ids.forEach(function (id) { - self.app.sbot.blobs.want(id, done()) + self.app.wantSizeBlob(id, done()) }) + if (self.data.async_want) return cb() done(function (err) { if (err) return cb(err) // self.note = h('div', 'wanted blobs: ' + ids.join(', ') + '.') @@ -303,6 +304,7 @@ Serve.prototype.path = function (url) { case '/git': return this.git(m[2]) case '/image': return this.image(m[2]) case '/npm': return this.npm(m[2]) + case '/npm-readme': return this.npmReadme(m[2]) } return this.respond(404, 'Not found') } @@ -1911,7 +1913,8 @@ Serve.prototype.npm = function (url) { ph('td', 'version'), ph('td', 'tag'), ph('td', 'size'), - ph('td', 'tarball') + ph('td', 'tarball'), + ph('td', 'readme') ])), ph('tbody', pull( self.app.blobMentions({ @@ -1934,7 +1937,30 @@ Serve.prototype.npm = function (url) { )) ]) ]), - self.wrapPage('npm:'), + self.wrapPage(prefix), + self.respondSink(200) + ) +} + +Serve.prototype.npmReadme = function (url) { + var self = this + var id = decodeURIComponent(url.substr(1)) + return pull( + ph('section', {}, [ + ph('h3', [ + 'npm readme for ', + ph('a', {href: '/links/' + id}, id.substr(0, 8) + '…') + ]), + ph('blockquote', u.readNext(function (cb) { + self.app.getNpmReadme(id, function (err, readme, isMarkdown) { + if (err) return cb(null, ph('div', u.renderError(err).outerHTML)) + cb(null, isMarkdown + ? ph('div', self.app.render.markdown(readme)) + : ph('pre', readme)) + }) + })) + ]), + self.wrapPage('npm readme'), self.respondSink(200) ) } -- cgit v1.2.3