aboutsummaryrefslogtreecommitdiff
path: root/lib/render.js
diff options
context:
space:
mode:
authorcel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-09-20 07:50:23 -1000
committercel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519>2017-09-20 09:35:33 -1000
commita9feab3b1f5335b14fc0feba4da2b9fe40aa1224 (patch)
treebf6f10ae9a721c1f531b18b6aec9d84463485151 /lib/render.js
parent73022a68b920123bf3c150dbce5d5872f6f00669 (diff)
downloadpatchfoo-a9feab3b1f5335b14fc0feba4da2b9fe40aa1224.tar.gz
patchfoo-a9feab3b1f5335b14fc0feba4da2b9fe40aa1224.zip
Render npm package publishers
Diffstat (limited to 'lib/render.js')
-rw-r--r--lib/render.js78
1 files changed, 48 insertions, 30 deletions
diff --git a/lib/render.js b/lib/render.js
index 9bba5bd..6001184 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -390,13 +390,18 @@ Render.prototype.highlight = function (code, lang) {
}
}
-Render.prototype.npmPackageMentions = function (links) {
+Render.prototype.npmPackageMentions = function (links, cb) {
var self = this
var pkgLinks = u.toArray(links).filter(function (link) {
return /^npm:/.test(link.name)
})
- return pkgLinks.length > 0 ? h('div',
- h('table',
+ if (pkgLinks.length === 0) return cb(null, '')
+ var done = multicb({pluck: 1})
+ pkgLinks.forEach(function (link) {
+ self.npmPackageMention(link, {}, done())
+ })
+ done(function (err, mentionEls) {
+ cb(null, h('table',
h('thead', h('tr',
h('td', 'package'),
h('td', 'version'),
@@ -404,37 +409,50 @@ Render.prototype.npmPackageMentions = function (links) {
h('td', 'size'),
h('td', 'tarball')
)),
- h('tbody', pkgLinks.map(function (link) {
- return self.npmPackageMention(link)
- }))
- )
- ) : ''
+ h('tbody', mentionEls)
+ ))
+ })
}
-Render.prototype.npmPackageMention = function (link) {
+Render.prototype.npmPackageMention = function (link, opts, cb) {
var parts = String(link.name).replace(/\.tgz$/, '').split(':')
var name = parts[1]
var version = parts[2]
var distTag = parts[3]
- return h('tr', [
- h('td', h('a', {
- href: this.toUrl('/npm/' + name),
- title: 'package name'
- }, name), ' '),
- h('td', version ? [h('a', {
- href: this.toUrl('/npm/' + name + '/' + version + '/'),
- title: 'package version'
- }, version), ' '] : ''),
- h('td', distTag ? [h('a', {
- href: this.toUrl('/npm/' + name + '//' + distTag + '/'),
- title: 'dist-tag'
- }, distTag), ' '] : ''),
- h('td', {align: 'right'}, link.size != null ? [h('span', {
- title: 'tarball size'
- }, this.formatSize(link.size)), ' '] : ''),
- h('td', typeof link.link === 'string' ? [h('a', {
- href: this.toUrl('/links/' + link.link),
- title: 'package tarball'
- }, link.link.substr(0, 8) + '…')] : '')
- ])
+ var self = this
+ var done = multicb({pluck: 1, spread: true})
+ var base = '/npm/' + (opts.author ? u.escapeId(link.author) + '/' : '')
+ var pathWithAuthor = '/npm/' +
+ u.escapeId(link.author) + '/' +
+ (opts.name ? opts.name + '/' +
+ (opts.version ? opts.version + '/' +
+ (opts.distTag ? opts.distTag + '/' : '') : '') : '')
+ self.app.getAbout(link.author, function (err, about) {
+ if (err) return cb(err)
+ cb(null, h('tr', [
+ opts.withAuthor ? h('td', h('a', {
+ href: self.toUrl(pathWithAuthor),
+ title: 'publisher'
+ }, about.name), ' ') : '',
+ h('td', h('a', {
+ href: self.toUrl(base + name),
+ title: 'package name'
+ }, name), ' '),
+ h('td', version ? [h('a', {
+ href: self.toUrl(base + name + '/' + version + '/'),
+ title: 'package version'
+ }, version), ' '] : ''),
+ h('td', distTag ? [h('a', {
+ href: self.toUrl(base + name + '//' + distTag + '/'),
+ title: 'dist-tag'
+ }, distTag), ' '] : ''),
+ h('td', {align: 'right'}, link.size != null ? [h('span', {
+ title: 'tarball size'
+ }, self.formatSize(link.size)), ' '] : ''),
+ h('td', typeof link.link === 'string' ? h('code', h('a', {
+ href: self.toUrl('/links/' + link.link),
+ title: 'package tarball'
+ }, link.link.substr(0, 8) + '…')) : '')
+ ]))
+ })
}