-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.html
254 lines (197 loc) · 5.9 KB
/
index.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>bye-bye-feedly</title>
<style>
html,
body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-smoothing: antialiased;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica,
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-size: 1em;
line-height: 1.6;
color: #333;
}
main {
overflow: auto;
height: 100%;
}
.content-container {
max-width: 45em;
margin: 0 auto;
}
.text-gray { color: #999; }
/* Article list */
.list {
max-width: 45em;
margin: 0 auto;
padding-left: 0;
}
.list__item {
padding: .5em 1em;
list-style: none;
cursor: pointer;
}
.list__item:hover { background-color: rgba(238,238,238,.6); }
/* Article view */
article { padding-top: 2.5em; }
.overlay {
display: none;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 1;
background-color: #fff;
}
.overlay__content {
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
height: 100%;
padding: 0 1em 1em;
}
.title { padding-left: 1rem; }
.button {
padding: .25em .5em;
text-decoration: none;
color: #ccc;
border: 1px solid #eee;
border-radius: 4px;
}
.button--back {
position: fixed;
top: 1em;
left: 1em;
}
img,
iframe {
max-width: 100%;
height: auto;
}
p { word-wrap: break-word; }
pre { white-space: pre-wrap; }
/* Desktop */
@media only screen and (min-width: 56em) {
article,
.overlay__content { padding: 0; }
.button { padding: .5em 1em; }
.list__item { padding: 1em; }
}
</style>
</head>
<body>
<main>
<div class="content-container">
<h1 class="title">Articles <span id="js-total-articles"></span></h1>
<ul id="js-list" class="list"></ul>
</div>
<div id="js-article" class="overlay">
<div class="overlay__content">
<a href="#" class="button button--back" onclick="closeContent()">esc</a>
<article class="content-container">
<h1 id="js-article-title"></h1>
<h5 id="js-article-meta" class="text-gray"></h5>
<div id="js-article-content"></div>
</article>
</div>
</div>
</main>
<script type="text/javascript">
var data;
var request = new XMLHttpRequest();
request.open('GET', 'data.json', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
data = JSON.parse(request.responseText);
document.getElementById('js-total-articles').innerHTML = '(' + data.items.length + ')';
data.items.reverse(); // Conserve permalinks on new items
renderArticleList(data);
// If permalink, instantly get article
var urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('id')) getArticle(urlParams.get('id'));
} else {
console.log('Error: Server returned status code >> ' + request.status)
}
};
request.onerror = function() {
console.log('Connection error')
};
request.send();
function renderArticleList(data) {
var articleList = '';
for(var i = data.items.length; i--;) {
var published = new Date(data.items[i].published);
articleList += '<li class="list__item" onclick="getArticle(' + i + ')">\
<h3>' + data.items[i].title +'</h3>\
<h5 class="text-gray">' + data.items[i].origin.title + ' · \
<date>' + published.toDateString() + '</date></h5></li>';
}
document.getElementById('js-list').innerHTML = articleList;
}
function closeContent() {
document.body.style.overflow = "initial";
document.getElementById('js-article').style.display = 'none';
}
function getArticle(id) {
var article = data.items[id];
// Get full content, if available
if ('content' in article) {
var text = article.content.content;
} else if ('summary' in article) {
var text = article.summary.content;
} else {
var text = 'No content';
}
// Get the right source URL
if ('canonical' in article) {
var source = article.canonical[0].href;
} else if ('alternate' in article) {
var source = article.alternate[0].href;
} else {
var source = '?id=' + id;
console.log('URL for "' + article.title + '" not found, using bye-bye permalink instead.');
}
var published = new Date(article.published);
var meta = article.origin.title + ' · <date>' + published.toDateString() + '</date> \
· <a href="?id=' + id + '">Permalink</a>';
document.body.style.overflow = 'hidden'; // Better overlay scrolling
document.getElementById('js-article').style.display = 'block';
document.getElementById('js-article-title').innerHTML = '\
<a href="' + source + '" target="_blank" rel="noopener">' + article.title + '</a>';
document.getElementById('js-article-meta').innerHTML = meta;
document.getElementById('js-article-content').innerHTML = text;
// Keyboard shortcuts: Article view
document.onkeydown = function(e) {
e = e || window.event;
// esc: close article
if (e.keyCode == 27) {
closeContent();
// k: newer article, back to article list on end
} else if (e.keyCode == 75 && id < data.items.length) {
id++;
id === data.items.length ? closeContent() : getArticle(id);
// j: older article, back to article list on end
} else if (e.keyCode == 74 && id >= 0) {
id--;
id < 0 ? closeContent() : getArticle(id);
}
};
}
// Keyboard shortcuts: List view
window.onkeydown = function(e) {
e = e || window.event;
// o: open newest article
if (e.keyCode == 79) getArticle(data.items.length-1);
};
</script>
</body>
</html>