Commit cab781470c10d358f770475c7b25d87e29f614bb
Render post edits and diffs
cel committed on 7/26/2018, 10:03:40 PMParent: 09f70e5f94777bbe5a18d2980ca221360642a970
Files changed
lib/render-msg.js | changed |
lib/serve.js | changed |
lib/util.js | changed |
lib/render-msg.js | |||
---|---|---|---|
@@ -157,8 +157,11 @@ | |||
157 | 157 … | h('form', {method: 'post', action: ''}, | |
158 | 158 … | this.msg.rel ? [this.msg.rel, ' '] : '', | |
159 | 159 … | this.opts.withGt && this.msg.timestamp ? [ | |
160 | 160 … | h('a', {href: '?gt=' + this.msg.timestamp}, '↓'), ' '] : '', | |
161 … | + this.c.type === 'edit' ? [ | ||
162 … | + h('a', {href: this.toUrl('/edit-diff/' + encodeURIComponent(this.msg.key)), | ||
163 … | + title: 'view post edit diff'}, 'diff'), ' '] : '', | ||
161 | 164 … | this.c.type === 'gathering' ? [ | |
162 | 165 … | h('a', {href: this.render.toUrl('/about/' + encodeURIComponent(this.msg.key))}, 'about'), ' '] : '', | |
163 | 166 … | /^(ssb_)?chess_/.test(this.c.type) ? [ | |
164 | 167 … | h('a', {href: this.toUrl(this.msg.key) + '?full', | |
@@ -299,8 +302,9 @@ | |||
299 | 302 … | case 'position': if (this.c.version === 'v1') return this.pollPosition(cb) | |
300 | 303 … | case 'scat_message': return this.scat(cb) | |
301 | 304 … | case 'share': return this.share(cb) | |
302 | 305 … | case 'tag': return this.tag(cb) | |
306 … | + case 'edit': return this.edit(cb) | ||
303 | 307 … | default: return this.object(cb) | |
304 | 308 … | } | |
305 | 309 … | } | |
306 | 310 … | ||
@@ -345,8 +349,35 @@ | |||
345 | 349 … | ), cb) | |
346 | 350 … | }) | |
347 | 351 … | } | |
348 | 352 … | ||
353 … | +RenderMsg.prototype.edit = function (cb) { | ||
354 … | + var self = this | ||
355 … | + var done = multicb({pluck: 1, spread: true}) | ||
356 … | + if (self.c.root === self.c.branch) done()() | ||
357 … | + else self.link(self.c.root, done()) | ||
358 … | + self.links(self.c.branch, done()) | ||
359 … | + self.links(self.c.fork, done()) | ||
360 … | + self.link(self.c.original, done()) | ||
361 … | + if (self.c.updated === self.c.branch) done()() | ||
362 … | + else self.link(self.c.updated, done()) | ||
363 … | + done(function (err, rootLink, branchLinks, forkLinks, originalLink, updatedLink) { | ||
364 … | + if (err) return self.wrap(u.renderError(err), cb) | ||
365 … | + self.wrap(h('div.ssb-post', | ||
366 … | + h('div', 'edit ', originalLink || ''), | ||
367 … | + rootLink ? h('div', h('small', h('span.symbol', '→'), ' ', rootLink)) : '', | ||
368 … | + updatedLink ? h('div', h('small', h('span.symbol', ' ↳'), ' ', updatedLink)) : '', | ||
369 … | + branchLinks.map(function (a, i) { | ||
370 … | + return h('div', h('small', h('span.symbol', ' ↳'), ' ', a)) | ||
371 … | + }), | ||
372 … | + forkLinks.map(function (a, i) { | ||
373 … | + return h('div', h('small', h('span.symbol', '⑂'), ' ', a)) | ||
374 … | + }), | ||
375 … | + h('blockquote.ssb-post-text', {innerHTML: self.markdown()}) | ||
376 … | + ), cb) | ||
377 … | + }) | ||
378 … | +} | ||
379 … | + | ||
349 | 380 … | RenderMsg.prototype.vote = function (cb) { | |
350 | 381 … | var self = this | |
351 | 382 … | var v = self.c.vote || self.c.like || {} | |
352 | 383 … | self.link(v, function (err, a) { | |
@@ -612,9 +643,9 @@ | |||
612 | 643 … | if (rating > 5) rating = 5 | |
613 | 644 … | var el = h('div', {title: text}) | |
614 | 645 … | for (var i = 0; i < rating; i++) { | |
615 | 646 … | el.appendChild(h('span', | |
616 | - {innerHTML: unwrapP(this.render.markdown(type) + ' ')} | ||
647 … | + {innerHTML: u.unwrapP(this.render.markdown(type) + ' ')} | ||
617 | 648 … | )) | |
618 | 649 … | } | |
619 | 650 … | return el | |
620 | 651 … | } | |
@@ -1009,9 +1040,9 @@ | |||
1009 | 1040 … | currency[0] === '#' | |
1010 | 1041 … | ? h('a', {href: self.toUrl(currency)}, currency) | |
1011 | 1042 … | : h('ins', currency), | |
1012 | 1043 … | self.c.memo ? [' for ', | |
1013 | - h('q', {innerHTML: unwrapP(self.render.markdown(self.c.memo))}) | ||
1044 … | + h('q', {innerHTML: u.unwrapP(self.render.markdown(self.c.memo))}) | ||
1014 | 1045 … | ] : '' | |
1015 | 1046 … | ], cb) | |
1016 | 1047 … | }) | |
1017 | 1048 … | } | |
@@ -1023,16 +1054,10 @@ | |||
1023 | 1054 … | RenderMsg.prototype.gathering = function (cb) { | |
1024 | 1055 … | this.wrapMini('gathering', cb) | |
1025 | 1056 … | } | |
1026 | 1057 … | ||
1027 | -function unwrapP(html) { | ||
1028 | - return String(html).replace(/^<p>(.*)<\/p>\s*$/, function ($0, $1) { | ||
1029 | - return $1 | ||
1030 | - }) | ||
1031 | -} | ||
1032 | - | ||
1033 | 1058 … | RenderMsg.prototype.micro = function (cb) { | |
1034 | - var el = h('span', {innerHTML: unwrapP(this.markdown())}) | ||
1059 … | + var el = h('span', {innerHTML: u.unwrapP(this.markdown())}) | ||
1035 | 1060 … | this.wrapMini(el, cb) | |
1036 | 1061 … | } | |
1037 | 1062 … | ||
1038 | 1063 … | function hJoin(els, seperator, lastSeparator) { | |
@@ -1086,9 +1111,9 @@ | |||
1086 | 1111 … | }), ', ') | |
1087 | 1112 … | ), | |
1088 | 1113 … | pkgDescription ? h('div', | |
1089 | 1114 … | // TODO: make mdInline use custom emojis | |
1090 | - h('q', {innerHTML: unwrapP(render.markdown(pkgDescription))})) : '', | ||
1115 … | + h('q', {innerHTML: u.unwrapP(render.markdown(pkgDescription))})) : '', | ||
1091 | 1116 … | prevLinks.length ? h('div', 'previous: ', prevLinks) : '', | |
1092 | 1117 … | pkgReadme && pkgReadme !== singleReadme ? | |
1093 | 1118 … | h('blockquote', {innerHTML: render.markdown(pkgReadme)}) : '', | |
1094 | 1119 … | versions.map(function (version, i) { | |
@@ -1747,10 +1772,10 @@ | |||
1747 | 1772 … | var closeDate = new Date(self.c.closesAt) | |
1748 | 1773 … | var details = self.c.pollDetails || self.c.details || {} | |
1749 | 1774 … | var choices = u.toArray(details.choices) | |
1750 | 1775 … | return self.wrap(h('div', | |
1751 | - h('h3', {innerHTML: unwrapP(self.render.markdown(self.c.title))}), | ||
1752 | - h('div', {innerHTML: unwrapP(self.render.markdown(self.c.body, self.c.mentions))}), | ||
1776 … | + h('h3', {innerHTML: u.unwrapP(self.render.markdown(self.c.title))}), | ||
1777 … | + h('div', {innerHTML: u.unwrapP(self.render.markdown(self.c.body, self.c.mentions))}), | ||
1753 | 1778 … | h('p', 'closes at: ', h('span', { | |
1754 | 1779 … | title: closeDate.toLocaleString() | |
1755 | 1780 … | }, closeDate.toString())), | |
1756 | 1781 … | details.type === 'chooseOne' ? h('form', {method: 'post', action: ''}, |
lib/serve.js | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 103688 bytes New file size: 106158 bytes |
lib/util.js | ||
---|---|---|
@@ -225,4 +225,11 @@ | ||
225 | 225 … | |
226 | 226 … | u.token = function () { |
227 | 227 … | return '__' + Math.random().toString(36).substr(2) + '__' |
228 | 228 … | } |
229 … | + | |
230 … | +u.unwrapP = function(html) { | |
231 … | + return String(html).replace(/^<p>(.*)<\/p>\s*$/, function ($0, $1) { | |
232 … | + return $1 | |
233 … | + }) | |
234 … | +} | |
235 … | + |
Built with git-ssb-web