-
Notifications
You must be signed in to change notification settings - Fork 1
/
blog.html
144 lines (125 loc) · 3.97 KB
/
blog.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
<!doctype html>
<html><head>
<title>Your Yamemex Annotations</title>
<style>
/* New stylesheet inspired by the one on <http://worrydream.com/KillMath/>
*/
@font-face {
font-family: "CandalRegular";
src: url('Candal/Candal.ttf') format('truetype');
}
body {
background: url('write-big-gray.png') top left no-repeat;
background-attachment: fixed;
margin: 0 auto;
padding: 0;
font: 13px Optima, Helvetica, Arial, sans-serif;
color: #555;
width: 50em;
}
h1, h2 {
font-family: "CandalRegular";
font-weight: normal;
text-align: center;
color: #600;
padding: 0;
}
h1 {
font-size: 2em;
margin-top: 1.57em;
}
h2 {
font-size: 1.5em;
margin-top: 2em;
}
ul, li { margin: 0; padding: 0 }
ul { list-style-type: none }
li { margin-top: 1em; margin-bottom: 1em; line-height: 1.7 }
a { color: #933 }
</style>
<script src="jquery-1.5.2.min.js"></script>
<script src="mustache/mustache.js"></script>
<script src="db.js"></script>
<script>
$(renderPage);
var template =
'{{#sections}}' +
'<h2>{{date}}</h2>' +
' <ul>' +
' {{#bookmarks}}' +
' <li><a href="{{url}}">{{title}}</a> ' +
' <span class="annotation">{{{annotation}}}</span>' +
' </li>' +
' {{/bookmarks}}' +
' </ul>' +
'{{/sections}}' ;
function tags(text) {
return text.match(/#\w+/g) || [];
}
function contains(item, list) {
for (var ii = 0; ii < list.length; ii++) {
if (item === list[ii]) return true;
}
return false;
}
function taggify(text) {
return text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/(#\w+)/g, function(tag) {
var param = encodeURIComponent(tag);
return '<a href="?'+param+'">'+tag+'</a>';
})
;
}
function renderPage() {
if (location.search) {
var tag = decodeURIComponent(location.search.substr(1));
$('.forwhat').text(' for '+tag);
document.title = $('h1').text();
renderBlog(tag);
} else {
renderBlog(null);
}
}
function renderBlog(tag) {
var start = new Date();
sql( 'select *, date(timestamp) as date from annotations ' +
'order by timestamp desc'
, []
, function(t, results) {
var sections = [];
var section = { };
for (var ii = 0; ii < results.rows.length; ii++) {
var row = results.rows.item(ii);
if (tag && !contains(tag, tags(row.annotation))) {
continue;
}
if (row.date !== section.date) {
section = { date: row.date, bookmarks: [] };
sections.push(section);
}
section.bookmarks.push({ url: row.url
, title: row.title || '<link>'
, annotation: taggify(row.annotation)
});
}
$('#entries').html(Mustache.to_html(template,
{sections: sections}));
var end = new Date();
$('<p/>')
.text( 'Rendering '+results.rows.length
+ ' items took '
+ ((end.getTime() - start.getTime())/1000)
+ ' seconds.'
)
.appendTo($('body'))
;
}
);
}
</script>
</head><body>
<h1>Your Yamemex Annotations<span class="forwhat"></span></h1>
<div id="entries"></div>
</body></html>