Files: c26a377b747816479b1dc93f160726ef84bf6205 / app / page / blogShow.js
1986 bytesRaw
1 | const nest = require('depnest') |
2 | const { h, computed, when } = require('mutant') |
3 | const { title: getTitle } = require('markdown-summary') |
4 | const last = require('lodash/last') |
5 | const get = require('lodash/get') |
6 | |
7 | exports.gives = nest('app.page.blogShow') |
8 | |
9 | exports.needs = nest({ |
10 | 'about.html.avatar': 'first', |
11 | 'about.obs.name': 'first', |
12 | 'app.html.comments': 'first', |
13 | 'app.html.context': 'first', |
14 | 'message.html.channel': 'first', |
15 | 'message.html.compose': 'first', |
16 | 'message.html.markdown': 'first', |
17 | 'message.html.timeago': 'first', |
18 | }) |
19 | |
20 | exports.create = (api) => { |
21 | return nest('app.page.blogShow', blogShow) |
22 | |
23 | function blogShow (blogMsg) { |
24 | // blogMsg = a thread (message, may be decorated with replies) |
25 | |
26 | const { author, content } = blogMsg.value |
27 | |
28 | const blog = content.text |
29 | const title = api.message.html.markdown(content.title || getTitle(blog)) |
30 | |
31 | const comments = api.app.html.comments(blogMsg.key) |
32 | |
33 | const meta = { |
34 | type: 'post', |
35 | root: blogMsg.key, |
36 | // branch: get(last(blogMsg.replies), 'key'), // TODO - change to match new comments logic |
37 | // >> lastId? CHECK THIS LOGIC |
38 | channel: content.channel |
39 | } |
40 | |
41 | const { timeago, channel, markdown, compose } = api.message.html |
42 | |
43 | return h('Page -blogShow', [ |
44 | api.app.html.context({ page: 'discover' }), // HACK to highlight discover |
45 | h('div.content', [ |
46 | h('header', [ |
47 | h('div.blog', [ |
48 | h('h1', title), |
49 | timeago(blogMsg), |
50 | channel(blogMsg) |
51 | ]), |
52 | h('div.author', [ |
53 | h('div.leftCol', api.about.html.avatar(author, 'medium')), |
54 | h('div.rightCol', [ |
55 | h('div.name', api.about.obs.name(author)), |
56 | h('Button', 'Follow') |
57 | ]), |
58 | ]) |
59 | ]), |
60 | h('div.break', h('hr')), |
61 | h('section.blog', markdown(blog)), |
62 | compose({ meta, shrink: true }), |
63 | comments, |
64 | compose({ meta, shrink: false }) |
65 | ]), |
66 | ]) |
67 | } |
68 | } |
69 | |
70 |
Built with git-ssb-web