Commit d9737b8da7935049dc1e0bfb9b0147eada9f7843
Merge remote-tracking branch 'origin/hyperscript'
cel committed on 7/19/2017, 1:43:04 AMParent: 07ff4c602e229a458d6210ac0c19dc2b699b740f
Parent: ccc712bad78a439c6287c829554052b9cd943a4b
Files changed
index.js | changed |
render.js | changed |
index.js | ||
---|---|---|
@@ -172,9 +172,9 @@ | ||
172 | 172 | delete channelSubscriptions[msg.value.content.channel] |
173 | 173 | } |
174 | 174 | }) |
175 | 175 | |
176 | - serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + about.name) | |
176 | + serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : "")) | |
177 | 177 | }) |
178 | 178 | ) |
179 | 179 | }) |
180 | 180 | } |
@@ -224,9 +224,9 @@ | ||
224 | 224 | pull( |
225 | 225 | pull.values(logs), |
226 | 226 | paramap(addAuthorAbout, 8), |
227 | 227 | paramap(addVoteMessage, 8), |
228 | - pull(renderThread(defaultOpts, | |
228 | + pull(renderThread(defaultOpts, '', | |
229 | 229 | renderShowAll(showAll, req.url)), |
230 | 230 | wrapPage('#' + channelId)), |
231 | 231 | toPull(res, function (err) { |
232 | 232 | if (err) console.error('[viewer]', err) |
render.js | ||
---|---|---|
@@ -42,13 +42,19 @@ | ||
42 | 42 | return href; |
43 | 43 | }; |
44 | 44 | |
45 | 45 | MdRenderer.prototype.image = function(href, title, text) { |
46 | - return h('img', | |
47 | - { src: this.opts.img_base + href, | |
48 | - alt: text, | |
49 | - title: title | |
50 | - }).outerHTML; | |
46 | + if (text.endsWith(".svg")) | |
47 | + return h('object', | |
48 | + { type: 'image/svg+xml', | |
49 | + data: href, | |
50 | + alt: text }).outerHTML; | |
51 | + else | |
52 | + return h('img', | |
53 | + { src: this.opts.img_base + href, | |
54 | + alt: text, | |
55 | + title: title | |
56 | + }).outerHTML; | |
51 | 57 | }; |
52 | 58 | |
53 | 59 | function renderEmoji(emoji) { |
54 | 60 | var opts = this.renderer.opts; |
@@ -76,9 +82,9 @@ | ||
76 | 82 | |
77 | 83 | function formatMsgs(id, ext, opts) { |
78 | 84 | switch (ext || "html") { |
79 | 85 | case "html": |
80 | - return pull(renderThread(opts), wrapPage(id)); | |
86 | + return pull(renderThread(opts, id, ''), wrapPage(id)); | |
81 | 87 | case "js": |
82 | 88 | return pull(renderThread(opts), wrapJSEmbed(opts)); |
83 | 89 | case "json": |
84 | 90 | return wrapJSON(); |
@@ -113,27 +119,26 @@ | ||
113 | 119 | figCaption.innerHTML = 'Feed of ' + about.name + '<br>' + |
114 | 120 | (about.description != undefined ? |
115 | 121 | marked(about.description, opts.marked) : ''); |
116 | 122 | return pull( |
117 | - pull.map(renderMsg.bind(this, opts)), | |
123 | + pull.map(renderMsg.bind(this, opts, '')), | |
118 | 124 | wrap(toolTipTop() + '<main>' + |
119 | 125 | h('article', |
120 | 126 | h('header', |
121 | 127 | h('figure', |
122 | 128 | h('img', |
123 | 129 | { src: opts.img_base + about.image, |
124 | - height: 200, | |
125 | - width: 200 | |
130 | + style: 'max-height: 200px; max-width: 200px;' | |
126 | 131 | }), |
127 | 132 | figCaption) |
128 | 133 | )).outerHTML, |
129 | 134 | showAllHTML + '</main>' + callToAction()) |
130 | 135 | ); |
131 | 136 | } |
132 | 137 | |
133 | -function renderThread(opts, showAllHTML = "") { | |
138 | +function renderThread(opts, id, showAllHTML = "") { | |
134 | 139 | return pull( |
135 | - pull.map(renderMsg.bind(this, opts)), | |
140 | + pull.map(renderMsg.bind(this, opts, id)), | |
136 | 141 | wrap(toolTipTop() + '<main>', |
137 | 142 | showAllHTML + '</main>' + callToAction()) |
138 | 143 | ); |
139 | 144 | } |
@@ -332,9 +337,9 @@ | ||
332 | 337 | function docWrite(str) { |
333 | 338 | return "document.write(" + JSON.stringify(str) + ")\n"; |
334 | 339 | } |
335 | 340 | |
336 | -function renderMsg(opts, msg) { | |
341 | +function renderMsg(opts, id, msg) { | |
337 | 342 | var c = msg.value.content || {}; |
338 | 343 | var name = encodeURIComponent(msg.key); |
339 | 344 | return h('article#' + name, |
340 | 345 | h('header', |
@@ -346,9 +351,9 @@ | ||
346 | 351 | h('a.ssb-avatar-name', |
347 | 352 | { href: opts.base + escape(msg.value.author) }, |
348 | 353 | msg.author.name), |
349 | 354 | msgTimestamp(msg, opts.base + name)))), |
350 | - render(opts, c)).outerHTML; | |
355 | + render(opts, id, c)).outerHTML; | |
351 | 356 | } |
352 | 357 | |
353 | 358 | function renderRss(opts, msg) { |
354 | 359 | var c = msg.value.content || {}; |
@@ -386,18 +391,18 @@ | ||
386 | 391 | function formatDate(date) { |
387 | 392 | return htime(date); |
388 | 393 | } |
389 | 394 | |
390 | -function render(opts, c) { | |
395 | +function render(opts, id, c) { | |
391 | 396 | var base = opts.base; |
392 | 397 | if (c.type === "post") { |
393 | 398 | var channel = c.channel |
394 | 399 | ? h('div.top-right', |
395 | 400 | h('a', |
396 | 401 | { href: base + 'channel/' + c.channel }, |
397 | 402 | '#' + c.channel)) |
398 | 403 | : ""; |
399 | - return [channel, renderPost(opts, c)]; | |
404 | + return [channel, renderPost(opts, id, c)]; | |
400 | 405 | } else if (c.type == "vote" && c.vote.expression == "Dig") { |
401 | 406 | var channel = c.channel |
402 | 407 | ? [' in ', |
403 | 408 | h('a', |
@@ -442,18 +447,23 @@ | ||
442 | 447 | else if (c.type == "issue") { |
443 | 448 | return [h('span.status', |
444 | 449 | "Created a git issue" + |
445 | 450 | (c.repoName != undefined ? " in repo " + c.repoName : ""), |
446 | - renderPost(opts, c))]; | |
451 | + renderPost(opts, id, c))]; | |
447 | 452 | } |
448 | - else if (c.type == "git-update") { | |
453 | + else if (c.type == "git-repo") { | |
449 | 454 | return h('span.status', |
450 | - "Did a git update " + | |
451 | - (c.repoName != undefined ? " in repo " + c.repoName : "") + | |
452 | - '<br>' + | |
453 | - (c.commits != undefined ? | |
454 | - c.commits.map(com => { return "-" +com.title; }).join('<br>') : "")); | |
455 | + "Created a git repo " + c.name); | |
455 | 456 | } |
457 | + else if (c.type == "git-update") { | |
458 | + var s = h('span.status'); | |
459 | + s.innerHTML = "Did a git update " + | |
460 | + (c.repoName != undefined ? " in repo " + c.repoName : "") + | |
461 | + '<br>' + | |
462 | + (c.commits != undefined ? | |
463 | + c.commits.map(com => { return "-" +com.title; }).join('<br>') : ""); | |
464 | + return s; | |
465 | + } | |
456 | 466 | else if (c.type == "ssb-dns") { |
457 | 467 | return [h('span.status', 'Updated DNS'), renderDefault(c)]; |
458 | 468 | } |
459 | 469 | else if (c.type == "pub") { |
@@ -473,18 +483,23 @@ | ||
473 | 483 | '#' + c.channel)) |
474 | 484 | else return renderDefault(c); |
475 | 485 | } |
476 | 486 | |
477 | -function renderPost(opts, c) { | |
487 | +function renderPost(opts, id, c) { | |
478 | 488 | opts.mentions = {}; |
479 | 489 | if (Array.isArray(c.mentions)) { |
480 | 490 | c.mentions.forEach(function (link) { |
481 | 491 | if (link && link.name && link.link) |
482 | 492 | opts.mentions[link.name] = link.link; |
483 | 493 | }); |
484 | 494 | } |
485 | 495 | var s = h('section'); |
486 | - s.innerHTML = marked(String(c.text), opts.marked); | |
496 | + var content = ''; | |
497 | + if (c.root && c.root != id) | |
498 | + content += 'Re: ' + h('a', | |
499 | + { href: '/' + encodeURIComponent(c.root) }, | |
500 | + c.root.substring(0, 10)).outerHTML + '<br>'; | |
501 | + s.innerHTML = content + marked(String(c.text), opts.marked); | |
487 | 502 | return s; |
488 | 503 | } |
489 | 504 | |
490 | 505 | function renderDefault(c) { |
Built with git-ssb-web