From ca9ab26ec6f4f060a9ef89bec77537aa46a99707 Mon Sep 17 00:00:00 2001 From: cel Date: Thu, 29 Aug 2019 13:10:59 -0700 Subject: [PATCH] Show content warnings --- index.js | 6 +++++- render.js | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 2aa5826..2f277fb 100644 --- a/index.js +++ b/index.js @@ -342,6 +342,7 @@ exports.init = function (sbot, config) { pull( pull.values(sort(links)), paramap(addAuthorAbout, 8), + paramap(addVoteMessage, 8), paramap(addBlog, 8), paramap(addGatheringAbout, 8), format, @@ -383,8 +384,11 @@ exports.init = function (sbot, config) { function addVoteMessage(msg, cb) { if (msg.value.content.type == 'vote' && msg.value.content.vote && msg.value.content.vote.link[0] == '%') getMsg(msg.value.content.vote.link, function (err, linkedMsg) { + var linkedC = linkedMsg && linkedMsg.value.content if (linkedMsg) - msg.value.content.vote.linkedText = linkedMsg.value.content.text + msg.value.content.vote.linkedText = + (typeof linkedC.contentWarning === 'string' ? '[CW: ' + linkedC.contentWarning + '] ' : '') + + linkedC.text cb(null, msg) }) else diff --git a/render.js b/render.js index 3ec8322..e5e8bfe 100644 --- a/render.js +++ b/render.js @@ -578,7 +578,14 @@ function renderPost(opts, id, c) { content += 'Re: ' + h('a', { href: '/' + encodeURIComponent(c.root) }, c.root.substring(0, 10)).outerHTML + '
' - s.innerHTML = content + marked(String(c.text), opts.marked) + var textHTML = marked(String(c.text), opts.marked) + if (typeof c.contentWarning === 'string') { + textHTML = h('details', + h('summary', 'Content warning: ' + c.contentWarning), + h('div', {innerHTML: textHTML}) + ).outerHTML + } + s.innerHTML = content + textHTML return s }