Whitespace and code style consistency
This commit is contained in:
@@ -24,7 +24,7 @@ var {
|
|||||||
renderShowAll,
|
renderShowAll,
|
||||||
renderRssItem,
|
renderRssItem,
|
||||||
wrapRss,
|
wrapRss,
|
||||||
} = require('./render');
|
} = require('./render')
|
||||||
|
|
||||||
var appHash = hash([fs.readFileSync(__filename)])
|
var appHash = hash([fs.readFileSync(__filename)])
|
||||||
|
|
||||||
@@ -110,9 +110,9 @@ exports.init = function (sbot, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function serveFeed(req, res, feedId, ext) {
|
function serveFeed(req, res, feedId, ext) {
|
||||||
console.log("serving feed: " + feedId)
|
console.log('serving feed: ' + feedId)
|
||||||
|
|
||||||
var showAll = req.url.endsWith("?showAll");
|
var showAll = req.url.endsWith('?showAll')
|
||||||
|
|
||||||
getAbout(feedId, function (err, about) {
|
getAbout(feedId, function (err, about) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
@@ -123,7 +123,7 @@ exports.init = function (sbot, config) {
|
|||||||
return pull(
|
return pull(
|
||||||
// formatMsgs(feedId, ext, defaultOpts)
|
// formatMsgs(feedId, ext, defaultOpts)
|
||||||
renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
|
renderRssItem(defaultOpts), wrapRss(about.name, defaultOpts)
|
||||||
);
|
)
|
||||||
default:
|
default:
|
||||||
var publicWebHosting = about.publicWebHosting == null
|
var publicWebHosting = about.publicWebHosting == null
|
||||||
? !defaultOpts.requireOptIn : about.publicWebHosting
|
? !defaultOpts.requireOptIn : about.publicWebHosting
|
||||||
@@ -131,7 +131,7 @@ exports.init = function (sbot, config) {
|
|||||||
return pull(
|
return pull(
|
||||||
renderAbout(defaultOpts, about,
|
renderAbout(defaultOpts, about,
|
||||||
renderShowAll(showAll, req.url)), wrapPage(name)
|
renderShowAll(showAll, req.url)), wrapPage(name)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,41 +187,41 @@ exports.init = function (sbot, config) {
|
|||||||
|
|
||||||
function serveUserFeed(req, res, url) {
|
function serveUserFeed(req, res, url) {
|
||||||
var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
|
var feedId = url.substring(url.lastIndexOf('user-feed/')+10, 100)
|
||||||
console.log("serving user feed: " + feedId)
|
console.log('serving user feed: ' + feedId)
|
||||||
|
|
||||||
var following = []
|
var following = []
|
||||||
var channelSubscriptions = []
|
var channelSubscriptions = []
|
||||||
|
|
||||||
getAbout(feedId, function (err, about) {
|
getAbout(feedId, function (err, about) {
|
||||||
pull(
|
pull(
|
||||||
sbot.createUserStream({ id: feedId }),
|
sbot.createUserStream({ id: feedId }),
|
||||||
pull.filter((msg) => {
|
pull.filter((msg) => {
|
||||||
return !msg.value ||
|
return !msg.value ||
|
||||||
msg.value.content.type == 'contact' ||
|
msg.value.content.type == 'contact' ||
|
||||||
(msg.value.content.type == 'channel' &&
|
(msg.value.content.type == 'channel' &&
|
||||||
typeof msg.value.content.subscribed != 'undefined')
|
typeof msg.value.content.subscribed != 'undefined')
|
||||||
}),
|
}),
|
||||||
pull.collect(function (err, msgs) {
|
pull.collect(function (err, msgs) {
|
||||||
msgs.forEach((msg) => {
|
msgs.forEach((msg) => {
|
||||||
if (msg.value.content.type == 'contact')
|
if (msg.value.content.type == 'contact')
|
||||||
{
|
{
|
||||||
if (msg.value.content.following)
|
if (msg.value.content.following)
|
||||||
following[msg.value.content.contact] = 1
|
following[msg.value.content.contact] = 1
|
||||||
else
|
else
|
||||||
delete following[msg.value.content.contact]
|
delete following[msg.value.content.contact]
|
||||||
}
|
}
|
||||||
else // channel subscription
|
else // channel subscription
|
||||||
{
|
{
|
||||||
if (msg.value.content.subscribed)
|
if (msg.value.content.subscribed)
|
||||||
channelSubscriptions[msg.value.content.channel] = 1
|
channelSubscriptions[msg.value.content.channel] = 1
|
||||||
else
|
else
|
||||||
delete channelSubscriptions[msg.value.content.channel]
|
delete channelSubscriptions[msg.value.content.channel]
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
serveFeeds(req, res, following, channelSubscriptions, feedId,
|
serveFeeds(req, res, following, channelSubscriptions, feedId,
|
||||||
'user feed ' + (about ? about.name : ""))
|
'user feed ' + (about ? about.name : ''))
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -241,58 +241,58 @@ exports.init = function (sbot, config) {
|
|||||||
pull(
|
pull(
|
||||||
sbot.createLogStream({ reverse: true, limit: 5000 }),
|
sbot.createLogStream({ reverse: true, limit: 5000 }),
|
||||||
pull.filter((msg) => {
|
pull.filter((msg) => {
|
||||||
return !msg.value ||
|
return !msg.value ||
|
||||||
(msg.value.author in following ||
|
(msg.value.author in following ||
|
||||||
msg.value.content.channel in channelSubscriptions)
|
msg.value.content.channel in channelSubscriptions)
|
||||||
}),
|
}),
|
||||||
pull.take(150),
|
pull.take(150),
|
||||||
pull.collect(function (err, logs) {
|
pull.collect(function (err, logs) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Type': ctype("html")
|
'Content-Type': ctype('html')
|
||||||
})
|
})
|
||||||
pull(
|
pull(
|
||||||
pull.values(logs),
|
pull.values(logs),
|
||||||
paramap(addAuthorAbout, 8),
|
paramap(addAuthorAbout, 8),
|
||||||
paramap(addBlog, 8),
|
paramap(addBlog, 8),
|
||||||
paramap(addFollowAbout, 8),
|
paramap(addFollowAbout, 8),
|
||||||
paramap(addVoteMessage, 8),
|
paramap(addVoteMessage, 8),
|
||||||
paramap(addGitLinks, 8),
|
paramap(addGitLinks, 8),
|
||||||
paramap(addGatheringAbout, 8),
|
paramap(addGatheringAbout, 8),
|
||||||
pull(renderThread(feedOpts), wrapPage(name)),
|
pull(renderThread(feedOpts), wrapPage(name)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function serveChannel(req, res, url) {
|
function serveChannel(req, res, url) {
|
||||||
var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
|
var channelId = url.substring(url.lastIndexOf('channel/')+8, 100)
|
||||||
console.log("serving channel: " + channelId)
|
console.log('serving channel: ' + channelId)
|
||||||
|
|
||||||
var showAll = req.url.endsWith("?showAll")
|
var showAll = req.url.endsWith('?showAll')
|
||||||
|
|
||||||
pull(
|
pull(
|
||||||
sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
|
sbot.query.read({ limit: showAll ? 300 : 10, reverse: true, query: [{$filter: { value: { content: { channel: channelId }}}}]}),
|
||||||
pull.collect(function (err, logs) {
|
pull.collect(function (err, logs) {
|
||||||
if (err) return respond(res, 500, err.stack || err)
|
if (err) return respond(res, 500, err.stack || err)
|
||||||
res.writeHead(200, {
|
res.writeHead(200, {
|
||||||
'Content-Type': ctype("html")
|
'Content-Type': ctype('html')
|
||||||
})
|
})
|
||||||
pull(
|
pull(
|
||||||
pull.values(logs),
|
pull.values(logs),
|
||||||
paramap(addAuthorAbout, 8),
|
paramap(addAuthorAbout, 8),
|
||||||
paramap(addBlog, 8),
|
paramap(addBlog, 8),
|
||||||
paramap(addVoteMessage, 8),
|
paramap(addVoteMessage, 8),
|
||||||
paramap(addGatheringAbout, 8),
|
paramap(addGatheringAbout, 8),
|
||||||
pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)),
|
pull(renderThread(defaultOpts, '', renderShowAll(showAll, req.url)),
|
||||||
wrapPage('#' + channelId)),
|
wrapPage('#' + channelId)),
|
||||||
toPull(res, function (err) {
|
toPull(res, function (err) {
|
||||||
if (err) console.error('[viewer]', err)
|
if (err) console.error('[viewer]', err)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -372,9 +372,9 @@ exports.init = function (sbot, config) {
|
|||||||
function addFollowAbout(msg, cb) {
|
function addFollowAbout(msg, cb) {
|
||||||
if (msg.value.content.contact)
|
if (msg.value.content.contact)
|
||||||
getAbout(msg.value.content.contact, function (err, about) {
|
getAbout(msg.value.content.contact, function (err, about) {
|
||||||
if (err) return cb(err)
|
if (err) return cb(err)
|
||||||
msg.value.content.contactAbout = about
|
msg.value.content.contactAbout = about
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
@@ -383,16 +383,16 @@ exports.init = function (sbot, config) {
|
|||||||
function addVoteMessage(msg, cb) {
|
function addVoteMessage(msg, cb) {
|
||||||
if (msg.value.content.type == 'vote' && msg.value.content.vote && msg.value.content.vote.link[0] == '%')
|
if (msg.value.content.type == 'vote' && msg.value.content.vote && msg.value.content.vote.link[0] == '%')
|
||||||
getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
|
getMsg(msg.value.content.vote.link, function (err, linkedMsg) {
|
||||||
if (linkedMsg)
|
if (linkedMsg)
|
||||||
msg.value.content.vote.linkedText = linkedMsg.value.content.text
|
msg.value.content.vote.linkedText = linkedMsg.value.content.text
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBlog(msg, cb) {
|
function addBlog(msg, cb) {
|
||||||
if (msg.value && msg.value.content.type == "blog") {
|
if (msg.value && msg.value.content.type == 'blog') {
|
||||||
pull(
|
pull(
|
||||||
sbot.blobs.get(msg.value.content.blog),
|
sbot.blobs.get(msg.value.content.blog),
|
||||||
pull.collect(function(err, blob) {
|
pull.collect(function(err, blob) {
|
||||||
@@ -449,15 +449,15 @@ exports.init = function (sbot, config) {
|
|||||||
function addGitLinks(msg, cb) {
|
function addGitLinks(msg, cb) {
|
||||||
if (msg.value.content.type == 'git-update')
|
if (msg.value.content.type == 'git-update')
|
||||||
getMsg(msg.value.content.repo, function (err, gitRepo) {
|
getMsg(msg.value.content.repo, function (err, gitRepo) {
|
||||||
if (gitRepo)
|
if (gitRepo)
|
||||||
msg.value.content.repoName = gitRepo.value.content.name
|
msg.value.content.repoName = gitRepo.value.content.name
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else if (msg.value.content.type == 'issue')
|
else if (msg.value.content.type == 'issue')
|
||||||
getMsg(msg.value.content.project, function (err, gitRepo) {
|
getMsg(msg.value.content.project, function (err, gitRepo) {
|
||||||
if (gitRepo)
|
if (gitRepo)
|
||||||
msg.value.content.repoName = gitRepo.value.content.name
|
msg.value.content.repoName = gitRepo.value.content.name
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
cb(null, msg)
|
cb(null, msg)
|
||||||
@@ -572,8 +572,8 @@ function serveHome(req, res, query, conf) {
|
|||||||
if (id) {
|
if (id) {
|
||||||
res.writeHead(303, {
|
res.writeHead(303, {
|
||||||
Location: '/' + (
|
Location: '/' + (
|
||||||
id[0] === '#' ? 'channel/' + id.substr(1) :
|
id[0] === '#' ? 'channel/' + id.substr(1) :
|
||||||
refs.isMsgId(id) ? encodeURIComponent(id) : id)
|
refs.isMsgId(id) ? encodeURIComponent(id) : id)
|
||||||
})
|
})
|
||||||
return res.end()
|
return res.end()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,120 +1,120 @@
|
|||||||
var path = require('path');
|
var path = require('path')
|
||||||
var pull = require("pull-stream");
|
var pull = require("pull-stream")
|
||||||
var marked = require("ssb-marked");
|
var marked = require("ssb-marked")
|
||||||
var htime = require("human-time");
|
var htime = require("human-time")
|
||||||
var emojis = require("emoji-named-characters");
|
var emojis = require("emoji-named-characters")
|
||||||
var cat = require("pull-cat");
|
var cat = require("pull-cat")
|
||||||
var h = require('hyperscript');
|
var h = require('hyperscript')
|
||||||
var refs = require('ssb-ref')
|
var refs = require('ssb-ref')
|
||||||
|
|
||||||
var emojiDir = path.join(require.resolve("emoji-named-characters"), "../pngs");
|
var emojiDir = path.join(require.resolve("emoji-named-characters"), "../pngs")
|
||||||
|
|
||||||
exports.wrapPage = wrapPage;
|
exports.wrapPage = wrapPage
|
||||||
exports.MdRenderer = MdRenderer;
|
exports.MdRenderer = MdRenderer
|
||||||
exports.renderEmoji = renderEmoji;
|
exports.renderEmoji = renderEmoji
|
||||||
exports.formatMsgs = formatMsgs;
|
exports.formatMsgs = formatMsgs
|
||||||
exports.renderThread = renderThread;
|
exports.renderThread = renderThread
|
||||||
exports.renderAbout = renderAbout;
|
exports.renderAbout = renderAbout
|
||||||
exports.renderShowAll = renderShowAll;
|
exports.renderShowAll = renderShowAll
|
||||||
exports.renderRssItem = renderRssItem;
|
exports.renderRssItem = renderRssItem
|
||||||
exports.wrapRss = wrapRss;
|
exports.wrapRss = wrapRss
|
||||||
|
|
||||||
function MdRenderer(opts) {
|
function MdRenderer(opts) {
|
||||||
marked.Renderer.call(this, {});
|
marked.Renderer.call(this, {})
|
||||||
this.opts = opts;
|
this.opts = opts
|
||||||
}
|
}
|
||||||
|
|
||||||
MdRenderer.prototype = new marked.Renderer();
|
MdRenderer.prototype = new marked.Renderer()
|
||||||
|
|
||||||
MdRenderer.prototype.urltransform = function(href) {
|
MdRenderer.prototype.urltransform = function(href) {
|
||||||
if (!href) return false;
|
if (!href) return false
|
||||||
switch (href[0]) {
|
switch (href[0]) {
|
||||||
case "#":
|
case '#':
|
||||||
return this.opts.base + "channel/" + href.slice(1);
|
return this.opts.base + 'channel/' + href.slice(1)
|
||||||
case "%":
|
case '%':
|
||||||
if (!refs.isMsgId(href)) return false
|
if (!refs.isMsgId(href)) return false
|
||||||
return this.opts.msg_base + encodeURIComponent(href);
|
return this.opts.msg_base + encodeURIComponent(href)
|
||||||
case "@":
|
case '@':
|
||||||
if (!refs.isFeedId(href)) return false
|
if (!refs.isFeedId(href)) return false
|
||||||
href = (this.opts.mentions && this.opts.mentions[href.substr(1)]) || href;
|
href = (this.opts.mentions && this.opts.mentions[href.substr(1)]) || href
|
||||||
return this.opts.feed_base + href;
|
return this.opts.feed_base + href
|
||||||
case "&":
|
case '&':
|
||||||
if (!refs.isBlobId(href)) return false
|
if (!refs.isBlobId(href)) return false
|
||||||
return this.opts.blob_base + href;
|
return this.opts.blob_base + href
|
||||||
}
|
}
|
||||||
if (href.indexOf("javascript:") === 0) return false;
|
if (href.indexOf('javascript:') === 0) return false
|
||||||
return href;
|
return href
|
||||||
};
|
}
|
||||||
|
|
||||||
MdRenderer.prototype.image = function(href, title, text) {
|
MdRenderer.prototype.image = function(href, title, text) {
|
||||||
if (text.endsWith(".svg"))
|
if (text.endsWith('.svg'))
|
||||||
return h('object',
|
return h('object',
|
||||||
{ type: 'image/svg+xml',
|
{ type: 'image/svg+xml',
|
||||||
data: href,
|
data: href,
|
||||||
alt: text }).outerHTML;
|
alt: text }).outerHTML
|
||||||
else
|
else
|
||||||
return h('img',
|
return h('img',
|
||||||
{ src: this.opts.img_base + href,
|
{ src: this.opts.img_base + href,
|
||||||
alt: text,
|
alt: text,
|
||||||
title: title
|
title: title
|
||||||
}).outerHTML;
|
}).outerHTML
|
||||||
};
|
}
|
||||||
|
|
||||||
function renderEmoji(emoji) {
|
function renderEmoji(emoji) {
|
||||||
var opts = this.renderer.opts;
|
var opts = this.renderer.opts
|
||||||
var url = opts.mentions && opts.mentions[emoji]
|
var url = opts.mentions && opts.mentions[emoji]
|
||||||
? opts.blob_base + encodeURIComponent(opts.mentions[emoji])
|
? opts.blob_base + encodeURIComponent(opts.mentions[emoji])
|
||||||
: emoji in emojis && opts.emoji_base + escape(emoji) + '.png';
|
: emoji in emojis && opts.emoji_base + escape(emoji) + '.png'
|
||||||
return url
|
return url
|
||||||
? h('img.ssb-emoji',
|
? h('img.ssb-emoji',
|
||||||
{ src: url,
|
{ src: url,
|
||||||
alt: ':' + escape(emoji) + ':',
|
alt: ':' + escape(emoji) + ':',
|
||||||
title: ':' + escape(emoji) + ':',
|
title: ':' + escape(emoji) + ':',
|
||||||
height: 16, width: 16
|
height: 16, width: 16
|
||||||
}).outerHTML
|
}).outerHTML
|
||||||
: ":" + emoji + ":";
|
: ':' + emoji + ':'
|
||||||
}
|
}
|
||||||
|
|
||||||
function escape(str) {
|
function escape(str) {
|
||||||
return String(str)
|
return String(str)
|
||||||
.replace(/&/g, "&")
|
.replace(/&/g, '&')
|
||||||
.replace(/</g, "<")
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, ">")
|
.replace(/>/g, '>')
|
||||||
.replace(/"/g, """);
|
.replace(/'/g, '"')
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatMsgs(id, ext, opts) {
|
function formatMsgs(id, ext, opts) {
|
||||||
switch (ext || "html") {
|
switch (ext || 'html') {
|
||||||
case "html":
|
case 'html':
|
||||||
return pull(renderThread(opts, id, ''), wrapPage(id));
|
return pull(renderThread(opts, id, ''), wrapPage(id))
|
||||||
case "js":
|
case 'js':
|
||||||
return pull(renderThread(opts), wrapJSEmbed(opts));
|
return pull(renderThread(opts), wrapJSEmbed(opts))
|
||||||
case "json":
|
case 'json':
|
||||||
return wrapJSON();
|
return wrapJSON()
|
||||||
case "rss":
|
case 'rss':
|
||||||
return pull(renderRssItem(opts), wrapRss(id, opts));
|
return pull(renderRssItem(opts), wrapRss(id, opts))
|
||||||
default:
|
default:
|
||||||
return null;
|
return null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrap(before, after) {
|
function wrap(before, after) {
|
||||||
return function(read) {
|
return function(read) {
|
||||||
return cat([pull.once(before), read, pull.once(after)]);
|
return cat([pull.once(before), read, pull.once(after)])
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function callToAction() {
|
function callToAction() {
|
||||||
return h('a.call-to-action',
|
return h('a.call-to-action',
|
||||||
{ href: 'https://www.scuttlebutt.nz' },
|
{ href: 'https://www.scuttlebutt.nz' },
|
||||||
'Join Scuttlebutt now').outerHTML;
|
'Join Scuttlebutt now').outerHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
function toolTipTop() {
|
function toolTipTop() {
|
||||||
return h('span.top-tip',
|
return h('span.top-tip',
|
||||||
'You are reading content from ',
|
'You are reading content from ',
|
||||||
h('a', { href: 'https://www.scuttlebutt.nz' },
|
h('a', { href: 'https://www.scuttlebutt.nz' },
|
||||||
'Scuttlebutt')).outerHTML;
|
'Scuttlebutt')).outerHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAbout(opts, about, showAllHTML = "") {
|
function renderAbout(opts, about, showAllHTML = "") {
|
||||||
@@ -122,39 +122,39 @@ function renderAbout(opts, about, showAllHTML = "") {
|
|||||||
return pull(
|
return pull(
|
||||||
pull.map(renderMsg.bind(this, opts, '')),
|
pull.map(renderMsg.bind(this, opts, '')),
|
||||||
wrap(toolTipTop() + '<main>', '</main>' + callToAction())
|
wrap(toolTipTop() + '<main>', '</main>' + callToAction())
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var figCaption = h('figcaption');
|
var figCaption = h('figcaption')
|
||||||
figCaption.innerHTML = 'Feed of ' + escape(about.name) + '<br>' + marked(String(about.description || ''), opts.marked);
|
figCaption.innerHTML = 'Feed of ' + escape(about.name) + '<br>' + marked(String(about.description || ''), opts.marked)
|
||||||
return pull(
|
return pull(
|
||||||
pull.map(renderMsg.bind(this, opts, '')),
|
pull.map(renderMsg.bind(this, opts, '')),
|
||||||
wrap(toolTipTop() + '<main>' +
|
wrap(toolTipTop() + '<main>' +
|
||||||
h('article',
|
h('article',
|
||||||
h('header',
|
h('header',
|
||||||
h('figure',
|
h('figure',
|
||||||
h('img',
|
h('img',
|
||||||
{ src: opts.img_base + about.image,
|
{ src: opts.img_base + about.image,
|
||||||
style: 'max-height: 200px; max-width: 200px;'
|
style: 'max-height: 200px; max-width: 200px;'
|
||||||
}),
|
}),
|
||||||
figCaption)
|
figCaption)
|
||||||
)).outerHTML,
|
)).outerHTML,
|
||||||
showAllHTML + '</main>' + callToAction())
|
showAllHTML + '</main>' + callToAction())
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderThread(opts, id, showAllHTML = "") {
|
function renderThread(opts, id, showAllHTML = "") {
|
||||||
return pull(
|
return pull(
|
||||||
pull.map(renderMsg.bind(this, opts, id)),
|
pull.map(renderMsg.bind(this, opts, id)),
|
||||||
wrap(toolTipTop() + '<main>',
|
wrap(toolTipTop() + '<main>',
|
||||||
showAllHTML + '</main>' + callToAction())
|
showAllHTML + '</main>' + callToAction())
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderRssItem(opts) {
|
function renderRssItem(opts) {
|
||||||
return pull(
|
return pull(
|
||||||
pull.map(renderRss.bind(this, opts))
|
pull.map(renderRss.bind(this, opts))
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapPage(id) {
|
function wrapPage(id) {
|
||||||
@@ -168,7 +168,7 @@ function wrapPage(id) {
|
|||||||
styles +
|
styles +
|
||||||
"</head><body>",
|
"</head><body>",
|
||||||
"</body></html>"
|
"</body></html>"
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapRss(id, opts) {
|
function wrapRss(id, opts) {
|
||||||
@@ -180,7 +180,7 @@ function wrapRss(id, opts) {
|
|||||||
|
|
||||||
'</channel>'+
|
'</channel>'+
|
||||||
'</rss>'
|
'</rss>'
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var styles = `
|
var styles = `
|
||||||
@@ -304,11 +304,11 @@ var styles = `
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
`;
|
`
|
||||||
|
|
||||||
function wrapJSON() {
|
function wrapJSON() {
|
||||||
var first = true;
|
var first = true
|
||||||
return pull(pull.map(JSON.stringify), join(","), wrap("[", "]"));
|
return pull(pull.map(JSON.stringify), join(','), wrap('[', ']'))
|
||||||
}
|
}
|
||||||
|
|
||||||
function wrapJSEmbed(opts) {
|
function wrapJSEmbed(opts) {
|
||||||
@@ -316,7 +316,7 @@ function wrapJSEmbed(opts) {
|
|||||||
wrap('<link rel=stylesheet href="' + opts.base + 'static/base.css">', ""),
|
wrap('<link rel=stylesheet href="' + opts.base + 'static/base.css">', ""),
|
||||||
pull.map(docWrite),
|
pull.map(docWrite),
|
||||||
opts.base_token && rewriteBase(new RegExp(opts.base_token, "g"))
|
opts.base_token && rewriteBase(new RegExp(opts.base_token, "g"))
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function rewriteBase(token) {
|
function rewriteBase(token) {
|
||||||
@@ -332,68 +332,66 @@ function rewriteBase(token) {
|
|||||||
"}())\n",
|
"}())\n",
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function join(delim) {
|
function join(delim) {
|
||||||
var first = true;
|
var first = true
|
||||||
return pull.map(function(val) {
|
return pull.map(function(val) {
|
||||||
if (!first) return delim + String(val);
|
if (!first) return delim + String(val)
|
||||||
first = false;
|
first = false
|
||||||
return val;
|
return val
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function replace(re, rep) {
|
function replace(re, rep) {
|
||||||
return pull.map(function(val) {
|
return pull.map(function(val) {
|
||||||
return String(val).replace(re, rep);
|
return String(val).replace(re, rep)
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function docWrite(str) {
|
function docWrite(str) {
|
||||||
return "document.write(" + JSON.stringify(str) + ")\n";
|
return 'document.write(' + JSON.stringify(str) + ')\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMsg(opts, id, msg) {
|
function renderMsg(opts, id, msg) {
|
||||||
var c = msg.value.content || {};
|
var c = msg.value.content || {}
|
||||||
|
|
||||||
if (opts.renderPrivate == false && typeof(msg.value.content) == 'string') return ''
|
if (opts.renderPrivate == false && typeof(msg.value.content) == 'string') return ''
|
||||||
if (opts.renderSubscribe == false && c.type == "channel" && c.subscribed != undefined) return ''
|
if (opts.renderSubscribe == false && c.type == 'channel' && c.subscribed != undefined) return ''
|
||||||
if (opts.renderVote == false && c.type == "vote") return ''
|
if (opts.renderVote == false && c.type == "vote") return ''
|
||||||
if (opts.renderChess == false && c.type.startsWith("chess")) return ''
|
if (opts.renderChess == false && c.type.startsWith("chess")) return ''
|
||||||
if (opts.renderTalenet == false && c.type.startsWith("talenet")) return ''
|
if (opts.renderTalenet == false && c.type.startsWith("talenet")) return ''
|
||||||
if (opts.renderFollow == false && c.type == "contact") return ''
|
if (opts.renderFollow == false && c.type == "contact") return ''
|
||||||
if (opts.renderAbout == false && c.type == "about") return ''
|
if (opts.renderAbout == false && c.type == "about") return ''
|
||||||
if (opts.renderPub == false && c.type == "pub") return ''
|
if (opts.renderPub == false && c.type == "pub") return ''
|
||||||
if (msg.author.publicWebHosting === false) return h('article', 'User has chosen not to be hosted publicly').outerHTML;
|
if (msg.author.publicWebHosting === false) return h('article', 'User has chosen not to be hosted publicly').outerHTML
|
||||||
if (msg.author.publicWebHosting == null && opts.requireOptIn) return h('article', 'User has not chosen to be hosted publicly').outerHTML;
|
if (msg.author.publicWebHosting == null && opts.requireOptIn) return h('article', 'User has not chosen to be hosted publicly').outerHTML
|
||||||
|
|
||||||
var name = encodeURIComponent(msg.key);
|
var name = encodeURIComponent(msg.key)
|
||||||
return h('article#' + name,
|
return h('article#' + name,
|
||||||
h('header',
|
h('header',
|
||||||
h('figure',
|
h('figure',
|
||||||
h('img', { alt: '',
|
h('img', { alt: '',
|
||||||
src: opts.img_base + msg.author.image,
|
src: opts.img_base + msg.author.image,
|
||||||
height: 50, width: 50 }),
|
height: 50, width: 50 }),
|
||||||
h('figcaption',
|
h('figcaption',
|
||||||
h('a.ssb-avatar-name',
|
h('a.ssb-avatar-name',
|
||||||
{ href: opts.base + escape(msg.value.author) },
|
{ href: opts.base + escape(msg.value.author) },
|
||||||
msg.author.name),
|
msg.author.name),
|
||||||
msgTimestamp(msg, opts.base + name), ' ',
|
msgTimestamp(msg, opts.base + name), ' ',
|
||||||
h('small', h('code', msg.key))
|
h('small', h('code', msg.key))
|
||||||
))),
|
))),
|
||||||
render(opts, id, c)).outerHTML;
|
render(opts, id, c)).outerHTML
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderRss(opts, msg) {
|
function renderRss(opts, msg) {
|
||||||
var c = msg.value.content || {};
|
var c = msg.value.content || {}
|
||||||
var name = encodeURIComponent(msg.key);
|
var name = encodeURIComponent(msg.key)
|
||||||
|
|
||||||
let content = h('div', render(opts, c)).innerHTML;
|
let content = h('div', render(opts, c)).innerHTML
|
||||||
|
|
||||||
if (!content) {
|
if (!content) return null
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
'<item>' +
|
'<item>' +
|
||||||
@@ -404,109 +402,109 @@ function renderRss(opts, msg) {
|
|||||||
'<pubDate>' + new Date(msg.value.timestamp).toUTCString() + '</pubDate>' +
|
'<pubDate>' + new Date(msg.value.timestamp).toUTCString() + '</pubDate>' +
|
||||||
'<guid>' + msg.key + '</guid>' +
|
'<guid>' + msg.key + '</guid>' +
|
||||||
'</item>'
|
'</item>'
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function msgTimestamp(msg, link) {
|
function msgTimestamp(msg, link) {
|
||||||
var date = new Date(msg.value.timestamp);
|
var date = new Date(msg.value.timestamp)
|
||||||
var isoStr = date.toISOString();
|
var isoStr = date.toISOString()
|
||||||
return h('time.ssb-timestamp',
|
return h('time.ssb-timestamp',
|
||||||
{ datetime: isoStr },
|
{ datetime: isoStr },
|
||||||
h('a',
|
h('a',
|
||||||
{ href: link,
|
{ href: link,
|
||||||
title: isoStr },
|
title: isoStr },
|
||||||
formatDate(date)));
|
formatDate(date)))
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
return htime(date);
|
return htime(date)
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(opts, id, c) {
|
function render(opts, id, c) {
|
||||||
var base = opts.base;
|
var base = opts.base
|
||||||
if (!c) return
|
if (!c) return
|
||||||
if (c.type === "post") {
|
if (c.type === 'post') {
|
||||||
var channel = c.channel
|
var channel = c.channel
|
||||||
? h('div.top-right',
|
? h('div.top-right',
|
||||||
h('a',
|
h('a',
|
||||||
{ href: base + 'channel/' + c.channel },
|
{ href: base + 'channel/' + c.channel },
|
||||||
'#' + c.channel))
|
'#' + c.channel))
|
||||||
: "";
|
: ''
|
||||||
return [channel, renderPost(opts, id, c)];
|
return [channel, renderPost(opts, id, c)]
|
||||||
} else if (c.type == "vote" && c.vote.expression == "Dig") {
|
} else if (c.type == 'vote' && c.vote.expression == 'Dig') {
|
||||||
var channel = c.channel
|
var channel = c.channel
|
||||||
? [' in ',
|
? [' in ',
|
||||||
h('a',
|
h('a',
|
||||||
{ href: base + 'channel/' + c.channel },
|
{ href: base + 'channel/' + c.channel },
|
||||||
'#' + c.channel)]
|
'#' + c.channel)]
|
||||||
: "";
|
: ''
|
||||||
var linkedText = "this";
|
var linkedText = 'this'
|
||||||
if (typeof c.vote.linkedText != "undefined")
|
if (typeof c.vote.linkedText != 'undefined')
|
||||||
linkedText = c.vote.linkedText.substring(0, 75);
|
linkedText = c.vote.linkedText.substring(0, 75)
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
['Liked ',
|
['Liked ',
|
||||||
h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText),
|
h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText),
|
||||||
channel]);
|
channel])
|
||||||
} else if (c.type == "vote") {
|
} else if (c.type == 'vote') {
|
||||||
var linkedText = "this";
|
var linkedText = 'this'
|
||||||
if (c.vote && typeof c.vote.linkedText === "string")
|
if (c.vote && typeof c.vote.linkedText === 'string')
|
||||||
linkedText = c.vote.linkedText.substring(0, 75);
|
linkedText = c.vote.linkedText.substring(0, 75)
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
['Voted ',
|
['Voted ',
|
||||||
h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText)]);
|
h('a', { href: base + encodeURIComponent(c.vote.link) }, linkedText)])
|
||||||
} else if (c.type == "contact" && c.following) {
|
} else if (c.type == 'contact' && c.following) {
|
||||||
var name = c.contact;
|
var name = c.contact
|
||||||
if (c.contactAbout)
|
if (c.contactAbout)
|
||||||
name = c.contactAbout.name;
|
name = c.contactAbout.name
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
['Followed ',
|
['Followed ',
|
||||||
h('a', { href: base + c.contact }, name)]);
|
h('a', { href: base + c.contact }, name)])
|
||||||
} else if (c.type == "contact" && !c.following) {
|
} else if (c.type == 'contact' && !c.following) {
|
||||||
var name = c.contact;
|
var name = c.contact
|
||||||
if (c.contactAbout)
|
if (c.contactAbout)
|
||||||
name = c.contactAbout.name;
|
name = c.contactAbout.name
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
['Unfollowed ',
|
['Unfollowed ',
|
||||||
h('a', { href: base + c.contact }, name)]);
|
h('a', { href: base + c.contact }, name)])
|
||||||
} else if (typeof c == "string") {
|
} else if (typeof c == 'string') {
|
||||||
return h('span.status', 'Wrote something private')
|
return h('span.status', 'Wrote something private')
|
||||||
} else if (c.type == "chess_move") {
|
} else if (c.type == 'chess_move') {
|
||||||
return h('span.status', 'Moved a chess piece')
|
return h('span.status', 'Moved a chess piece')
|
||||||
} else if (c.type == "chess_invite") {
|
} else if (c.type == 'chess_invite') {
|
||||||
return h('span.status', 'Started a chess game')
|
return h('span.status', 'Started a chess game')
|
||||||
}
|
}
|
||||||
else if (c.type == "about") {
|
else if (c.type == 'about') {
|
||||||
return [h('span.status', 'Changed something in about'),
|
return [h('span.status', 'Changed something in about'),
|
||||||
renderDefault(c)];
|
renderDefault(c)]
|
||||||
}
|
}
|
||||||
else if (c.type == "issue") {
|
else if (c.type == 'issue') {
|
||||||
return [h('span.status',
|
return [h('span.status',
|
||||||
"Created a git issue" +
|
'Created a git issue' +
|
||||||
(c.repoName ? " in repo " + c.repoName : ""),
|
(c.repoName ? ' in repo ' + c.repoName : ''),
|
||||||
renderPost(opts, id, c))];
|
renderPost(opts, id, c))]
|
||||||
}
|
}
|
||||||
else if (c.type == "git-repo") {
|
else if (c.type == 'git-repo') {
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
"Created a git repo " + c.name);
|
'Created a git repo ' + c.name)
|
||||||
}
|
}
|
||||||
else if (c.type == "git-update") {
|
else if (c.type == 'git-update') {
|
||||||
return h('div.status', "Did a git update " +
|
return h('div.status', 'Did a git update ' +
|
||||||
(c.repoName ? " in repo " + c.repoName : ""),
|
(c.repoName ? ' in repo ' + c.repoName : ''),
|
||||||
(Array.isArray(c.commits) ? h('ul',
|
(Array.isArray(c.commits) ? h('ul',
|
||||||
c.commits.filter(Boolean).map(com => {
|
c.commits.filter(Boolean).map(com => {
|
||||||
return h('li', String(com.title || com.sha1))
|
return h('li', String(com.title || com.sha1))
|
||||||
})
|
})
|
||||||
) : "")
|
) : '')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else if (c.type == "ssb-dns") {
|
else if (c.type == 'ssb-dns') {
|
||||||
return [h('span.status', 'Updated DNS'), renderDefault(c)];
|
return [h('span.status', 'Updated DNS'), renderDefault(c)]
|
||||||
}
|
}
|
||||||
else if (c.type == "pub") {
|
else if (c.type == 'pub') {
|
||||||
var host = c.address && c.address.host
|
var host = c.address && c.address.host
|
||||||
return h('span.status', 'Connected to the pub ' + host);
|
return h('span.status', 'Connected to the pub ' + host)
|
||||||
}
|
}
|
||||||
else if (c.type == "npm-packages") {
|
else if (c.type == 'npm-packages') {
|
||||||
return h('div.status', 'Pushed npm packages',
|
return h('div.status', 'Pushed npm packages',
|
||||||
Array.isArray(c.mentions) ? h('ul', c.mentions.map(function (link) {
|
Array.isArray(c.mentions) ? h('ul', c.mentions.map(function (link) {
|
||||||
var name = link && link.name
|
var name = link && link.name
|
||||||
@@ -515,38 +513,38 @@ function render(opts, id, c) {
|
|||||||
var [, name, version, tag] = m
|
var [, name, version, tag] = m
|
||||||
return h('li', name + ' v' + version + (tag ? ' (' + tag + ')' : ''))
|
return h('li', name + ' v' + version + (tag ? ' (' + tag + ')' : ''))
|
||||||
})) : ''
|
})) : ''
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
else if (c.type == "channel" && c.subscribed)
|
else if (c.type == 'channel' && c.subscribed)
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
'Subscribed to channel ',
|
'Subscribed to channel ',
|
||||||
h('a',
|
h('a',
|
||||||
{ href: base + 'channel/' + c.channel },
|
{ href: base + 'channel/' + c.channel },
|
||||||
'#' + c.channel));
|
'#' + c.channel))
|
||||||
else if (c.type == "channel" && !c.subscribed)
|
else if (c.type == 'channel' && !c.subscribed)
|
||||||
return h('span.status',
|
return h('span.status',
|
||||||
'Unsubscribed from channel ',
|
'Unsubscribed from channel ',
|
||||||
h('a',
|
h('a',
|
||||||
{ href: base + 'channel/' + c.channel },
|
{ href: base + 'channel/' + c.channel },
|
||||||
'#' + c.channel))
|
'#' + c.channel))
|
||||||
else if (c.type == "blog") {
|
else if (c.type == 'blog') {
|
||||||
//%RTXvyZ2fZWwTyWdlk0lYGk5sKw5Irj+Wk4QwxyOVG5g=.sha256
|
//%RTXvyZ2fZWwTyWdlk0lYGk5sKw5Irj+Wk4QwxyOVG5g=.sha256
|
||||||
var channel = c.channel
|
var channel = c.channel
|
||||||
? h('div.top-right',
|
? h('div.top-right',
|
||||||
h('a',
|
h('a',
|
||||||
{ href: base + 'channel/' + c.channel },
|
{ href: base + 'channel/' + c.channel },
|
||||||
'#' + c.channel))
|
'#' + c.channel))
|
||||||
: "";
|
: ''
|
||||||
|
|
||||||
var s = h('section');
|
var s = h('section')
|
||||||
s.innerHTML = marked(String(c.blogContent), opts.marked)
|
s.innerHTML = marked(String(c.blogContent), opts.marked)
|
||||||
|
|
||||||
return [channel, h('h2', String(c.title)), s];
|
return [channel, h('h2', String(c.title)), s]
|
||||||
}
|
}
|
||||||
else if (c.type === 'gathering') {
|
else if (c.type === 'gathering') {
|
||||||
return h('div', renderGathering(opts, id, c))
|
return h('div', renderGathering(opts, id, c))
|
||||||
}
|
}
|
||||||
else return renderDefault(c);
|
else return renderDefault(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderGathering(opts, id, c) {
|
function renderGathering(opts, id, c) {
|
||||||
@@ -567,28 +565,28 @@ function renderGathering(opts, id, c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function renderPost(opts, id, c) {
|
function renderPost(opts, id, c) {
|
||||||
opts.mentions = {};
|
opts.mentions = {}
|
||||||
if (Array.isArray(c.mentions)) {
|
if (Array.isArray(c.mentions)) {
|
||||||
c.mentions.forEach(function (link) {
|
c.mentions.forEach(function (link) {
|
||||||
if (link && link.name && link.link)
|
if (link && link.name && link.link)
|
||||||
opts.mentions[link.name] = link.link;
|
opts.mentions[link.name] = link.link
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
var s = h('section');
|
var s = h('section')
|
||||||
var content = '';
|
var content = ''
|
||||||
if (c.root && c.root != id)
|
if (c.root && c.root != id)
|
||||||
content += 'Re: ' + h('a',
|
content += 'Re: ' + h('a',
|
||||||
{ href: '/' + encodeURIComponent(c.root) },
|
{ href: '/' + encodeURIComponent(c.root) },
|
||||||
c.root.substring(0, 10)).outerHTML + '<br>';
|
c.root.substring(0, 10)).outerHTML + '<br>'
|
||||||
s.innerHTML = content + marked(String(c.text), opts.marked);
|
s.innerHTML = content + marked(String(c.text), opts.marked)
|
||||||
return s;
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderDefault(c) {
|
function renderDefault(c) {
|
||||||
return h('pre', JSON.stringify(c, 0, 2));
|
return h('pre', JSON.stringify(c, 0, 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderShowAll(showAll, url) {
|
function renderShowAll(showAll, url) {
|
||||||
if (!showAll)
|
if (!showAll)
|
||||||
return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML;
|
return '<br>' + h('a', { href : url + '?showAll' }, 'Show whole feed').outerHTML
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user