aboutsummaryrefslogtreecommitdiff
path: root/lib/render.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render.js')
-rw-r--r--lib/render.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/render.js b/lib/render.js
index 63eecd4..9bba5bd 100644
--- a/lib/render.js
+++ b/lib/render.js
@@ -389,3 +389,52 @@ Render.prototype.highlight = function (code, lang) {
return u.escapeHTML(code)
}
}
+
+Render.prototype.npmPackageMentions = function (links) {
+ var self = this
+ var pkgLinks = u.toArray(links).filter(function (link) {
+ return /^npm:/.test(link.name)
+ })
+ return pkgLinks.length > 0 ? h('div',
+ h('table',
+ h('thead', h('tr',
+ h('td', 'package'),
+ h('td', 'version'),
+ h('td', 'tag'),
+ h('td', 'size'),
+ h('td', 'tarball')
+ )),
+ h('tbody', pkgLinks.map(function (link) {
+ return self.npmPackageMention(link)
+ }))
+ )
+ ) : ''
+}
+
+Render.prototype.npmPackageMention = function (link) {
+ 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) + '…')] : '')
+ ])
+}