forked from mateogianolio/issuance
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
206 lines (183 loc) · 7.09 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
<!doctype html>
<html>
<head>
<title>Casual JavaScript</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="A collection of short and informative programming articles written in JavaScript. 100% open-source.">
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="css/structure.css">
<link rel="stylesheet" type="text/css" href="css/typography.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<!-- <link rel="stylesheet" type="text/css" href="css/prettify.css"> -->
<link href='https://fonts.googleapis.com/css?family=PT+Serif:400,400i,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=PT+Sans:700' rel='stylesheet' type='text/css'>
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/themes/prism.min.css" rel="stylesheet" />
<script src="https://buttons.github.io/buttons.js"></script>
<script type="module">
import { React, ReactDOM } from 'https://unpkg.com/es-react@16.12.0/dev';
import htm from 'https://unpkg.com/htm?module'
import { endpoint } from 'https://cdn.skypack.dev/@octokit/endpoint';
import marked from 'https://unpkg.com/marked@0.8.0/lib/marked.esm.js';
const html = htm.bind(React.createElement);
const Header = (props) => {
return html`
<div className="header">
<a className="logo" href="https://casualjavascript.com">Casual JavaScript</a>
<div className="follow">
<a className="github-button" href="https://github.com/casualjavascript/blog" data-icon="octicon-star" data-size="large" data-show-count="true" aria-label="Star casualjavascript/blog on GitHub">Star</a>
<br />
<a className="github-button" href="https://github.com/casualjavascript/blog/subscription" data-icon="octicon-eye" data-size="large" data-show-count="true" aria-label="Watch casualjavascript/blog on GitHub">Watch</a>
</div>
</div>
`;
}
const Comments = (props) => {
const [comments, setComments] = React.useState();
const {
search,
} = window.location;
React.useEffect(() => {
async function fetchComments() {
const issue_number = search.slice(1);
if (issue_number && !comments) {
const { url, ...options } = endpoint('GET /repos/:owner/:repo/issues/:issue_number/comments', {
owner: 'casualjavascript',
repo: 'blog',
issue_number,
});
console.log(options);
const res = await fetch(url, options);
setComments(await res.json());
Prism.highlightAll();
}
}
fetchComments();
}, [search, comments]);
return html`
<div id="comments" className="comments">
<h1>Comments</h1>
${(comments || [])
.map(({
id,
user: {
html_url,
login,
},
created_at,
body,
}) => html`
<div key=${id} className="comment">
<a className="author" href="${html_url}">
${login}
</a>
<span className="date">
${'commented '}
${new Date(created_at).toLocaleDateString()} ${new Date(created_at).toLocaleTimeString()}:
</span>
<div
className="body"
dangerouslySetInnerHTML="${{ __html: marked(body)}}"
/>
</div>
`)}
</div>
`;
}
const Posts = (props) => {
const [issues, setIssues] = React.useState();
React.useEffect(() => {
async function fetchIssues() {
if (!issues) {
const { url, ...options } = endpoint('GET /repos/:owner/:repo/issues', {
owner: 'casualjavascript',
repo: 'blog',
});
const res = await fetch(url, options);
setIssues(await res.json());
Prism.highlightAll();
}
}
fetchIssues();
}, [issues]);
const {
search,
} = window.location;
return html`
<div className="posts">
${(issues || [])
.filter(({ user }) => user.login === 'mateogianolio')
.filter(({ number }) => !search || Number(search.slice(1)) === number)
.map(({
number,
title,
labels,
user,
created_at,
comments,
body,
}) => html`
<div
className="post"
id={${number}}
key={${number}}
>
<h1 className="title">
<a href="?${number}">
${title}
</a>
</h1>
${labels.length > 0 && html`
<div className="categories">
in
${labels.map((label) => html`
<span
key="${label.id}"
style=${{ color: '#' + label.color, padding: '0 .25em' }}
>
${label.name}
</span>
`)}
</div>
`}
<div className="meta">
<span>by </span>
<a href="${user.html_url}">${user.login}</a>
<span>, </span>
<span>${new Date(created_at).toLocaleDateString()} </span>
${comments
? html`
<a href="?${number}#comments">
${comments} comment(s)
</a>
`
: null
}
</div>
${search && Number(search.slice(1)) === number && html`
<div
className="body"
dangerouslySetInnerHTML="${{ __html: marked(body)}}"
/>
<${Comments} />
`}
</div>
`)}
</div>
`;
};
ReactDOM.render(
html`
<${Header} />
<${Posts} />
`,
document.querySelector('#issuance')
)
</script>
</head>
<body>
<div id="issuance">
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.20.0/plugins/autoloader/prism-autoloader.min.js"></script>
</body>
</html>