From e525414d1f2edc4363b7e94b7b4da1252e853026 Mon Sep 17 00:00:00 2001 From: Anders Rune Jensen Date: Wed, 25 Apr 2018 15:57:30 +0200 Subject: [PATCH] Render blog posts --- index.js | 20 ++++++++++++++++++-- render.js | 14 ++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6e30497..db9e947 100644 --- a/index.js +++ b/index.js @@ -133,6 +133,7 @@ exports.init = function (sbot, config) { pull( pull.values(logs), paramap(addAuthorAbout, 8), + paramap(addBlog, 8), paramap(addFollowAbout, 8), paramap(addVoteMessage, 8), paramap(addGitLinks, 8), @@ -232,6 +233,7 @@ exports.init = function (sbot, config) { pull( pull.values(logs), paramap(addAuthorAbout, 8), + paramap(addBlog, 8), paramap(addFollowAbout, 8), paramap(addVoteMessage, 8), paramap(addGitLinks, 8), @@ -260,9 +262,9 @@ exports.init = function (sbot, config) { pull( pull.values(logs), paramap(addAuthorAbout, 8), + paramap(addBlog, 8), paramap(addVoteMessage, 8), - pull(renderThread(defaultOpts, '', - renderShowAll(showAll, req.url)), + pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)), wrapPage('#' + channelId)), toPull(res, function (err) { if (err) console.error('[viewer]', err) @@ -316,6 +318,7 @@ exports.init = function (sbot, config) { pull( pull.values(sort(links)), paramap(addAuthorAbout, 8), + paramap(addBlog, 8), format, toPull(res, function (err) { if (err) console.error('[viewer]', err) @@ -363,6 +366,19 @@ exports.init = function (sbot, config) { cb(null, msg) } + function addBlog(msg, cb) { + if (msg.value && msg.value.content.type == "blog") { + pull( + sbot.blobs.get(msg.value.content.blog), + pull.collect(function(err, blob) { + msg.value.content.blogContent = blob + cb(null, msg) + }) + ) + } else + cb(null, msg) + } + function addAuthorAbout(msg, cb) { getAbout(msg.value.author, function (err, about) { if (err) return cb(err) diff --git a/render.js b/render.js index 780ae4f..3ada05e 100644 --- a/render.js +++ b/render.js @@ -504,6 +504,20 @@ function render(opts, id, c) { h('a', { href: base + 'channel/' + c.channel }, '#' + c.channel)) + else if (c.type == "blog") { + //%RTXvyZ2fZWwTyWdlk0lYGk5sKw5Irj+Wk4QwxyOVG5g=.sha256 + var channel = c.channel + ? h('div.top-right', + h('a', + { href: base + 'channel/' + c.channel }, + '#' + c.channel)) + : ""; + + var s = h('section'); + s.innerHTML = marked(String(c.blogContent), opts.marked) + + return [channel, h('h2', c.title), s]; + } else return renderDefault(c); }