From a9feab3b1f5335b14fc0feba4da2b9fe40aa1224 Mon Sep 17 00:00:00 2001 From: cel Date: Wed, 20 Sep 2017 07:50:23 -1000 Subject: Render npm package publishers --- lib/render.js | 78 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 30 deletions(-) (limited to 'lib/render.js') 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) + '…')) : '') + ])) + }) } -- cgit v1.2.3