diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-09-20 10:43:25 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-09-20 10:44:17 -1000 |
commit | 2eb748d24d3ee0d13f990d2b7eab167a1b41b930 (patch) | |
tree | bc28850107b8360a188ecd59dc8c78887eecc410 /lib/serve.js | |
parent | a9feab3b1f5335b14fc0feba4da2b9fe40aa1224 (diff) | |
download | patchfoo-2eb748d24d3ee0d13f990d2b7eab167a1b41b930.tar.gz patchfoo-2eb748d24d3ee0d13f990d2b7eab167a1b41b930.zip |
Render npm package readmes
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 32 |
1 files changed, 29 insertions, 3 deletions
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) ) } |