Commit 35ee32eefff5c36f236876e4918c46cbeb22ef6d
refactor
Dominic Tarr committed on 12/7/2017, 2:09:45 AMParent: f279e0482bb337ac884bc177d679b808a5821f23
Files changed
app/html/blogCard.js | changed |
app/page/blogNew.js | changed |
app/page/blogShow.js | changed |
main.js | changed |
blogs/blog.js | deleted |
blogs/post.js | deleted |
blog/html/blog.js | added |
blog/html/post.js | added |
app/html/blogCard.js | ||
---|---|---|
@@ -32,11 +32,11 @@ | ||
32 | 32 | 'message.html.timeago': 'first', |
33 | 33 | 'blob.sync.url': 'first', |
34 | 34 | 'emoji.sync.url': 'first', |
35 | 35 | |
36 | - 'message.html.title': 'first', | |
37 | - 'message.html.summary': 'first', | |
38 | - 'message.html.thumbnail': 'first', | |
36 | + 'blog.html.title': 'first', | |
37 | + 'blog.html.summary': 'first', | |
38 | + 'blog.html.thumbnail': 'first', | |
39 | 39 | }) |
40 | 40 | |
41 | 41 | exports.create = function (api) { |
42 | 42 | |
@@ -98,9 +98,9 @@ | ||
98 | 98 | const { content, author } = blog.value |
99 | 99 | |
100 | 100 | var img = h('Thumbnail') |
101 | 101 | |
102 | - var image = api.message.html.thumbnail(blog) | |
102 | + var image = api.blog.html.thumbnail(blog) | |
103 | 103 | |
104 | 104 | if(image) { |
105 | 105 | //Hey this works! fit an image into a specific size (see blog-card.mcss) |
106 | 106 | //centered, and scaled to fit the square (works with both landscape and portrait!) |
@@ -126,13 +126,13 @@ | ||
126 | 126 | ]), |
127 | 127 | h('div.content', [ |
128 | 128 | img, |
129 | 129 | h('div.text', [ |
130 | - h('h2', api.message.html.title(blog)), | |
130 | + h('h2', api.blog.html.title(blog)), | |
131 | 131 | content.channel |
132 | 132 | ? api.message.html.channel(blog) |
133 | 133 | : '', |
134 | - h('div.summary', api.message.html.summary(blog)) | |
134 | + h('div.summary', api.blog.html.summary(blog)) | |
135 | 135 | ]) |
136 | 136 | ]) |
137 | 137 | ]) |
138 | 138 |
app/page/blogNew.js | ||
---|---|---|
@@ -34,8 +34,11 @@ | ||
34 | 34 | meta, |
35 | 35 | placeholder: strings.blogNew.actions.writeBlog, |
36 | 36 | shrink: false, |
37 | 37 | prepublish: function (content, cb) { |
38 | + var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(marksum.image(content.text)) | |
39 | + content.thumbnail = m && m[1] | |
40 | + | |
38 | 41 | var stream = pull.values([content.text]) |
39 | 42 | delete content.text |
40 | 43 | api.sbot.async.addBlob(stream, function (err, hash) { |
41 | 44 | if(err) return cb(err) |
@@ -102,4 +105,6 @@ | ||
102 | 105 | return page |
103 | 106 | } |
104 | 107 | } |
105 | 108 | |
109 | + | |
110 | + |
app/page/blogShow.js | ||
---|---|---|
@@ -18,10 +18,10 @@ | ||
18 | 18 | 'message.html.markdown': 'first', |
19 | 19 | 'message.html.timeago': 'first', |
20 | 20 | 'feed.obs.thread': 'first', |
21 | 21 | |
22 | - 'message.html.title': 'first', | |
23 | - 'message.html.content': 'first', | |
22 | + 'blog.html.title': 'first', | |
23 | + 'blog.html.content': 'first', | |
24 | 24 | |
25 | 25 | }) |
26 | 26 | |
27 | 27 | exports.create = (api) => { |
@@ -31,10 +31,10 @@ | ||
31 | 31 | // blogMsg = a thread (message, may be decorated with replies) |
32 | 32 | |
33 | 33 | const { author, content } = blogMsg.value |
34 | 34 | |
35 | - const blog = api.message.html.content(blogMsg) | |
36 | - const title = api.message.html.title(blogMsg) | |
35 | + const blog = api.blog.html.content(blogMsg) | |
36 | + const title = api.blog.html.title(blogMsg) | |
37 | 37 | |
38 | 38 | const comments = api.app.html.comments(blogMsg.key) |
39 | 39 | |
40 | 40 | const { lastId: branch } = api.feed.obs.thread(blogMsg.key) |
main.js | ||
---|---|---|
@@ -30,12 +30,12 @@ | ||
30 | 30 | state: require('./state/obs'), |
31 | 31 | unread: require('./unread'), |
32 | 32 | }, |
33 | 33 | { |
34 | - blogs: { | |
35 | - post: require('./blogs/post'), | |
36 | - blog: require('./blogs/blog') | |
37 | - } | |
34 | + blog: {html: { | |
35 | + post: require('./blog/html/post'), | |
36 | + blog: require('./blog/html/blog') | |
37 | + }} | |
38 | 38 | }, |
39 | 39 | { |
40 | 40 | profile: require('patch-profile'), |
41 | 41 | history: require('patch-history'), |
blogs/blog.js | ||
---|---|---|
@@ -1,57 +1,0 @@ | ||
1 | -var pull = require('pull-stream') | |
2 | -const h = require('mutant').h | |
3 | - | |
4 | -exports.gives = { | |
5 | - message: { | |
6 | - html: { | |
7 | - title: true, | |
8 | - summary: true, | |
9 | - thumbnail: true, | |
10 | - content: true | |
11 | - } | |
12 | - } | |
13 | -} | |
14 | - | |
15 | -exports.needs = { | |
16 | - message: { html: { markdown: 'first' } }, | |
17 | - sbot: { pull: { stream: 'first' } } | |
18 | -} | |
19 | - | |
20 | - | |
21 | -exports.create = function (api) { | |
22 | - | |
23 | - return { | |
24 | - message: { | |
25 | - html: { | |
26 | - title: function (data) { | |
27 | - if('blog' == typeof data.value.content.type) return | |
28 | - return data.value.content.title | |
29 | - }, | |
30 | - summary: function (data) { | |
31 | - if('blog' == typeof data.value.content.type) return | |
32 | - return data.value.content.summary | |
33 | - }, | |
34 | - thumbnail: function (data) { | |
35 | - if('blog' == typeof data.value.content.type) return | |
36 | - return data.value.content.thumbnail | |
37 | - }, | |
38 | - content: function (data) { | |
39 | - if('blog' == typeof data.value.content.type) return | |
40 | - var div = h('Markdown') | |
41 | - pull( | |
42 | - api.sbot.pull.stream(function (sbot) { | |
43 | - return sbot.blobs.get(data.value.content.blog) | |
44 | - }), | |
45 | - pull.collect(function (err, ary) { | |
46 | - if(err) return | |
47 | - var md = api.message.html.markdown({text:Buffer.concat(ary).toString()}) | |
48 | - div.innerHTML = md.innerHTML | |
49 | - }) | |
50 | - ) | |
51 | - return div | |
52 | - } | |
53 | - } | |
54 | - } | |
55 | - } | |
56 | -} | |
57 | - |
blogs/post.js | ||
---|---|---|
@@ -1,56 +1,0 @@ | ||
1 | -var marksum = require('markdown-summary') | |
2 | - | |
3 | -exports.gives = { | |
4 | - message: { | |
5 | - html: { | |
6 | - title: true, | |
7 | - summary: true, | |
8 | - thumbnail: true, | |
9 | - content: true | |
10 | - } | |
11 | - } | |
12 | -} | |
13 | - | |
14 | -exports.needs = { | |
15 | - message: { html: { markdown: 'first' } } | |
16 | -} | |
17 | - | |
18 | - | |
19 | -exports.create = function (api) { | |
20 | - | |
21 | - function fromPost(fn) { | |
22 | - return function (data) { | |
23 | - if('post' !== data.value.content.type) return | |
24 | - return api.message.html.markdown ({text: fn(data.value.content)}) | |
25 | - } | |
26 | - } | |
27 | - | |
28 | - return { | |
29 | - message: { | |
30 | - html: { | |
31 | - title: fromPost(function (content) { | |
32 | - return content.title || marksum.title(content.text) | |
33 | - }), | |
34 | - summary: fromPost(function (content) { | |
35 | - return content.summary || marksum.summary(content.text) | |
36 | - }), | |
37 | - thumbnail: function (data) { | |
38 | - if('post' !== data.value.content.type) return | |
39 | - var content = data.value.content | |
40 | - if(content.thumbnail) return content.thumbnail | |
41 | - var img = marksum.image(content.text) | |
42 | - var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) | |
43 | - if(m) return m[1] | |
44 | - }, | |
45 | - content: fromPost(function (content) { | |
46 | - return content.text | |
47 | - }) | |
48 | - } | |
49 | - } | |
50 | - } | |
51 | -} | |
52 | - | |
53 | - | |
54 | - | |
55 | - | |
56 | - |
blog/html/blog.js | ||
---|---|---|
@@ -1,0 +1,54 @@ | ||
1 | +var pull = require('pull-stream') | |
2 | +var nest = require('depnest') | |
3 | +const h = require('mutant').h | |
4 | + | |
5 | +exports.gives = nest({ | |
6 | + 'blog.html.title': true, | |
7 | + 'blog.html.summary': true, | |
8 | + 'blog.html.thumbnail': true, | |
9 | + 'blog.html.content': true, | |
10 | +}) | |
11 | + | |
12 | +exports.needs = nest({ | |
13 | + 'message.html.markdown': 'first', | |
14 | + 'sbot.pull.stream': 'first' | |
15 | +}) | |
16 | + | |
17 | + | |
18 | +exports.create = function (api) { | |
19 | + | |
20 | + return nest({ | |
21 | + 'blog.html.title': function (data) { | |
22 | + if('blog' == typeof data.value.content.type) return | |
23 | + return data.value.content.title | |
24 | + }, | |
25 | + 'blog.html.summary': function (data) { | |
26 | + if('blog' == typeof data.value.content.type) return | |
27 | + return data.value.content.summary | |
28 | + }, | |
29 | + 'blog.html.thumbnail': function (data) { | |
30 | + if('blog' == typeof data.value.content.type) return | |
31 | + return data.value.content.thumbnail | |
32 | + }, | |
33 | + 'blog.html.content': function (data) { | |
34 | + if('blog' == typeof data.value.content.type) return | |
35 | + var div = h('Markdown') | |
36 | + pull( | |
37 | + api.sbot.pull.stream(function (sbot) { | |
38 | + return sbot.blobs.get(data.value.content.blog) | |
39 | + }), | |
40 | + pull.collect(function (err, ary) { | |
41 | + if(err) return | |
42 | + var md = api.message.html.markdown({text:Buffer.concat(ary).toString()}) | |
43 | + div.innerHTML = md.innerHTML | |
44 | + }) | |
45 | + ) | |
46 | + return div | |
47 | + } | |
48 | + }) | |
49 | +} | |
50 | + | |
51 | + | |
52 | + | |
53 | + | |
54 | + |
blog/html/post.js | ||
---|---|---|
@@ -1,0 +1,45 @@ | ||
1 | +var marksum = require('markdown-summary') | |
2 | +var nest = require('depnest') | |
3 | + | |
4 | +exports.gives = nest({ | |
5 | + 'blog.html.title': true, | |
6 | + 'blog.html.summary': true, | |
7 | + 'blog.html.thumbnail': true, | |
8 | + 'blog.html.content': true, | |
9 | +}) | |
10 | + | |
11 | +exports.needs = nest({ | |
12 | + 'message.html.markdown': 'first', | |
13 | +}) | |
14 | + | |
15 | +exports.create = function (api) { | |
16 | + | |
17 | + function fromPost(fn) { | |
18 | + return function (data) { | |
19 | + if('post' !== data.value.content.type) return | |
20 | + return api.message.html.markdown ({text: fn(data.value.content)}) | |
21 | + } | |
22 | + } | |
23 | + | |
24 | + return nest({ | |
25 | + 'blog.html.title': fromPost(function (content) { | |
26 | + return content.title || marksum.title(content.text) | |
27 | + }), | |
28 | + 'blog.html.summary': fromPost(function (content) { | |
29 | + return content.summary || marksum.summary(content.text) | |
30 | + }), | |
31 | + 'blog.html.thumbnail': function (data) { | |
32 | + if('post' !== data.value.content.type) return | |
33 | + var content = data.value.content | |
34 | + if(content.thumbnail) return content.thumbnail | |
35 | + var img = marksum.image(content.text) | |
36 | + var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(img) | |
37 | + if(m) return m[1] | |
38 | + }, | |
39 | + 'blog.html.content': fromPost(function (content) { | |
40 | + return content.text | |
41 | + }) | |
42 | + }) | |
43 | +} | |
44 | + | |
45 | + |
Built with git-ssb-web