diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-09-14 08:46:07 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2017-09-18 21:18:29 -1000 |
commit | 00472915a4fb29399109ec9c088ab1e6a3f9b0ec (patch) | |
tree | 4b0bc076e8fda9de5dcc4bc96a51c39dce03c518 /lib/serve.js | |
parent | c8ef3a1d10fe170e6a1939bb83e6148c4bdbd72d (diff) | |
download | patchfoo-00472915a4fb29399109ec9c088ab1e6a3f9b0ec.tar.gz patchfoo-00472915a4fb29399109ec9c088ab1e6a3f9b0ec.zip |
Render npm-packages
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 |