git ssb

10+

Matt McKegg / patchwork



Commit 100dd561a4f0904611f178ea030022058e906aee

Merge pull request #767 from ssbc/blogs-patchcore

suggestions for #763 add blog rendering
Matt 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.jschanged
package-lock.jsonchanged
package.jsonchanged
plugs/message/html/render/blog.jschanged
modules/feed/html/rollup.jsView
@@ -243,9 +243,8 @@
243243
244244 var renderedMessage = api.message.html.render(item, {
245245 compact: compactFilter(item),
246246 includeForks: false, // this is a root message, so forks are already displayed as replies
247- inRollup: true,
248247 priority: getPriority(item)
249248 })
250249
251250 unreadIds.delete(item.key)
package-lock.jsonView
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.jsonView
@@ -42,9 +42,9 @@
4242 "mutant": "^3.21.2",
4343 "mutant-pull-reduce": "^1.1.0",
4444 "obv": "0.0.1",
4545 "patch-settings": "~1.1.0",
46- "patchcore": "^1.23.6",
46+ "patchcore": "~1.24.0",
4747 "pull-abortable": "^4.1.0",
4848 "pull-cat": "^1.1.11",
4949 "pull-defer": "^0.2.2",
5050 "pull-file": "~1.0.0",
plugs/message/html/render/blog.jsView
@@ -1,11 +1,14 @@
11 const nest = require('depnest')
2-const Blog = require('scuttle-blog')
32 const isBlog = require('scuttle-blog/isBlog')
43 const { h, Value, computed, when, resolve } = require('mutant')
54
6-exports.gives = nest('message.html.render')
75
6+exports.gives = nest('message.html', {
7+ canRender: true,
8+ render: true
9+})
10+
811 exports.needs = nest({
912 'about.obs.color': 'first',
1013 'app.navigate': 'first',
1114 'blob.sync.url': 'first',
@@ -15,23 +18,36 @@
1518 'sbot.obs.connection': 'first'
1619 })
1720
1821 exports.create = function (api) {
22+
23+ return nest('message.html', {
24+ render: blogRenderer,
25+ canRender
26+ })
27+
1928 return nest('message.html.render', blogRenderer)
2029
2130 function blogRenderer (msg, opts) {
22- if (!isBlog(msg)) return
31+ if (!canRender(msg)) return
2332
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,
2844 onClick: () => api.app.navigate(msg.key),
2945 color: api.about.obs.color,
3046 blobUrl: api.blob.sync.url
3147 })
32- : BlogFull(blog, api.message.html.markdown)
33-
48+ }
49+
3450 const element = api.message.html.layout(msg, Object.assign({}, {
3551 content,
3652 layout: 'default'
3753 }, opts))
@@ -39,25 +55,8 @@
3955 return api.message.html.decorate(element, { msg })
4056 }
4157 }
4258
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-
6059 function BlogCard ({ blog, blobUrl, onClick, color }) {
6160 const thumbnail = when(blog.thumbnail,
6261 h('Thumbnail', {
6362 style: {
@@ -91,4 +90,8 @@
9190 ])
9291
9392 return b
9493 }
94+
95+function canRender (msg) {
96+ if (isBlog(msg)) return true
97+}

Built with git-ssb-web