/
index.html
217 lines (186 loc) · 5.72 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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Hubticle : Make a blog with your GitHub repository</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="./app/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="./app/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="./app/async.js"></script>
<script type="text/javascript" src="./app/json2.js"></script>
<script type="text/javascript" src="./app/underscore-min.js"></script>
<script type="text/javascript" src="./app/backbone-min.js"></script>
<script type="text/javascript" src="./app/base64.js"></script>
<script type="text/javascript" src="./app/showdown.js"></script>
<script src="http://scripts.embed.ly/jquery.embedly.min.js"></script>
<script type="text/javascript">
var hubticle = {}
hubticle.settings = {};
hubticle.settings.apiUrl = 'https://api.github.com';
hubticle.settings.pageCapacity = 5;
hubticle.settings.user = 'hubticle'; // setting user name
hubticle.settings.repo = 'hubticle.github.com'; // setting repo name
hubticle.settings.embedlyApiKey = '1a76167c734511e193c14040d3dc5c07';
</script>
</head>
<body>
<div class="container">
<div id="header">
<h1><a href="/">Hubticle</a></h1>
<p class="lead">Make a blog with your GitHub repository</p>
</div>
<div id="posts">
</div>
<div id="steps">
<div id="steps_prev"></div>
<div id="steps_next"></div>
</div>
<div id="footer">
</div>
</div>
<style>
.container {
margin: 0 auto;
width: 500px;
}
#header {
margin: 10px 0px 50px 0px;
}
#header > h1 {
margin: 10px 0px 20px 0px;
font-size: 54px;
}
.post {
margin: 10px 0px 20px 0px;
border-bottom: 1px solid #EEEEEE;
}
.post > .content > h1 {
margin: 10px 0px 10px 0px;
}
#steps_next {
font-family: Monaco, Courier, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
}
#steps_prev {
font-family: Monaco, Courier, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
}
body {
font-family: Monaco, Courier, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
}
p {
font-family: Monaco, Courier, "DejaVu Sans Mono", "Bitstream Vera Sans Mono", monospace;
}
</style>
<script type="text/javascript">
var markdown = new Showdown.converter();
hubticle.postView = function(path, content) {
var view = '<div class="post"><div class="content">#{content}</div><div class="path"><a href="/#/posts/#{path}">#{path}</a></div></div>';
view = view.replace('#{path}', path);
view = view.replace('#{path}', path);
view = view.replace('#{content}', markdown.makeHtml(content));
return view;
}
hubticle.setItem = function(path, url, callback) {
var apiCall = {
url: hubticle.settings.apiUrl, dataType: 'jsonp', data: null, success: null, error: function() {alert('error');}
}
apiCall.url = url;
apiCall.success = function(data) {
var content = data.data.content;
content = data.data.content.replace(/\r\n/g, '').replace(/\n/g, '');
$('#posts').append(hubticle.postView(path, Base64.decode(content)));
callback();
};
$.ajax(apiCall);
}
hubticle.setList = function(articleId, pageNum) {
$('#posts').empty();
var apiCall = {
url: hubticle.settings.apiUrl, dataType: 'jsonp', data: null, success: null, error: function() {alert('error');}
}
apiCall.url = apiCall.url + '/repos/' + hubticle.settings.user + '/' + hubticle.settings.repo + '/git/trees/master';
apiCall.success = function(data) {
var fileList = [];
for (var i = 0; i < data.data.tree.length; i++) {
if (data.data.tree[i]['path'].match(/^.*\.markdown$/)) {
fileList.push(data.data.tree[i]);
}
}
fileList = fileList.sort(function(a, b) {return a['path'] < b['path'] ? 1 : -1;});
var q = async.queue(
function(task, callback) {
hubticle.setItem(task.path, task.url, callback);
},
1
);
var sIndex = 0;
if (pageNum != null) {
sIndex = pageNum * hubticle.settings.pageCapacity;
}
var eIndex = fileList.length;
if (pageNum != null) {
eIndex = pageNum * hubticle.settings.pageCapacity + hubticle.settings.pageCapacity;
}
for (var i = sIndex; i < fileList.length && i < eIndex; i++) {
if ((articleId != null && articleId == fileList[i]['path']) || (articleId == null)) {
q.push(fileList[i]);
}
}
q.drain = function() {
$('a').embedly({key: hubticle.settings.embedlyApiKey});
}
if (pageNum != null) {
if (sIndex != 0) {
$('#steps_prev').empty();
$('#steps_prev').append('<a href="#/page/' + (parseInt(pageNum) - 1) + '">prev</a>');
}
else {
$('#steps_prev').empty();
$('#steps_prev').append('<span>prev</span>');
}
} else {
$('#steps_prev').empty();
}
if (pageNum != null) {
if (eIndex < fileList.length) {
$('#steps_next').empty();
$('#steps_next').append('<a href="#/page/' + (parseInt(pageNum) + 1) + '">next</a>');
}
else {
$('#steps_next').empty();
$('#steps_next').append('<span>next</span>');
}
} else {
$('#steps_next').empty();
}
};
$.ajax(apiCall);
}
hubticle.AppRouter = Backbone.Router.extend({
routes: {
'': 'index',
'/posts/:id': 'archivesByItem',
'/page/:pageNum': 'archivesByPage'
},
index: function() {
var id = null;
var pageNum = 0;
hubticle.setList(id, pageNum);
},
archivesByItem: function(id) {
var id = id;
var pageNum = null;
hubticle.setList(id, pageNum);
},
archivesByPage: function(pageNum) {
var id = null;
var pageNum = pageNum;
hubticle.setList(id, pageNum);
}
});
$(function() {
new hubticle.AppRouter();
Backbone.history.start();
});
</script>
</body>
</html>