From b2c03954f07ab2baee3e4a7390bb6bcffe2c6df3 Mon Sep 17 00:00:00 2001 From: Ev Bogue Date: Sat, 24 Jun 2017 16:44:46 -0400 Subject: [PATCH] Merge: add thread links to posts that have a root And don't render them when rendering the thread --- index.js | 2 +- render.js | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 6db10b7..f59e668 100644 --- a/index.js +++ b/index.js @@ -210,7 +210,7 @@ exports.init = function (sbot, config) { pull.values(logs), paramap(addAuthorAbout, 8), paramap(addVoteMessage, 8), - pull(renderThread(defaultOpts, + pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)), wrapPage('#' + channelId)), toPull(res, function (err) { diff --git a/render.js b/render.js index 353f087..c4291f5 100644 --- a/render.js +++ b/render.js @@ -75,7 +75,7 @@ function escape(str) { function formatMsgs(id, ext, opts) { switch (ext || "html") { case "html": - return pull(renderThread(opts), wrapPage(id)); + return pull(renderThread(opts, id, ''), wrapPage(id)); case "js": return pull(renderThread(opts), wrapJSEmbed(opts)); case "json": @@ -110,7 +110,7 @@ function renderAbout(opts, about, showAllHTML = "") { (about.description != undefined ? marked(about.description, opts.marked) : ''); return pull( - pull.map(renderMsg.bind(this, opts)), + pull.map(renderMsg.bind(this, opts, '')), wrap(toolTipTop() + '
' + h('article', h('header', @@ -126,9 +126,9 @@ function renderAbout(opts, about, showAllHTML = "") { ); } -function renderThread(opts, showAllHTML = "") { +function renderThread(opts, id, showAllHTML = "") { return pull( - pull.map(renderMsg.bind(this, opts)), + pull.map(renderMsg.bind(this, opts, id)), wrap(toolTipTop() + '
', showAllHTML + '
' + callToAction()) ); @@ -311,7 +311,7 @@ function docWrite(str) { return "document.write(" + JSON.stringify(str) + ")\n"; } -function renderMsg(opts, msg) { +function renderMsg(opts, id, msg) { var c = msg.value.content || {}; var name = encodeURIComponent(msg.key); return h('article#' + name, @@ -325,7 +325,7 @@ function renderMsg(opts, msg) { { href: opts.base + escape(msg.value.author) }, msg.author.name), msgTimestamp(msg, opts.base + name)))), - render(opts, c)).outerHTML; + render(opts, id, c)).outerHTML; } function msgTimestamp(msg, link) { @@ -343,7 +343,7 @@ function formatDate(date) { return htime(date); } -function render(opts, c) { +function render(opts, id, c) { var base = opts.base; if (c.type === "post") { var channel = c.channel @@ -352,7 +352,7 @@ function render(opts, c) { { href: base + 'channel/' + c.channel }, '#' + c.channel)) : ""; - return [channel, renderPost(opts, c)]; + return [channel, renderPost(opts, id, c)]; } else if (c.type == "vote" && c.vote.expression == "Dig") { var channel = c.channel ? [' in ', @@ -399,7 +399,7 @@ function render(opts, c) { return [h('span.status', "Created a git issue" + (c.repoName != undefined ? " in repo " + c.repoName : ""), - renderPost(opts, c))]; + renderPost(opts, id, c))]; } else if (c.type == "git-repo") { return h('span.status', @@ -435,7 +435,7 @@ function render(opts, c) { else return renderDefault(c); } -function renderPost(opts, c) { +function renderPost(opts, id, c) { opts.mentions = {}; if (Array.isArray(c.mentions)) { c.mentions.forEach(function (link) { @@ -444,7 +444,12 @@ function renderPost(opts, c) { }); } var s = h('section'); - s.innerHTML = marked(String(c.text), opts.marked); + var content = ''; + if (c.root && c.root != id) + content += 'Re: ' + h('a', + { href: '/' + encodeURIComponent(c.root) }, + c.root.substring(0, 10)).outerHTML + '
'; + s.innerHTML = content + marked(String(c.text), opts.marked); return s; }