-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreading.html
More file actions
77 lines (63 loc) · 1.94 KB
/
reading.html
File metadata and controls
77 lines (63 loc) · 1.94 KB
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
---
title: "I Recently Liked..."
layout: default
permalink: /reading/
description: "A list of the last few articles I enjoyed reading"
---
<p>Articles I enjoyed reading.</p>
<p id="feed"></p>
<a href="https://www.instapaper.com/p/jgmalcolm">See more articles...</a>
<script>
$(document).ready(function(){
var url = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vThZKXzN43Nea5uifoE_lDEJnXJ3D1mgoxz-baeJe2lZeaKW3fTKqYXkoPhZaXxkMytdNRlHFh-rCfF/pub?gid=0&single=true&output=csv';
function hostname(url) {
var matches = url.match(/^https?\:\/\/(www\.)?([^\/?#]+)(?:[\/?#]|$)/i);
return matches[2];
}
function parseCSV(text) {
var rows = [];
var lines = text.trim().split('\n');
lines.forEach(function(line) {
var cols = [];
var inQuote = false;
var cur = '';
for (var i = 0; i < line.length; i++) {
var c = line[i];
if (c === '"') {
inQuote = !inQuote;
} else if (c === ',' && !inQuote) {
cols.push(cur);
cur = '';
} else {
cur += c;
}
}
cols.push(cur);
rows.push(cols);
});
return rows;
}
fetch(url)
.then(function(r) { return r.text(); })
.then(function(csv) {
var rows = parseCSV(csv);
var headers = rows[0].map(function(h) { return h.toLowerCase().trim(); });
var urlIdx = headers.indexOf('url');
var titleIdx = headers.indexOf('title');
var excerptIdx = headers.indexOf('excerpt');
var feed = '';
rows.slice(1).reverse().forEach(function(cols) {
var href = cols[urlIdx] || '';
var title = cols[titleIdx] || '';
var excerpt = cols[excerptIdx] || '';
if (!href || !title) return;
var quote = '';
if (excerpt && !/\u2026$/.test(excerpt))
quote = '<br>"' + excerpt + '"';
feed += '<p><b><a href="' + href + '">' + title + '</a></b>'
+ ' <i>@' + hostname(href) + '</i>' + quote + '</p>';
});
$('#feed').append(feed);
});
}); /* ready */
</script>