git ssb

2+

mixmix / ticktack



Commit 35ee32eefff5c36f236876e4918c46cbeb22ef6d

refactor

Dominic Tarr committed on 12/7/2017, 2:09:45 AM
Parent: f279e0482bb337ac884bc177d679b808a5821f23

Files changed

app/html/blogCard.jschanged
app/page/blogNew.jschanged
app/page/blogShow.jschanged
main.jschanged
blogs/blog.jsdeleted
blogs/post.jsdeleted
blog/html/blog.jsadded
blog/html/post.jsadded
app/html/blogCard.jsView
@@ -32,11 +32,11 @@
3232 'message.html.timeago': 'first',
3333 'blob.sync.url': 'first',
3434 'emoji.sync.url': 'first',
3535
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',
3939 })
4040
4141 exports.create = function (api) {
4242
@@ -98,9 +98,9 @@
9898 const { content, author } = blog.value
9999
100100 var img = h('Thumbnail')
101101
102- var image = api.message.html.thumbnail(blog)
102+ var image = api.blog.html.thumbnail(blog)
103103
104104 if(image) {
105105 //Hey this works! fit an image into a specific size (see blog-card.mcss)
106106 //centered, and scaled to fit the square (works with both landscape and portrait!)
@@ -126,13 +126,13 @@
126126 ]),
127127 h('div.content', [
128128 img,
129129 h('div.text', [
130- h('h2', api.message.html.title(blog)),
130+ h('h2', api.blog.html.title(blog)),
131131 content.channel
132132 ? api.message.html.channel(blog)
133133 : '',
134- h('div.summary', api.message.html.summary(blog))
134+ h('div.summary', api.blog.html.summary(blog))
135135 ])
136136 ])
137137 ])
138138
app/page/blogNew.jsView
@@ -34,8 +34,11 @@
3434 meta,
3535 placeholder: strings.blogNew.actions.writeBlog,
3636 shrink: false,
3737 prepublish: function (content, cb) {
38+ var m = /\!\[[^]+\]\(([^\)]+)\)/.exec(marksum.image(content.text))
39+ content.thumbnail = m && m[1]
40+
3841 var stream = pull.values([content.text])
3942 delete content.text
4043 api.sbot.async.addBlob(stream, function (err, hash) {
4144 if(err) return cb(err)
@@ -102,4 +105,6 @@
102105 return page
103106 }
104107 }
105108
109+
110+
app/page/blogShow.jsView
@@ -18,10 +18,10 @@
1818 'message.html.markdown': 'first',
1919 'message.html.timeago': 'first',
2020 'feed.obs.thread': 'first',
2121
22- 'message.html.title': 'first',
23- 'message.html.content': 'first',
22+ 'blog.html.title': 'first',
23+ 'blog.html.content': 'first',
2424
2525 })
2626
2727 exports.create = (api) => {
@@ -31,10 +31,10 @@
3131 // blogMsg = a thread (message, may be decorated with replies)
3232
3333 const { author, content } = blogMsg.value
3434
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)
3737
3838 const comments = api.app.html.comments(blogMsg.key)
3939
4040 const { lastId: branch } = api.feed.obs.thread(blogMsg.key)
main.jsView
@@ -30,12 +30,12 @@
3030 state: require('./state/obs'),
3131 unread: require('./unread'),
3232 },
3333 {
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+ }}
3838 },
3939 {
4040 profile: require('patch-profile'),
4141 history: require('patch-history'),
blogs/blog.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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.jsView
@@ -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