From 678bce09b58899d8689acf40946b9985db7a9ada Mon Sep 17 00:00:00 2001 From: cel Date: Fri, 8 Dec 2017 12:28:31 -0800 Subject: Render blog messages --- lib/render-msg.js | 23 +++++++++++++++++++++++ lib/serve.js | 26 ++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'lib') diff --git a/lib/render-msg.js b/lib/render-msg.js index 51db2a7..7d34fc3 100644 --- a/lib/render-msg.js +++ b/lib/render-msg.js @@ -275,6 +275,7 @@ RenderMsg.prototype.message = function (cb) { case 'macaco_maluco-sombrio-wall': return this.sombrioWall(cb) case 'macaco_maluco-sombrio-tombstone': return this.sombrioTombstone(cb) case 'macaco_maluco-sombrio-score': return this.sombrioScore(cb) + case 'blog': return this.blog(cb) default: return this.object(cb) } } @@ -1414,3 +1415,25 @@ RenderMsg.prototype.sombrioScore = function (cb) { h('ins', self.c.score) ), cb) } + +RenderMsg.prototype.blog = function (cb) { + var self = this + var blogId = u.linkDest(self.c.blog) + var imgId = u.linkDest(self.c.thumbnail) + var imgLink = imgId ? u.toLinkArray(self.c.mentions).filter(function (link) { + return link.link === imgId + })[0] || u.toLink(self.c.thumbnail) : null + self.wrapMini(h('table', h('tr', + h('td', + imgId ? h('img', { + src: self.render.imageUrl(imgId), + alt: (imgLink.name || '') + + (imgLink.size != null ? ' (' + self.render.formatSize(imgLink.size) + ')' : ''), + width: 180, + }) : 'blog'), + h('td', + blogId ? h('h3', h('a', {href: self.render.toUrl('/markdown/' + blogId)}, + self.c.title || self.msg.key)) : '', + self.c.summary || '') + )), cb) +} diff --git a/lib/serve.js b/lib/serve.js index c100f40..c858a1b 100644 --- a/lib/serve.js +++ b/lib/serve.js @@ -326,6 +326,7 @@ Serve.prototype.path = function (url) { case '/npm': return this.npm(m[2]) case '/npm-prebuilds': return this.npmPrebuilds(m[2]) case '/npm-readme': return this.npmReadme(m[2]) + case '/markdown': return this.markdown(m[2]) } return this.respond(404, 'Not found') } @@ -2143,6 +2144,31 @@ Serve.prototype.npmReadme = function (url) { ) } +Serve.prototype.markdown = function (url) { + var self = this + var id = decodeURIComponent(url.substr(1)) + var blobs = self.app.sbot.blobs + return pull( + ph('section', {}, [ + ph('h3', [ + ph('a', {href: '/links/' + id}, id.substr(0, 8) + '…') + ]), + u.readNext(function (cb) { + blobs.size(id, function (err, size) { + if (size == null) return cb(null, self.askWantBlobsForm([id])) + pull(blobs.get(id), pull.collect(function (err, chunks) { + if (err) return cb(null, ph('div', u.renderError(err).outerHTML)) + var text = Buffer.concat(chunks).toString() + cb(null, ph('blockquote', self.app.render.markdown(text))) + })) + }) + }) + ]), + self.wrapPage('markdown'), + self.respondSink(200) + ) +} + // wrap a binary source and render it or turn into an embed Serve.prototype.wrapBinary = function (opts) { var self = this -- cgit v1.2.3