aboutsummaryrefslogtreecommitdiff
path: root/lib/render-msg.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/render-msg.js')
-rw-r--r--lib/render-msg.js109
1 files changed, 104 insertions, 5 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 8346baf..262b6e7 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -241,6 +241,7 @@ RenderMsg.prototype.message = function (cb) {
case 'wifi-network': return this.wifiNetwork(cb)
case 'mutual/credit': return this.mutualCredit(cb)
case 'mutual/account': return this.mutualAccount(cb)
+ case 'npm-publish': return this.npmPublish(cb)
default: return this.object(cb)
}
}
@@ -268,13 +269,9 @@ RenderMsg.prototype.markdownSource = function (text, mentions) {
RenderMsg.prototype.post = function (cb) {
var self = this
var done = multicb({pluck: 1, spread: true})
- var branchDone = multicb({pluck: 1})
- u.toArray(self.c.branch).forEach(function (branch) {
- self.link(branch, branchDone())
- })
if (self.c.root === self.c.branch) done()()
else self.link(self.c.root, done())
- branchDone(done())
+ self.links(self.c.branch, done())
done(function (err, rootLink, branchLinks) {
if (err) return self.wrap(u.renderError(err), cb)
self.wrap(h('div.ssb-post',
@@ -347,6 +344,8 @@ RenderMsg.prototype.title = function (cb) {
} else {
if (self.c.type === 'ssb-dns')
cb(null, self.c.record && JSON.stringify(self.c.record.data) || self.msg.key)
+ else if (self.c.type === 'npm-publish')
+ self.npmPublishTitle(cb)
else
self.app.getAbout(self.msg.key, function (err, about) {
if (err) return cb(err)
@@ -389,6 +388,15 @@ RenderMsg.prototype.link1 = function (link, cb) {
return a
}
+RenderMsg.prototype.links = function (links, cb) {
+ var self = this
+ var done = multicb({pluck: 1})
+ u.toArray(links).forEach(function (link) {
+ self.link(link, done())
+ })
+ done(cb)
+}
+
function dateTime(d) {
var date = new Date(d.epoch)
return date.toString()
@@ -840,3 +848,94 @@ RenderMsg.prototype.micro = function (cb) {
var el = h('span', {innerHTML: unwrapP(this.markdown())})
this.wrapMini(el, cb)
}
+
+function hJoin(els, seperator) {
+ return els.map(function (el, i) {
+ return [i === 0 ? '' : separator, el]
+ })
+}
+
+function asNpmReadme(readme) {
+ if (!readme || readme === 'ERROR: No README data found!') return
+ return u.ifString(readme)
+}
+
+RenderMsg.prototype.npmPublish = function (cb) {
+ var self = this
+ var render = self.render
+ var pkg = self.c.meta || {}
+ var pkgReadme = asNpmReadme(pkg.readme)
+ var pkgDescription = u.ifString(pkg.description)
+
+ var versions = Object.keys(pkg.versions || {})
+ var singleVersion = versions.length === 1 ? versions[0] : null
+ var singleRelease = singleVersion && pkg.versions[singleVersion]
+ var singleReadme = singleRelease && asNpmReadme(singleRelease.readme)
+
+ var distTags = pkg['dist-tags'] || {}
+ var distTagged = {}
+ for (var distTag in distTags)
+ if (distTag !== 'latest')
+ distTagged[distTags[distTag]] = distTag
+
+ self.links(self.c.previousPublish, function (err, prevLinks) {
+ if (err) return cb(err)
+ self.wrap([
+ h('div',
+ 'published ',
+ h('u', pkg.name), ' ',
+ hJoin(versions.map(function (version) {
+ var distTag = distTagged[version]
+ return [h('b', version), distTag ? [' (', h('i', distTag), ')'] : '']
+ }), ', ')
+ ),
+ pkgDescription ? h('div', h('q', self.linkify(pkgDescription))) : '',
+ prevLinks.length ? h('div', 'previous: ', prevLinks) : '',
+ pkgReadme && pkgReadme !== singleReadme ?
+ h('blockquote', {innerHTML: render.markdown(pkgReadme)}) : '',
+ versions.map(function (version, i) {
+ var release = pkg.versions[version] || {}
+ var license = u.ifString(release.license)
+ var author = release.author
+ var description = u.ifString(release.description)
+ var readme = asNpmReadme(release.readme)
+ var keywords = u.toArray(release.keywords).map(u.ifString)
+ var dist = release.dist || {}
+ var size = u.ifNumber(dist.size)
+ return [
+ h > 0 ? h('br') : '',
+ version !== singleVersion ? h('div', 'version: ', version) : '',
+ author ? h('div', 'author: ', render.npmAuthorLink(author)) : '',
+ license ? h('div', 'license: ', h('code', license)) : '',
+ keywords.length ? h('div', 'keywords: ', keywords.join(', ')) : '',
+ size ? h('div', 'size: ', render.formatSize(size)) : '',
+ description && description !== pkgDescription ?
+ h('div', h('q', self.linkify(description))) : '',
+ readme ? h('blockquote', {innerHTML: render.markdown(readme)}) : ''
+ ]
+ })
+ ], cb)
+ })
+}
+
+RenderMsg.prototype.npmPublishTitle = function (cb) {
+ var pkg = this.c.meta || {}
+ var name = pkg.name || pkg._id || '?'
+
+ var taggedVersions = {}
+ for (var version in pkg.versions || {})
+ taggedVersions[version] = []
+
+ var distTags = pkg['dist-tags'] || {}
+ for (var distTag in distTags) {
+ if (distTag === 'latest') continue
+ var version = distTags[distTag] || '?'
+ var tags = taggedVersions[version] || (taggedVersions[version] = [])
+ tags.push(distTag)
+ }
+
+ cb(null, name + '@' + Object.keys(taggedVersions).map(function (version) {
+ var tags = taggedVersions[version]
+ return (tags.length ? tags.join(',') + ':' : '') + version
+ }).join(','))
+}