git ssb

10+

Matt McKegg / patchwork



Tree: 35ca2d9446f15b90de0ece30391868c2761a1247

Files: 35ca2d9446f15b90de0ece30391868c2761a1247 / plugs / message / html / render / blog.js

2449 bytesRaw
1const nest = require('depnest')
2const isBlog = require('scuttle-blog/isBlog')
3const { h, Value, computed, when, resolve } = require('mutant')
4
5
6exports.gives = nest('message.html', {
7 canRender: true,
8 render: true
9})
10
11exports.needs = nest({
12 'about.obs.color': 'first',
13 'app.navigate': 'first',
14 'blob.sync.url': 'first',
15 'message.html.decorate': 'reduce',
16 'message.html.layout': 'first',
17 'message.html.markdown': 'first',
18 'sbot.obs.connection': 'first'
19})
20
21exports.create = function (api) {
22
23 return nest('message.html', {
24 render: blogRenderer,
25 canRender
26 })
27
28 return nest('message.html.render', blogRenderer)
29
30 function blogRenderer (msg, opts) {
31 if (!canRender(msg)) return
32
33 var content = null
34
35 // only render the message body if it is available (only in thread view), otherwise show card
36 if (msg.body) {
37 content = h('BlogFull.Markdown', [
38 h('h1', msg.value.content.title),
39 api.message.html.markdown(msg.body)
40 ])
41 } else {
42 content = BlogCard({
43 blog: msg.value.content,
44 onClick: () => api.app.navigate(msg.key),
45 color: api.about.obs.color,
46 blobUrl: api.blob.sync.url
47 })
48 }
49
50 const element = api.message.html.layout(msg, Object.assign({}, {
51 content,
52 layout: 'default'
53 }, opts))
54
55 return api.message.html.decorate(element, { msg })
56 }
57}
58
59function BlogCard ({ blog, blobUrl, onClick, color }) {
60 const thumbnail = when(blog.thumbnail,
61 h('Thumbnail', {
62 style: {
63 'background-image': `url("${blobUrl(resolve(blog.thumbnail))}")`,
64 'background-position': 'center',
65 'background-size': 'cover'
66 }
67 }),
68 h('Thumbnail -empty', {
69 style: { 'background-color': color(blog.title) }
70 }, [
71 h('i.fa.fa-file-text-o')
72 ])
73 )
74
75 var b = h('BlogCard', { 'ev-click': onClick }, [
76 // h('div.context', [
77 // api.about.html.avatar(author, 'tiny'),
78 // h('div.name', api.about.obs.name(author)),
79 // api.message.html.timeago(blog)
80 // ]),
81 h('div.content', [
82 thumbnail,
83 h('div.text.Markdown', [
84 h('h1', blog.title),
85 // when(blog.channel, api.message.html.channel(blog.channel))
86 h('div.summary', blog.summary),
87 h('div.read', 'Read blog')
88 ])
89 ])
90 ])
91
92 return b
93}
94
95function canRender (msg) {
96 return msg.value && msg.value.content && msg.value.content.type === 'blog' && isBlog(msg)
97}

Built with git-ssb-web