UX: strip outgoing links from bottom of post.
Only show incoming
This commit is contained in:
parent
3015030fe2
commit
30e4b17de8
|
@ -20,37 +20,42 @@ export default createWidget('post-links', {
|
||||||
|
|
||||||
return h('li',
|
return h('li',
|
||||||
h('a.track-link', {
|
h('a.track-link', {
|
||||||
className: link.reflection ? 'inbound' : 'outbound',
|
className: 'inbound',
|
||||||
attributes: { href: link.url }
|
attributes: { href: link.url }
|
||||||
}, [iconNode(link.reflection ? 'arrow-left' : 'arrow-right'), linkBody])
|
}, [iconNode('arrow-left'), linkBody])
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
html(attrs, state) {
|
html(attrs, state) {
|
||||||
const links = this.attrs.links || [];
|
if (!this.attrs.links || this.attrs.links.length == 0) {
|
||||||
const dedupedLinks = _.uniq(links, true, l => l.title);
|
// shortcut all work
|
||||||
const incomingLinks = dedupedLinks.filter(l => l.reflection);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if all links are outgoing, don't show any
|
// only show incoming
|
||||||
if (incomingLinks.length === 0) { return; }
|
const links = _(this.attrs.links)
|
||||||
|
.filter(l => l.reflection)
|
||||||
|
.uniq(true, l => l.title)
|
||||||
|
.value();
|
||||||
|
|
||||||
|
if (links.length === 0) { return; }
|
||||||
|
|
||||||
const result = [];
|
const result = [];
|
||||||
|
|
||||||
// show all links
|
// show all links
|
||||||
if (dedupedLinks.length <= 5 || !state.collapsed) {
|
if (links.length <= 5 || !state.collapsed) {
|
||||||
_.each(dedupedLinks, l => result.push(this.linkHtml(l)));
|
_.each(links, l => result.push(this.linkHtml(l)));
|
||||||
} else {
|
} else {
|
||||||
// show up to 5 *incoming* links when collapsed
|
const max = Math.min(5, links.length);
|
||||||
const max = Math.min(5, incomingLinks.length);
|
|
||||||
for (let i = 0; i < max; i++) {
|
for (let i = 0; i < max; i++) {
|
||||||
result.push(this.linkHtml(incomingLinks[i]));
|
result.push(this.linkHtml(links[i]));
|
||||||
}
|
}
|
||||||
// 'show more' link
|
// 'show more' link
|
||||||
if (dedupedLinks.length > max) {
|
if (links.length > max) {
|
||||||
result.push(h('li', this.attach('link', {
|
result.push(h('li', this.attach('link', {
|
||||||
labelCount: 'post_links.title',
|
labelCount: 'post_links.title',
|
||||||
title: 'post_links.about',
|
title: 'post_links.about',
|
||||||
count: dedupedLinks.length - max,
|
count: links.length - max,
|
||||||
action: 'expandLinks',
|
action: 'expandLinks',
|
||||||
className: 'expand-links'
|
className: 'expand-links'
|
||||||
})));
|
})));
|
||||||
|
|
Loading…
Reference in New Issue