Commit 100dd561a4f0904611f178ea030022058e906aee
Merge pull request #767 from ssbc/blogs-patchcore
suggestions for #763 add blog renderingMatt McKegg authored on 4/11/2018, 3:48:05 AM
GitHub committed on 4/11/2018, 3:48:05 AM
Parent: 8b5a53ad4e12f5f4957f2a1ed938d0179a3ab04a
Parent: 909800fff77d989c6fd603989b6c73570271320b
Files changed
modules/feed/html/rollup.js | changed |
package-lock.json | changed |
package.json | changed |
plugs/message/html/render/blog.js | changed |
modules/feed/html/rollup.js | ||
---|---|---|
@@ -243,9 +243,8 @@ | ||
243 | 243 | |
244 | 244 | var renderedMessage = api.message.html.render(item, { |
245 | 245 | compact: compactFilter(item), |
246 | 246 | includeForks: false, // this is a root message, so forks are already displayed as replies |
247 | - inRollup: true, | |
248 | 247 | priority: getPriority(item) |
249 | 248 | }) |
250 | 249 | |
251 | 250 | unreadIds.delete(item.key) |
package-lock.json | ||
---|---|---|
The diff is too large to show. Use a local git client to view these changes. Old file size: 291054 bytes New file size: 293146 bytes |
package.json | ||
---|---|---|
@@ -42,9 +42,9 @@ | ||
42 | 42 | "mutant": "^3.21.2", |
43 | 43 | "mutant-pull-reduce": "^1.1.0", |
44 | 44 | "obv": "0.0.1", |
45 | 45 | "patch-settings": "~1.1.0", |
46 | - "patchcore": "^1.23.6", | |
46 | + "patchcore": "~1.24.0", | |
47 | 47 | "pull-abortable": "^4.1.0", |
48 | 48 | "pull-cat": "^1.1.11", |
49 | 49 | "pull-defer": "^0.2.2", |
50 | 50 | "pull-file": "~1.0.0", |
plugs/message/html/render/blog.js | ||
---|---|---|
@@ -1,11 +1,14 @@ | ||
1 | 1 | const nest = require('depnest') |
2 | -const Blog = require('scuttle-blog') | |
3 | 2 | const isBlog = require('scuttle-blog/isBlog') |
4 | 3 | const { h, Value, computed, when, resolve } = require('mutant') |
5 | 4 | |
6 | -exports.gives = nest('message.html.render') | |
7 | 5 | |
6 | +exports.gives = nest('message.html', { | |
7 | + canRender: true, | |
8 | + render: true | |
9 | +}) | |
10 | + | |
8 | 11 | exports.needs = nest({ |
9 | 12 | 'about.obs.color': 'first', |
10 | 13 | 'app.navigate': 'first', |
11 | 14 | 'blob.sync.url': 'first', |
@@ -15,23 +18,36 @@ | ||
15 | 18 | 'sbot.obs.connection': 'first' |
16 | 19 | }) |
17 | 20 | |
18 | 21 | exports.create = function (api) { |
22 | + | |
23 | + return nest('message.html', { | |
24 | + render: blogRenderer, | |
25 | + canRender | |
26 | + }) | |
27 | + | |
19 | 28 | return nest('message.html.render', blogRenderer) |
20 | 29 | |
21 | 30 | function blogRenderer (msg, opts) { |
22 | - if (!isBlog(msg)) return | |
31 | + if (!canRender(msg)) return | |
23 | 32 | |
24 | - var blog = Blog(api.sbot.obs.connection).obs.get(msg) | |
25 | - var content = opts.inRollup | |
26 | - ? BlogCard({ | |
27 | - blog, | |
33 | + var content = null | |
34 | + // show a card (if there's no body loaded) or the full blog (if the blog body is loaded) | |
35 | + // msg is decorated with a `body` attribute when loaded using feed.obs.thread from patchcore | |
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, | |
28 | 44 | onClick: () => api.app.navigate(msg.key), |
29 | 45 | color: api.about.obs.color, |
30 | 46 | blobUrl: api.blob.sync.url |
31 | 47 | }) |
32 | - : BlogFull(blog, api.message.html.markdown) | |
33 | - | |
48 | + } | |
49 | + | |
34 | 50 | const element = api.message.html.layout(msg, Object.assign({}, { |
35 | 51 | content, |
36 | 52 | layout: 'default' |
37 | 53 | }, opts)) |
@@ -39,25 +55,8 @@ | ||
39 | 55 | return api.message.html.decorate(element, { msg }) |
40 | 56 | } |
41 | 57 | } |
42 | 58 | |
43 | -function BlogFull (blog, renderMd) { | |
44 | - return computed(blog.body, body => { | |
45 | - if (body && body.length) { | |
46 | - return h('BlogFull.Markdown', [ | |
47 | - h('h1', blog.title), | |
48 | - renderMd(body) | |
49 | - ]) | |
50 | - } | |
51 | - | |
52 | - return h('BlogFull.Markdown', [ | |
53 | - h('h1', blog.title), | |
54 | - blog.summary, | |
55 | - h('p', 'loading...') | |
56 | - ]) | |
57 | - }) | |
58 | -} | |
59 | - | |
60 | 59 | function BlogCard ({ blog, blobUrl, onClick, color }) { |
61 | 60 | const thumbnail = when(blog.thumbnail, |
62 | 61 | h('Thumbnail', { |
63 | 62 | style: { |
@@ -91,4 +90,8 @@ | ||
91 | 90 | ]) |
92 | 91 | |
93 | 92 | return b |
94 | 93 | } |
94 | + | |
95 | +function canRender (msg) { | |
96 | + if (isBlog(msg)) return true | |
97 | +} |
Built with git-ssb-web