diff options
Diffstat (limited to 'lib/serve.js')
-rw-r--r-- | lib/serve.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/serve.js b/lib/serve.js index c4c740c..9686927 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -302,6 +302,7 @@ Serve.prototype.path = function (url) { case '/about': return this.about(m[2]) case '/git': return this.git(m[2]) case '/image': return this.image(m[2]) + case '/npm': return this.npm(m[2]) } return this.respond(404, 'Not found') } @@ -1872,6 +1873,42 @@ Serve.prototype.gitObjectLinks = function (headMsgId, type) { }, 8) } +Serve.prototype.npm = function (url) { + var self = this + var parts = url.split('/') + var name = parts[1] + var version = parts[2] + var distTag = parts[3] + var prefix = 'npm:' + + (name ? name + ':' + + (version ? version + ':' + + (distTag ? distTag + ':' : '') : '') : '') + + return pull( + ph('section', {}, [ + ph('h3', ['npm: ', + name ? [ph('code', name), ' '] : '', + version ? [ph('code', version), ' '] : '', + distTag ? [ph('code', distTag), ' '] : '' + ]), + pull( + self.app.blobMentions({ + name: {$prefix: prefix} + }), + distTag && !version && pull.filter(function (link) { + return link.name.split(':')[3] === distTag + }), + pull.map(function (link) { + return self.app.render.npmPackageMention(link) + }), + pull.map(u.toHTML) + ) + ]), + self.wrapPage('npm:'), + self.respondSink(200) + ) +} + // wrap a binary source and render it or turn into an embed Serve.prototype.wrapBinary = function (opts) { var self = this |