git ssb

9+

cel / ssb-viewer



Commit 332c09b046eddbc3f31c2105251afcf185d868b0

Whitespace and code style consistency

cel committed on 8/29/2019, 7:49:22 PM
Parent: ad80496c9aaec127be8cd80533c253901b618812

Files changed

index.jschanged
render.jschanged
index.jsView
@@ -23,9 +23,9 @@
2323 renderAbout,
2424 renderShowAll,
2525 renderRssItem,
2626 wrapRss,
27-} = require('./render');
27 +} = require('./render')
2828
2929 var appHash = hash([fs.readFileSync(__filename)])
3030
3131 var urlIdRegex = /^(?:\/(([%&@]|%25|%26|%40)(?:[A-Za-z0-9\/+]|%2[Ff]|%2[Bb]){43}(?:=|%3[Dd])\.(?:sha256|ed25519))(?:\.([^?]*))?|(\/.*?))(?:\?(.*))?$/
@@ -109,11 +109,11 @@
109109 return respond(res, 404, 'Not found')
110110 }
111111
112112 function serveFeed(req, res, feedId, ext) {
113- console.log("serving feed: " + feedId)
113 + console.log('serving feed: ' + feedId)
114114
115- var showAll = req.url.endsWith("?showAll");
115 + var showAll = req.url.endsWith('?showAll')
116116
117117 getAbout(feedId, function (err, about) {
118118 if (err) return respond(res, 500, err.stack || err)
119119
@@ -122,17 +122,17 @@
122122 case 'rss':
123123 return pull(
124124 // formatMsgs(feedId, ext, defaultOpts)
125125 renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
126- );
126 + )
127127 default:
128128 var publicWebHosting = about.publicWebHosting == null
129129 ? !defaultOpts.requireOptIn : about.publicWebHosting
130130 var name = publicWebHosting ? about.name : feedId.substr(0, 10) + '…'
131131 return pull(
132132 renderAbout(defaultOpts, about,
133133 renderShowAll(showAll, req.url)), wrapPage(name)
134- );
134 + )
135135 }
136136 }
137137
138138 pull(
@@ -186,43 +186,43 @@
186186 }
187187
188188 function serveUserFeed(req, res, url) {
189189 var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
190- console.log("serving user feed: " + feedId)
190 + console.log('serving user feed: ' + feedId)
191191
192192 var following = []
193193 var channelSubscriptions = []
194194
195195 getAbout(feedId, function (err, about) {
196196 pull(
197- sbot.createUserStream({ id: feedId }),
198- pull.filter((msg) => {
199- return !msg.value ||
200- msg.value.content.type == 'contact' ||
201- (msg.value.content.type == 'channel' &&
202- typeof msg.value.content.subscribed != 'undefined')
203- }),
204- pull.collect(function (err, msgs) {
205- msgs.forEach((msg) => {
206- if (msg.value.content.type == 'contact')
207- {
208- if (msg.value.content.following)
209- following[msg.value.content.contact] = 1
210- else
211- delete following[msg.value.content.contact]
212- }
213- else // channel subscription
214- {
215- if (msg.value.content.subscribed)
216- channelSubscriptions[msg.value.content.channel] = 1
217- else
218- delete channelSubscriptions[msg.value.content.channel]
219- }
220- })
221-
222- serveFeeds(req, res, following, channelSubscriptions, feedId,
223- 'user feed ' + (about ? about.name : ""))
224- })
197 + sbot.createUserStream({ id: feedId }),
198 + pull.filter((msg) => {
199 + return !msg.value ||
200 + msg.value.content.type == 'contact' ||
201 + (msg.value.content.type == 'channel' &&
202 + typeof msg.value.content.subscribed != 'undefined')
203 + }),
204 + pull.collect(function (err, msgs) {
205 + msgs.forEach((msg) => {
206 + if (msg.value.content.type == 'contact')
207 + {
208 + if (msg.value.content.following)
209 + following[msg.value.content.contact] = 1
210 + else
211 + delete following[msg.value.content.contact]
212 + }
213 + else // channel subscription
214 + {
215 + if (msg.value.content.subscribed)
216 + channelSubscriptions[msg.value.content.channel] = 1
217 + else
218 + delete channelSubscriptions[msg.value.content.channel]
219 + }
220 + })
221 +
222 + serveFeeds(req, res, following, channelSubscriptions, feedId,
223 + 'user feed ' + (about ? about.name : ''))
224 + })
225225 )
226226 })
227227 }
228228
@@ -240,60 +240,60 @@
240240
241241 pull(
242242 sbot.createLogStream({ reverse: true, limit: 5000 }),
243243 pull.filter((msg) => {
244- return !msg.value ||
245- (msg.value.author in following ||
246- msg.value.content.channel in channelSubscriptions)
244 + return !msg.value ||
245 + (msg.value.author in following ||
246 + msg.value.content.channel in channelSubscriptions)
247247 }),
248248 pull.take(150),
249249 pull.collect(function (err, logs) {
250- if (err) return respond(res, 500, err.stack || err)
251- res.writeHead(200, {
252- 'Content-Type': ctype("html")
253- })
254- pull(
255- pull.values(logs),
256- paramap(addAuthorAbout, 8),
250 + if (err) return respond(res, 500, err.stack || err)
251 + res.writeHead(200, {
252 + 'Content-Type': ctype('html')
253 + })
254 + pull(
255 + pull.values(logs),
256 + paramap(addAuthorAbout, 8),
257257 paramap(addBlog, 8),
258- paramap(addFollowAbout, 8),
259- paramap(addVoteMessage, 8),
260- paramap(addGitLinks, 8),
261- paramap(addGatheringAbout, 8),
262- pull(renderThread(feedOpts), wrapPage(name)),
263- toPull(res, function (err) {
264- if (err) console.error('[viewer]', err)
265- })
266- )
258 + paramap(addFollowAbout, 8),
259 + paramap(addVoteMessage, 8),
260 + paramap(addGitLinks, 8),
261 + paramap(addGatheringAbout, 8),
262 + pull(renderThread(feedOpts), wrapPage(name)),
263 + toPull(res, function (err) {
264 + if (err) console.error('[viewer]', err)
265 + })
266 + )
267267 })
268268 )
269269 }
270270
271271 function serveChannel(req, res, url) {
272272 var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
273- console.log("serving channel: " + channelId)
273 + console.log('serving channel: ' + channelId)
274274
275- var showAll = req.url.endsWith("?showAll")
275 + var showAll = req.url.endsWith('?showAll')
276276
277277 pull(
278278 sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
279279 pull.collect(function (err, logs) {
280- if (err) return respond(res, 500, err.stack || err)
281- res.writeHead(200, {
282- 'Content-Type': ctype("html")
283- })
284- pull(
285- pull.values(logs),
286- paramap(addAuthorAbout, 8),
280 + if (err) return respond(res, 500, err.stack || err)
281 + res.writeHead(200, {
282 + 'Content-Type': ctype('html')
283 + })
284 + pull(
285 + pull.values(logs),
286 + paramap(addAuthorAbout, 8),
287287 paramap(addBlog, 8),
288- paramap(addVoteMessage, 8),
289- paramap(addGatheringAbout, 8),
290- pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)),
291- wrapPage('#' + channelId)),
292- toPull(res, function (err) {
293- if (err) console.error('[viewer]', err)
294- })
295- )
288 + paramap(addVoteMessage, 8),
289 + paramap(addGatheringAbout, 8),
290 + pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)),
291 + wrapPage('#' + channelId)),
292 + toPull(res, function (err) {
293 + if (err) console.error('[viewer]', err)
294 + })
295 + )
296296 })
297297 )
298298 }
299299
@@ -371,29 +371,29 @@
371371
372372 function addFollowAbout(msg, cb) {
373373 if (msg.value.content.contact)
374374 getAbout(msg.value.content.contact, function (err, about) {
375- if (err) return cb(err)
376- msg.value.content.contactAbout = about
377- cb(null, msg)
375 + if (err) return cb(err)
376 + msg.value.content.contactAbout = about
377 + cb(null, msg)
378378 })
379379 else
380380 cb(null, msg)
381381 }
382382
383383 function addVoteMessage(msg, cb) {
384384 if (msg.value.content.type == 'vote' && msg.value.content.vote && msg.value.content.vote.link[0] == '%')
385385 getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
386- if (linkedMsg)
387- msg.value.content.vote.linkedText = linkedMsg.value.content.text
388- cb(null, msg)
386 + if (linkedMsg)
387 + msg.value.content.vote.linkedText = linkedMsg.value.content.text
388 + cb(null, msg)
389389 })
390390 else
391391 cb(null, msg)
392392 }
393393
394394 function addBlog(msg, cb) {
395- if (msg.value && msg.value.content.type == "blog") {
395 + if (msg.value && msg.value.content.type == 'blog') {
396396 pull(
397397 sbot.blobs.get(msg.value.content.blog),
398398 pull.collect(function(err, blob) {
399399 msg.value.content.blogContent = blob
@@ -448,17 +448,17 @@
448448
449449 function addGitLinks(msg, cb) {
450450 if (msg.value.content.type == 'git-update')
451451 getMsg(msg.value.content.repo, function (err, gitRepo) {
452- if (gitRepo)
453- msg.value.content.repoName = gitRepo.value.content.name
454- cb(null, msg)
452 + if (gitRepo)
453 + msg.value.content.repoName = gitRepo.value.content.name
454 + cb(null, msg)
455455 })
456456 else if (msg.value.content.type == 'issue')
457457 getMsg(msg.value.content.project, function (err, gitRepo) {
458- if (gitRepo)
459- msg.value.content.repoName = gitRepo.value.content.name
460- cb(null, msg)
458 + if (gitRepo)
459 + msg.value.content.repoName = gitRepo.value.content.name
460 + cb(null, msg)
461461 })
462462 else
463463 cb(null, msg)
464464 }
@@ -571,10 +571,10 @@
571571 var id = asLink(q.id)
572572 if (id) {
573573 res.writeHead(303, {
574574 Location: '/' + (
575- id[0] === '#' ? 'channel/' + id.substr(1) :
576- refs.isMsgId(id) ? encodeURIComponent(id) : id)
575 + id[0] === '#' ? 'channel/' + id.substr(1) :
576 + refs.isMsgId(id) ? encodeURIComponent(id) : id)
577577 })
578578 return res.end()
579579 }
580580 res.writeHead(200, {
render.jsView
@@ -1,161 +1,161 @@
1-var path = require('path');
2-var pull = require("pull-stream");
3-var marked = require("ssb-marked");
4-var htime = require("human-time");
5-var emojis = require("emoji-named-characters");
6-var cat = require("pull-cat");
7-var h = require('hyperscript');
1 +var path = require('path')
2 +var pull = require("pull-stream")
3 +var marked = require("ssb-marked")
4 +var htime = require("human-time")
5 +var emojis = require("emoji-named-characters")
6 +var cat = require("pull-cat")
7 +var h = require('hyperscript')
88 var refs = require('ssb-ref')
99
10-var emojiDir = path.join(require.resolve("emoji-named-characters"), "../pngs");
10 +var emojiDir = path.join(require.resolve("emoji-named-characters"), "../pngs")
1111
12-exports.wrapPage = wrapPage;
13-exports.MdRenderer = MdRenderer;
14-exports.renderEmoji = renderEmoji;
15-exports.formatMsgs = formatMsgs;
16-exports.renderThread = renderThread;
17-exports.renderAbout = renderAbout;
18-exports.renderShowAll = renderShowAll;
19-exports.renderRssItem = renderRssItem;
20-exports.wrapRss = wrapRss;
12 +exports.wrapPage = wrapPage
13 +exports.MdRenderer = MdRenderer
14 +exports.renderEmoji = renderEmoji
15 +exports.formatMsgs = formatMsgs
16 +exports.renderThread = renderThread
17 +exports.renderAbout = renderAbout
18 +exports.renderShowAll = renderShowAll
19 +exports.renderRssItem = renderRssItem
20 +exports.wrapRss = wrapRss
2121
2222 function MdRenderer(opts) {
23- marked.Renderer.call(this, {});
24- this.opts = opts;
23 + marked.Renderer.call(this, {})
24 + this.opts = opts
2525 }
2626
27-MdRenderer.prototype = new marked.Renderer();
27 +MdRenderer.prototype = new marked.Renderer()
2828
2929 MdRenderer.prototype.urltransform = function(href) {
30- if (!href) return false;
30 + if (!href) return false
3131 switch (href[0]) {
32- case "#":
33- return this.opts.base + "channel/" + href.slice(1);
34- case "%":
32 + case '#':
33 + return this.opts.base + 'channel/' + href.slice(1)
34 + case '%':
3535 if (!refs.isMsgId(href)) return false
36- return this.opts.msg_base + encodeURIComponent(href);
37- case "@":
36 + return this.opts.msg_base + encodeURIComponent(href)
37 + case '@':
3838 if (!refs.isFeedId(href)) return false
39- href = (this.opts.mentions && this.opts.mentions[href.substr(1)]) || href;
40- return this.opts.feed_base + href;
41- case "&":
39 + href = (this.opts.mentions && this.opts.mentions[href.substr(1)]) || href
40 + return this.opts.feed_base + href
41 + case '&':
4242 if (!refs.isBlobId(href)) return false
43- return this.opts.blob_base + href;
43 + return this.opts.blob_base + href
4444 }
45- if (href.indexOf("javascript:") === 0) return false;
46- return href;
47-};
45 + if (href.indexOf('javascript:') === 0) return false
46 + return href
47 +}
4848
4949 MdRenderer.prototype.image = function(href, title, text) {
50- if (text.endsWith(".svg"))
50 + if (text.endsWith('.svg'))
5151 return h('object',
52- { type: 'image/svg+xml',
53- data: href,
54- alt: text }).outerHTML;
52 + { type: 'image/svg+xml',
53 + data: href,
54 + alt: text }).outerHTML
5555 else
5656 return h('img',
57- { src: this.opts.img_base + href,
58- alt: text,
59- title: title
60- }).outerHTML;
61-};
57 + { src: this.opts.img_base + href,
58 + alt: text,
59 + title: title
60 + }).outerHTML
61 +}
6262
6363 function renderEmoji(emoji) {
64- var opts = this.renderer.opts;
64 + var opts = this.renderer.opts
6565 var url = opts.mentions && opts.mentions[emoji]
6666 ? opts.blob_base + encodeURIComponent(opts.mentions[emoji])
67- : emoji in emojis && opts.emoji_base + escape(emoji) + '.png';
67 + : emoji in emojis && opts.emoji_base + escape(emoji) + '.png'
6868 return url
69- ? h('img.ssb-emoji',
70- { src: url,
71- alt: ':' + escape(emoji) + ':',
72- title: ':' + escape(emoji) + ':',
73- height: 16, width: 16
74- }).outerHTML
75- : ":" + emoji + ":";
69 + ? h('img.ssb-emoji',
70 + { src: url,
71 + alt: ':' + escape(emoji) + ':',
72 + title: ':' + escape(emoji) + ':',
73 + height: 16, width: 16
74 + }).outerHTML
75 + : ':' + emoji + ':'
7676 }
7777
7878 function escape(str) {
7979 return String(str)
80- .replace(/&/g, "&")
81- .replace(/</g, "&lt;")
82- .replace(/>/g, "&gt;")
83- .replace(/"/g, "&quot;");
80 + .replace(/&/g, '&amp;')
81 + .replace(/</g, '&lt;')
82 + .replace(/>/g, '&gt;')
83 + .replace(/'/g, '&quot;')
8484 }
8585
8686 function formatMsgs(id, ext, opts) {
87- switch (ext || "html") {
88- case "html":
89- return pull(renderThread(opts, id, ''), wrapPage(id));
90- case "js":
91- return pull(renderThread(opts), wrapJSEmbed(opts));
92- case "json":
93- return wrapJSON();
94- case "rss":
95- return pull(renderRssItem(opts), wrapRss(id, opts));
87 + switch (ext || 'html') {
88 + case 'html':
89 + return pull(renderThread(opts, id, ''), wrapPage(id))
90 + case 'js':
91 + return pull(renderThread(opts), wrapJSEmbed(opts))
92 + case 'json':
93 + return wrapJSON()
94 + case 'rss':
95 + return pull(renderRssItem(opts), wrapRss(id, opts))
9696 default:
97- return null;
97 + return null
9898 }
9999 }
100100
101101 function wrap(before, after) {
102102 return function(read) {
103- return cat([pull.once(before), read, pull.once(after)]);
104- };
103 + return cat([pull.once(before), read, pull.once(after)])
104 + }
105105 }
106106
107107 function callToAction() {
108108 return h('a.call-to-action',
109- { href: 'https://www.scuttlebutt.nz' },
110- 'Join Scuttlebutt now').outerHTML;
109 + { href: 'https://www.scuttlebutt.nz' },
110 + 'Join Scuttlebutt now').outerHTML
111111 }
112112
113113 function toolTipTop() {
114114 return h('span.top-tip',
115- 'You are reading content from ',
116- h('a', { href: 'https://www.scuttlebutt.nz' },
117- 'Scuttlebutt')).outerHTML;
115 + 'You are reading content from ',
116 + h('a', { href: 'https://www.scuttlebutt.nz' },
117 + 'Scuttlebutt')).outerHTML
118118 }
119119
120120 function renderAbout(opts, about, showAllHTML = "") {
121121 if (about.publicWebHosting === false || (about.publicWebHosting == null && opts.requireOptIn)) {
122122 return pull(
123123 pull.map(renderMsg.bind(this, opts, '')),
124124 wrap(toolTipTop() + '<main>', '</main>' + callToAction())
125- );
125 + )
126126 }
127127
128- var figCaption = h('figcaption');
129- figCaption.innerHTML = 'Feed of ' + escape(about.name) + '<br>' + marked(String(about.description || ''), opts.marked);
128 + var figCaption = h('figcaption')
129 + figCaption.innerHTML = 'Feed of ' + escape(about.name) + '<br>' + marked(String(about.description || ''), opts.marked)
130130 return pull(
131131 pull.map(renderMsg.bind(this, opts, '')),
132132 wrap(toolTipTop() + '<main>' +
133- h('article',
134- h('header',
135- h('figure',
136- h('img',
137- { src: opts.img_base + about.image,
138- style: 'max-height: 200px; max-width: 200px;'
139- }),
140- figCaption)
141- )).outerHTML,
142- showAllHTML + '</main>' + callToAction())
143- );
133 + h('article',
134 + h('header',
135 + h('figure',
136 + h('img',
137 + { src: opts.img_base + about.image,
138 + style: 'max-height: 200px; max-width: 200px;'
139 + }),
140 + figCaption)
141 + )).outerHTML,
142 + showAllHTML + '</main>' + callToAction())
143 + )
144144 }
145145
146146 function renderThread(opts, id, showAllHTML = "") {
147147 return pull(
148148 pull.map(renderMsg.bind(this, opts, id)),
149149 wrap(toolTipTop() + '<main>',
150- showAllHTML + '</main>' + callToAction())
151- );
150 + showAllHTML + '</main>' + callToAction())
151 + )
152152 }
153153
154154 function renderRssItem(opts) {
155155 return pull(
156156 pull.map(renderRss.bind(this, opts))
157- );
157 + )
158158 }
159159
160160 function wrapPage(id) {
161161 return wrap(
@@ -167,9 +167,9 @@
167167 '<meta name=viewport content="width=device-width,initial-scale=1">' +
168168 styles +
169169 "</head><body>",
170170 "</body></html>"
171- );
171 + )
172172 }
173173
174174 function wrapRss(id, opts) {
175175 return wrap(
@@ -179,9 +179,9 @@
179179 '<title>' + id + ' | ssb-viewer</title>',
180180
181181 '</channel>'+
182182 '</rss>'
183- );
183 + )
184184 }
185185
186186 var styles = `
187187 <style>
@@ -303,21 +303,21 @@
303303 .attending {
304304 text-align: center;
305305 }
306306 </style>
307-`;
307 +`
308308
309309 function wrapJSON() {
310- var first = true;
311- return pull(pull.map(JSON.stringify), join(","), wrap("[", "]"));
310 + var first = true
311 + return pull(pull.map(JSON.stringify), join(','), wrap('[', ']'))
312312 }
313313
314314 function wrapJSEmbed(opts) {
315315 return pull(
316316 wrap('<link rel=stylesheet href="' + opts.base + 'static/base.css">', ""),
317317 pull.map(docWrite),
318318 opts.base_token && rewriteBase(new RegExp(opts.base_token, "g"))
319- );
319 + )
320320 }
321321
322322 function rewriteBase(token) {
323323 // detect the origin of the script and rewrite the js/html to use it
@@ -331,70 +331,68 @@
331331 'return script.src.replace(/\\/%.*$/, "")\n' +
332332 "}())\n",
333333 ""
334334 )
335- );
335 + )
336336 }
337337
338338 function join(delim) {
339- var first = true;
339 + var first = true
340340 return pull.map(function(val) {
341- if (!first) return delim + String(val);
342- first = false;
343- return val;
344- });
341 + if (!first) return delim + String(val)
342 + first = false
343 + return val
344 + })
345345 }
346346
347347 function replace(re, rep) {
348348 return pull.map(function(val) {
349- return String(val).replace(re, rep);
350- });
349 + return String(val).replace(re, rep)
350 + })
351351 }
352352
353353 function docWrite(str) {
354- return "document.write(" + JSON.stringify(str) + ")\n";
354 + return 'document.write(' + JSON.stringify(str) + ')\n'
355355 }
356356
357357 function renderMsg(opts, id, msg) {
358- var c = msg.value.content || {};
358 + var c = msg.value.content || {}
359359
360360 if (opts.renderPrivate == false && typeof(msg.value.content) == 'string') return ''
361- if (opts.renderSubscribe == false && c.type == "channel" && c.subscribed != undefined) return ''
361 + if (opts.renderSubscribe == false && c.type == 'channel' && c.subscribed != undefined) return ''
362362 if (opts.renderVote == false && c.type == "vote") return ''
363363 if (opts.renderChess == false && c.type.startsWith("chess")) return ''
364364 if (opts.renderTalenet == false && c.type.startsWith("talenet")) return ''
365365 if (opts.renderFollow == false && c.type == "contact") return ''
366366 if (opts.renderAbout == false && c.type == "about") return ''
367367 if (opts.renderPub == false && c.type == "pub") return ''
368- if (msg.author.publicWebHosting === false) return h('article', 'User has chosen not to be hosted publicly').outerHTML;
369- if (msg.author.publicWebHosting == null && opts.requireOptIn) return h('article', 'User has not chosen to be hosted publicly').outerHTML;
368 + if (msg.author.publicWebHosting === false) return h('article', 'User has chosen not to be hosted publicly').outerHTML
369 + if (msg.author.publicWebHosting == null && opts.requireOptIn) return h('article', 'User has not chosen to be hosted publicly').outerHTML
370370
371- var name = encodeURIComponent(msg.key);
371 + var name = encodeURIComponent(msg.key)
372372 return h('article#' + name,
373- h('header',
374- h('figure',
375- h('img', { alt: '',
376- src: opts.img_base + msg.author.image,
377- height: 50, width: 50 }),
378- h('figcaption',
379- h('a.ssb-avatar-name',
380- { href: opts.base + escape(msg.value.author) },
381- msg.author.name),
382- msgTimestamp(msg, opts.base + name), ' ',
383- h('small', h('code', msg.key))
384- ))),
385- render(opts, id, c)).outerHTML;
373 + h('header',
374 + h('figure',
375 + h('img', { alt: '',
376 + src: opts.img_base + msg.author.image,
377 + height: 50, width: 50 }),
378 + h('figcaption',
379 + h('a.ssb-avatar-name',
380 + { href: opts.base + escape(msg.value.author) },
381 + msg.author.name),
382 + msgTimestamp(msg, opts.base + name), ' ',
383 + h('small', h('code', msg.key))
384 + ))),
385 + render(opts, id, c)).outerHTML
386386 }
387387
388388 function renderRss(opts, msg) {
389- var c = msg.value.content || {};
390- var name = encodeURIComponent(msg.key);
389 + var c = msg.value.content || {}
390 + var name = encodeURIComponent(msg.key)
391391
392- let content = h('div', render(opts, c)).innerHTML;
392 + let content = h('div', render(opts, c)).innerHTML
393393
394- if (!content) {
395- return null;
396- }
394 + if (!content) return null
397395
398396 return (
399397 '<item>' +
400398 '<title>' + escape(c.type || 'private') + '</title>' +
@@ -403,151 +401,151 @@
403401 '<link>' + opts.base + escape(name) + '</link>' +
404402 '<pubDate>' + new Date(msg.value.timestamp).toUTCString() + '</pubDate>' +
405403 '<guid>' + msg.key + '</guid>' +
406404 '</item>'
407- );
405 + )
408406 }
409407
410408 function msgTimestamp(msg, link) {
411- var date = new Date(msg.value.timestamp);
412- var isoStr = date.toISOString();
409 + var date = new Date(msg.value.timestamp)
410 + var isoStr = date.toISOString()
413411 return h('time.ssb-timestamp',
414- { datetime: isoStr },
415- h('a',
416- { href: link,
417- title: isoStr },
418- formatDate(date)));
412 + { datetime: isoStr },
413 + h('a',
414 + { href: link,
415 + title: isoStr },
416 + formatDate(date)))
419417 }
420418
421419 function formatDate(date) {
422- return htime(date);
420 + return htime(date)
423421 }
424422
425423 function render(opts, id, c) {
426- var base = opts.base;
424 + var base = opts.base
427425 if (!c) return
428- if (c.type === "post") {
426 + if (c.type === 'post') {
429427 var channel = c.channel
430- ? h('div.top-right',
431- h('a',
432- { href: base + 'channel/' + c.channel },
433- '#' + c.channel))
434- : "";
435- return [channel, renderPost(opts, id, c)];
436- } else if (c.type == "vote" && c.vote.expression == "Dig") {
428 + ? h('div.top-right',
429 + h('a',
430 + { href: base + 'channel/' + c.channel },
431 + '#' + c.channel))
432 + : ''
433 + return [channel, renderPost(opts, id, c)]
434 + } else if (c.type == 'vote' && c.vote.expression == 'Dig') {
437435 var channel = c.channel
438- ? [' in ',
439- h('a',
440- { href: base + 'channel/' + c.channel },
441- '#' + c.channel)]
442- : "";
443- var linkedText = "this";
444- if (typeof c.vote.linkedText != "undefined")
445- linkedText = c.vote.linkedText.substring(0, 75);
436 + ? [' in ',
437 + h('a',
438 + { href: base + 'channel/' + c.channel },
439 + '#' + c.channel)]
440 + : ''
441 + var linkedText = 'this'
442 + if (typeof c.vote.linkedText != 'undefined')
443 + linkedText = c.vote.linkedText.substring(0, 75)
446444 return h('span.status',
447- ['Liked ',
448- h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText),
449- channel]);
450- } else if (c.type == "vote") {
451- var linkedText = "this";
452- if (c.vote && typeof c.vote.linkedText === "string")
453- linkedText = c.vote.linkedText.substring(0, 75);
445 + ['Liked ',
446 + h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText),
447 + channel])
448 + } else if (c.type == 'vote') {
449 + var linkedText = 'this'
450 + if (c.vote && typeof c.vote.linkedText === 'string')
451 + linkedText = c.vote.linkedText.substring(0, 75)
454452 return h('span.status',
455- ['Voted ',
456- h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText)]);
457- } else if (c.type == "contact" && c.following) {
458- var name = c.contact;
453 + ['Voted ',
454 + h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText)])
455 + } else if (c.type == 'contact' && c.following) {
456 + var name = c.contact
459457 if (c.contactAbout)
460- name = c.contactAbout.name;
458 + name = c.contactAbout.name
461459 return h('span.status',
462- ['Followed ',
463- h('a', { href: base + c.contact }, name)]);
464- } else if (c.type == "contact" && !c.following) {
465- var name = c.contact;
460 + ['Followed ',
461 + h('a', { href: base + c.contact }, name)])
462 + } else if (c.type == 'contact' && !c.following) {
463 + var name = c.contact
466464 if (c.contactAbout)
467- name = c.contactAbout.name;
465 + name = c.contactAbout.name
468466 return h('span.status',
469- ['Unfollowed ',
470- h('a', { href: base + c.contact }, name)]);
471- } else if (typeof c == "string") {
467 + ['Unfollowed ',
468 + h('a', { href: base + c.contact }, name)])
469 + } else if (typeof c == 'string') {
472470 return h('span.status', 'Wrote something private')
473- } else if (c.type == "chess_move") {
471 + } else if (c.type == 'chess_move') {
474472 return h('span.status', 'Moved a chess piece')
475- } else if (c.type == "chess_invite") {
473 + } else if (c.type == 'chess_invite') {
476474 return h('span.status', 'Started a chess game')
477475 }
478- else if (c.type == "about") {
476 + else if (c.type == 'about') {
479477 return [h('span.status', 'Changed something in about'),
480- renderDefault(c)];
478 + renderDefault(c)]
481479 }
482- else if (c.type == "issue") {
480 + else if (c.type == 'issue') {
483481 return [h('span.status',
484- "Created a git issue" +
485- (c.repoName ? " in repo " + c.repoName : ""),
486- renderPost(opts, id, c))];
482 + 'Created a git issue' +
483 + (c.repoName ? ' in repo ' + c.repoName : ''),
484 + renderPost(opts, id, c))]
487485 }
488- else if (c.type == "git-repo") {
486 + else if (c.type == 'git-repo') {
489487 return h('span.status',
490- "Created a git repo " + c.name);
488 + 'Created a git repo ' + c.name)
491489 }
492- else if (c.type == "git-update") {
493- return h('div.status', "Did a git update " +
494- (c.repoName ? " in repo " + c.repoName : ""),
490 + else if (c.type == 'git-update') {
491 + return h('div.status', 'Did a git update ' +
492 + (c.repoName ? ' in repo ' + c.repoName : ''),
495493 (Array.isArray(c.commits) ? h('ul',
496494 c.commits.filter(Boolean).map(com => {
497495 return h('li', String(com.title || com.sha1))
498496 })
499- ) : "")
497 + ) : '')
500498 )
501499 }
502- else if (c.type == "ssb-dns") {
503- return [h('span.status', 'Updated DNS'), renderDefault(c)];
500 + else if (c.type == 'ssb-dns') {
501 + return [h('span.status', 'Updated DNS'), renderDefault(c)]
504502 }
505- else if (c.type == "pub") {
503 + else if (c.type == 'pub') {
506504 var host = c.address && c.address.host
507- return h('span.status', 'Connected to the pub ' + host);
505 + return h('span.status', 'Connected to the pub ' + host)
508506 }
509- else if (c.type == "npm-packages") {
507 + else if (c.type == 'npm-packages') {
510508 return h('div.status', 'Pushed npm packages',
511509 Array.isArray(c.mentions) ? h('ul', c.mentions.map(function (link) {
512510 var name = link && link.name
513511 var m = name && /^npm:([^:]*):([^:]*)(?::([^:]*)(?:\.tgz)?)?$/.exec(name)
514512 if (!m) return
515513 var [, name, version, tag] = m
516514 return h('li', name + ' v' + version + (tag ? ' (' + tag + ')' : ''))
517515 })) : ''
518- );
516 + )
519517 }
520- else if (c.type == "channel" && c.subscribed)
518 + else if (c.type == 'channel' && c.subscribed)
521519 return h('span.status',
522- 'Subscribed to channel ',
523- h('a',
524- { href: base + 'channel/' + c.channel },
525- '#' + c.channel));
526- else if (c.type == "channel" && !c.subscribed)
520 + 'Subscribed to channel ',
521 + h('a',
522 + { href: base + 'channel/' + c.channel },
523 + '#' + c.channel))
524 + else if (c.type == 'channel' && !c.subscribed)
527525 return h('span.status',
528- 'Unsubscribed from channel ',
529- h('a',
530- { href: base + 'channel/' + c.channel },
531- '#' + c.channel))
532- else if (c.type == "blog") {
526 + 'Unsubscribed from channel ',
527 + h('a',
528 + { href: base + 'channel/' + c.channel },
529 + '#' + c.channel))
530 + else if (c.type == 'blog') {
533531 //%RTXvyZ2fZWwTyWdlk0lYGk5sKw5Irj+Wk4QwxyOVG5g=.sha256
534532 var channel = c.channel
535- ? h('div.top-right',
536- h('a',
537- { href: base + 'channel/' + c.channel },
538- '#' + c.channel))
539- : "";
533 + ? h('div.top-right',
534 + h('a',
535 + { href: base + 'channel/' + c.channel },
536 + '#' + c.channel))
537 + : ''
540538
541- var s = h('section');
539 + var s = h('section')
542540 s.innerHTML = marked(String(c.blogContent), opts.marked)
543541
544- return [channel, h('h2', String(c.title)), s];
542 + return [channel, h('h2', String(c.title)), s]
545543 }
546544 else if (c.type === 'gathering') {
547545 return h('div', renderGathering(opts, id, c))
548546 }
549- else return renderDefault(c);
547 + else return renderDefault(c)
550548 }
551549
552550 function renderGathering(opts, id, c) {
553551 const title = h('h2', String(c.about.title))
@@ -566,29 +564,29 @@
566564 )
567565 }
568566
569567 function renderPost(opts, id, c) {
570- opts.mentions = {};
568 + opts.mentions = {}
571569 if (Array.isArray(c.mentions)) {
572- c.mentions.forEach(function (link) {
573- if (link && link.name && link.link)
574- opts.mentions[link.name] = link.link;
575- });
570 + c.mentions.forEach(function (link) {
571 + if (link && link.name && link.link)
572 + opts.mentions[link.name] = link.link
573 + })
576574 }
577- var s = h('section');
578- var content = '';
575 + var s = h('section')
576 + var content = ''
579577 if (c.root && c.root != id)
580- content += 'Re: ' + h('a',
581- { href: '/' + encodeURIComponent(c.root) },
582- c.root.substring(0, 10)).outerHTML + '<br>';
583- s.innerHTML = content + marked(String(c.text), opts.marked);
584- return s;
578 + content += 'Re: ' + h('a',
579 + { href: '/' + encodeURIComponent(c.root) },
580 + c.root.substring(0, 10)).outerHTML + '<br>'
581 + s.innerHTML = content + marked(String(c.text), opts.marked)
582 + return s
585583 }
586584
587585 function renderDefault(c) {
588- return h('pre', JSON.stringify(c, 0, 2));
586 + return h('pre', JSON.stringify(c, 0, 2))
589587 }
590588
591589 function renderShowAll(showAll, url) {
592590 if (!showAll)
593- return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
591 + return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML
594592 }

Built with git-ssb-web