From bd97292b635469091b048141038936cceb42ff7c Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 22 Nov 2018 12:19:23 -1000 Subject: Default render {name,link} more compactly --- lib/render-msg.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/render-msg.js') diff --git a/lib/render-msg.js b/lib/render-msg.js index dd35b06..78b3570 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -839,6 +839,11 @@ RenderMsg.prototype.object = function (cb) { done(cb) } +function linkName(link) { + if (link.link[0] === '@' && link.name[0] !== '@') return '@' + link.name + return link.name +} + RenderMsg.prototype.valueTable = function (val, depth, cb) { var isContent = depth === 1 var self = this @@ -846,11 +851,14 @@ RenderMsg.prototype.valueTable = function (val, depth, cb) { case 'object': if (val === null) return cb(), '' var done = multicb({pluck: 1, spread: true}) + var keys var el = Array.isArray(val) ? h('ul', val.map(function (item) { return h('li', self.valueTable(item, depth + 1, done())) })) - : h('table.ssb-object', Object.keys(val).map(function (key) { + : (keys = Object.keys(val)).sort().join() === 'link,name' && val.link && val.name + ? h('a', {href: self.toUrl(val.link)}, linkName(val)) + : h('table.ssb-object', keys.map(function (key) { if (key === 'text') { return h('tr', h('td', h('strong', 'text')), -- cgit v1.2.3