-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathperfplanet.js
executable file
·94 lines (91 loc) · 2.81 KB
/
perfplanet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var pipe = 'data.js';
var s = document.createElement('script');
s.src = pipe;
document.documentElement.firstChild.appendChild(s);
s.onload = function render(o) {
var items = null,
r = document.getElementById('blogs'),
i = 0,
b = null,
cats = [],
categories = '',
html = '',
author = '',
meta = [];
r.innerHTML = '';
try {
items = data;
} catch (e) {
r.innerHTML =
'<p>failed to retrieve blog posts, please refresh the page to try again.</p>';
}
for (i = 0; i < items.length; i++) {
b = items[i];
html +=
'<div class="blogpost"><h2 class="title"><a href="' +
b.link +
'">' +
(b.title || b['y:title']) +
'</a></h2>';
meta = [];
var a = document.createElement('a');
a.href = b.link;
meta.push('From: ' + a.hostname);
author = '';
if (b['dc:creator']) {
author = b['dc:creator'];
} else if (b.author && b.author.name) {
author = b.author.name;
} else if (typeof b.author === 'string') {
author = b.author;
} else if (typeof b.creator === 'string') {
author = b.creator;
} else if (b.author && typeof b.author.join === 'function') {
author = b.author.join(', ');
}
if (author) {
meta.push('Author: ' + author);
}
meta.push('Published: ' + b.pubDate);
if (b.category) {
if (typeof b.category.join === 'function') {
if (b.category[0] && (b.category[0].term || b.category[0].content)) {
cats = [];
for (j = 0; j < b.category.length; j++) {
cats[j] = b.category[j].term || b.category[j].content;
}
categories = cats.join(', ');
} else {
categories = b.category.join(', ');
}
} else {
categories = b.category;
}
if (categories) {
meta.push('Filed in: ' + categories);
}
}
html += '<ul><li>' + meta.join('</li><li>') + '</li></ul>';
html += b.description;
html += '<div class="sharing">';
html +=
'<a target="_blank" rel="noopener noreferrer" href="https://twitter.com/intent/tweet?via=perfplanet&url=' +
encodeURIComponent(b.link) +
'">Tweet</a>';
html +=
'<a target="_blank" rel="noopener noreferrer" href="https://www.facebook.com/sharer/sharer.php?u=' +
encodeURIComponent(b.link) +
'">Facebook</a>';
html +=
'<a target="_blank" rel="noopener noreferrer" href="https://www.linkedin.com/sharing/share-offsite/?url=' +
encodeURIComponent(b.link) +
'">LinkedIn</a>';
if (navigator.clipboard) {
html += '<a href="javascript:navigator.clipboard.writeText(\''+encodeURIComponent(b.link)+'\')">Copy URL</a>';
}
html += '</div>';
html += '<div class="ornament">☆ <b>☆</b> <i>☆</i></div>';
html += '</div>';
}
r.innerHTML = html;
};