From 00472915a4fb29399109ec9c088ab1e6a3f9b0ec Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 14 Sep 2017 08:46:07 -1000 Subject: Render npm-packages --- lib/serve.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/serve.js') 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 -- cgit v1.2.3