Commit b2c03954f07ab2baee3e4a7390bb6bcffe2c6df3
Merge: add thread links to posts that have a root
And don't render them when rendering the threadEv Bogue authored on 6/24/2017, 8:44:46 PM
Anders Rune Jensen committed on 6/25/2017, 8:18:50 PM
Parent: 336a39d74fbef28c1b1f707863fb872bcc447a6c
Files changed
index.js | changed |
render.js | changed |
index.js | ||
---|---|---|
@@ -209,9 +209,9 @@ | ||
209 | 209 | pull( |
210 | 210 | pull.values(logs), |
211 | 211 | paramap(addAuthorAbout, 8), |
212 | 212 | paramap(addVoteMessage, 8), |
213 | - pull(renderThread(defaultOpts, | |
213 | + pull(renderThread(defaultOpts, '', | |
214 | 214 | renderShowAll(showAll, req.url)), |
215 | 215 | wrapPage('#' + channelId)), |
216 | 216 | toPull(res, function (err) { |
217 | 217 | if (err) console.error('[viewer]', err) |
render.js | ||
---|---|---|
@@ -74,9 +74,9 @@ | ||
74 | 74 | |
75 | 75 | function formatMsgs(id, ext, opts) { |
76 | 76 | switch (ext || "html") { |
77 | 77 | case "html": |
78 | - return pull(renderThread(opts), wrapPage(id)); | |
78 | + return pull(renderThread(opts, id, ''), wrapPage(id)); | |
79 | 79 | case "js": |
80 | 80 | return pull(renderThread(opts), wrapJSEmbed(opts)); |
81 | 81 | case "json": |
82 | 82 | return wrapJSON(); |
@@ -109,9 +109,9 @@ | ||
109 | 109 | figCaption.innerHTML = 'Feed of ' + about.name + '<br>' + |
110 | 110 | (about.description != undefined ? |
111 | 111 | marked(about.description, opts.marked) : ''); |
112 | 112 | return pull( |
113 | - pull.map(renderMsg.bind(this, opts)), | |
113 | + pull.map(renderMsg.bind(this, opts, '')), | |
114 | 114 | wrap(toolTipTop() + '<main>' + |
115 | 115 | h('article', |
116 | 116 | h('header', |
117 | 117 | h('figure', |
@@ -125,11 +125,11 @@ | ||
125 | 125 | showAllHTML + '</main>' + callToAction()) |
126 | 126 | ); |
127 | 127 | } |
128 | 128 | |
129 | -function renderThread(opts, showAllHTML = "") { | |
129 | +function renderThread(opts, id, showAllHTML = "") { | |
130 | 130 | return pull( |
131 | - pull.map(renderMsg.bind(this, opts)), | |
131 | + pull.map(renderMsg.bind(this, opts, id)), | |
132 | 132 | wrap(toolTipTop() + '<main>', |
133 | 133 | showAllHTML + '</main>' + callToAction()) |
134 | 134 | ); |
135 | 135 | } |
@@ -310,9 +310,9 @@ | ||
310 | 310 | function docWrite(str) { |
311 | 311 | return "document.write(" + JSON.stringify(str) + ")\n"; |
312 | 312 | } |
313 | 313 | |
314 | -function renderMsg(opts, msg) { | |
314 | +function renderMsg(opts, id, msg) { | |
315 | 315 | var c = msg.value.content || {}; |
316 | 316 | var name = encodeURIComponent(msg.key); |
317 | 317 | return h('article#' + name, |
318 | 318 | h('header', |
@@ -324,9 +324,9 @@ | ||
324 | 324 | h('a.ssb-avatar-name', |
325 | 325 | { href: opts.base + escape(msg.value.author) }, |
326 | 326 | msg.author.name), |
327 | 327 | msgTimestamp(msg, opts.base + name)))), |
328 | - render(opts, c)).outerHTML; | |
328 | + render(opts, id, c)).outerHTML; | |
329 | 329 | } |
330 | 330 | |
331 | 331 | function msgTimestamp(msg, link) { |
332 | 332 | var date = new Date(msg.value.timestamp); |
@@ -342,18 +342,18 @@ | ||
342 | 342 | function formatDate(date) { |
343 | 343 | return htime(date); |
344 | 344 | } |
345 | 345 | |
346 | -function render(opts, c) { | |
346 | +function render(opts, id, c) { | |
347 | 347 | var base = opts.base; |
348 | 348 | if (c.type === "post") { |
349 | 349 | var channel = c.channel |
350 | 350 | ? h('div.top-right', |
351 | 351 | h('a', |
352 | 352 | { href: base + 'channel/' + c.channel }, |
353 | 353 | '#' + c.channel)) |
354 | 354 | : ""; |
355 | - return [channel, renderPost(opts, c)]; | |
355 | + return [channel, renderPost(opts, id, c)]; | |
356 | 356 | } else if (c.type == "vote" && c.vote.expression == "Dig") { |
357 | 357 | var channel = c.channel |
358 | 358 | ? [' in ', |
359 | 359 | h('a', |
@@ -398,9 +398,9 @@ | ||
398 | 398 | else if (c.type == "issue") { |
399 | 399 | return [h('span.status', |
400 | 400 | "Created a git issue" + |
401 | 401 | (c.repoName != undefined ? " in repo " + c.repoName : ""), |
402 | - renderPost(opts, c))]; | |
402 | + renderPost(opts, id, c))]; | |
403 | 403 | } |
404 | 404 | else if (c.type == "git-repo") { |
405 | 405 | return h('span.status', |
406 | 406 | "Created a git repo " + c.name); |
@@ -434,18 +434,23 @@ | ||
434 | 434 | '#' + c.channel)) |
435 | 435 | else return renderDefault(c); |
436 | 436 | } |
437 | 437 | |
438 | -function renderPost(opts, c) { | |
438 | +function renderPost(opts, id, c) { | |
439 | 439 | opts.mentions = {}; |
440 | 440 | if (Array.isArray(c.mentions)) { |
441 | 441 | c.mentions.forEach(function (link) { |
442 | 442 | if (link && link.name && link.link) |
443 | 443 | opts.mentions[link.name] = link.link; |
444 | 444 | }); |
445 | 445 | } |
446 | 446 | var s = h('section'); |
447 | - s.innerHTML = marked(String(c.text), opts.marked); | |
447 | + var content = ''; | |
448 | + if (c.root && c.root != id) | |
449 | + content += 'Re: ' + h('a', | |
450 | + { href: '/' + encodeURIComponent(c.root) }, | |
451 | + c.root.substring(0, 10)).outerHTML + '<br>'; | |
452 | + s.innerHTML = content + marked(String(c.text), opts.marked); | |
448 | 453 | return s; |
449 | 454 | } |
450 | 455 | |
451 | 456 | function renderDefault(c) { |
Built with git-ssb-web