git ssb

0+

Daan Patchwork / ssb-viewer



forked from cel / ssb-viewer

Commit d9737b8da7935049dc1e0bfb9b0147eada9f7843

Merge remote-tracking branch 'origin/hyperscript'

cel committed on 7/19/2017, 1:43:04 AM
Parent: 07ff4c602e229a458d6210ac0c19dc2b699b740f
Parent: ccc712bad78a439c6287c829554052b9cd943a4b

Files changed

index.jschanged
render.jschanged
index.jsView
@@ -172,9 +172,9 @@
172172 delete channelSubscriptions[msg.value.content.channel]
173173 }
174174 })
175175
176- serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + about.name)
176+ serveFeeds(req, res, following, channelSubscriptions, feedId, 'user feed ' + (about ? about.name : ""))
177177 })
178178 )
179179 })
180180 }
@@ -224,9 +224,9 @@
224224 pull(
225225 pull.values(logs),
226226 paramap(addAuthorAbout, 8),
227227 paramap(addVoteMessage, 8),
228- pull(renderThread(defaultOpts,
228+ pull(renderThread(defaultOpts, '',
229229 renderShowAll(showAll, req.url)),
230230 wrapPage('#' + channelId)),
231231 toPull(res, function (err) {
232232 if (err) console.error('[viewer]', err)
render.jsView
@@ -42,13 +42,19 @@
4242 return href;
4343 };
4444
4545 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;
5157 };
5258
5359 function renderEmoji(emoji) {
5460 var opts = this.renderer.opts;
@@ -76,9 +82,9 @@
7682
7783 function formatMsgs(id, ext, opts) {
7884 switch (ext || "html") {
7985 case "html":
80- return pull(renderThread(opts), wrapPage(id));
86+ return pull(renderThread(opts, id, ''), wrapPage(id));
8187 case "js":
8288 return pull(renderThread(opts), wrapJSEmbed(opts));
8389 case "json":
8490 return wrapJSON();
@@ -113,27 +119,26 @@
113119 figCaption.innerHTML = 'Feed of ' + about.name + '<br>' +
114120 (about.description != undefined ?
115121 marked(about.description, opts.marked) : '');
116122 return pull(
117- pull.map(renderMsg.bind(this, opts)),
123+ pull.map(renderMsg.bind(this, opts, '')),
118124 wrap(toolTipTop() + '<main>' +
119125 h('article',
120126 h('header',
121127 h('figure',
122128 h('img',
123129 { src: opts.img_base + about.image,
124- height: 200,
125- width: 200
130+ style: 'max-height: 200px; max-width: 200px;'
126131 }),
127132 figCaption)
128133 )).outerHTML,
129134 showAllHTML + '</main>' + callToAction())
130135 );
131136 }
132137
133-function renderThread(opts, showAllHTML = "") {
138+function renderThread(opts, id, showAllHTML = "") {
134139 return pull(
135- pull.map(renderMsg.bind(this, opts)),
140+ pull.map(renderMsg.bind(this, opts, id)),
136141 wrap(toolTipTop() + '<main>',
137142 showAllHTML + '</main>' + callToAction())
138143 );
139144 }
@@ -332,9 +337,9 @@
332337 function docWrite(str) {
333338 return "document.write(" + JSON.stringify(str) + ")\n";
334339 }
335340
336-function renderMsg(opts, msg) {
341+function renderMsg(opts, id, msg) {
337342 var c = msg.value.content || {};
338343 var name = encodeURIComponent(msg.key);
339344 return h('article#' + name,
340345 h('header',
@@ -346,9 +351,9 @@
346351 h('a.ssb-avatar-name',
347352 { href: opts.base + escape(msg.value.author) },
348353 msg.author.name),
349354 msgTimestamp(msg, opts.base + name)))),
350- render(opts, c)).outerHTML;
355+ render(opts, id, c)).outerHTML;
351356 }
352357
353358 function renderRss(opts, msg) {
354359 var c = msg.value.content || {};
@@ -386,18 +391,18 @@
386391 function formatDate(date) {
387392 return htime(date);
388393 }
389394
390-function render(opts, c) {
395+function render(opts, id, c) {
391396 var base = opts.base;
392397 if (c.type === "post") {
393398 var channel = c.channel
394399 ? h('div.top-right',
395400 h('a',
396401 { href: base + 'channel/' + c.channel },
397402 '#' + c.channel))
398403 : "";
399- return [channel, renderPost(opts, c)];
404+ return [channel, renderPost(opts, id, c)];
400405 } else if (c.type == "vote" && c.vote.expression == "Dig") {
401406 var channel = c.channel
402407 ? [' in ',
403408 h('a',
@@ -442,18 +447,23 @@
442447 else if (c.type == "issue") {
443448 return [h('span.status',
444449 "Created a git issue" +
445450 (c.repoName != undefined ? " in repo " + c.repoName : ""),
446- renderPost(opts, c))];
451+ renderPost(opts, id, c))];
447452 }
448- else if (c.type == "git-update") {
453+ else if (c.type == "git-repo") {
449454 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);
455456 }
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+ }
456466 else if (c.type == "ssb-dns") {
457467 return [h('span.status', 'Updated DNS'), renderDefault(c)];
458468 }
459469 else if (c.type == "pub") {
@@ -473,18 +483,23 @@
473483 '#' + c.channel))
474484 else return renderDefault(c);
475485 }
476486
477-function renderPost(opts, c) {
487+function renderPost(opts, id, c) {
478488 opts.mentions = {};
479489 if (Array.isArray(c.mentions)) {
480490 c.mentions.forEach(function (link) {
481491 if (link && link.name && link.link)
482492 opts.mentions[link.name] = link.link;
483493 });
484494 }
485495 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);
487502 return s;
488503 }
489504
490505 function renderDefault(c) {

Built with git-ssb-web