-
Notifications
You must be signed in to change notification settings - Fork 34
/
index.html
131 lines (119 loc) · 4.08 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
<!doctype html>
<html>
<head>
<title>Issuance</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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="https://fonts.googleapis.com/css?family=PT+Serif">
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
<script type="module">
import { React, ReactDOM } from 'https://unpkg.com/[email protected]/dev';
import htm from 'https://unpkg.com/htm?module'
import { endpoint } from 'https://cdn.skypack.dev/@octokit/endpoint';
import marked from 'https://unpkg.com/[email protected]/lib/marked.esm.js';
const html = htm.bind(React.createElement)
const Header = (props) => {
return html`
<div className="header">
<h1 className="title">
<a href="index.html"><strong>issuance</strong></a>
</h1>
<p className="description">
Open, free blogging on <strong>Github pages</strong> with <strong>Github issues</strong>.
</p>
</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: "mateogianolio",
repo: "issuance",
auth: 'x'
});
const res = await fetch(url, options);
setIssues(await res.json());
}
}
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} comment(s)
</a>
`
: null
}
</div>
<div
className="body"
dangerouslySetInnerHTML="${{ __html: marked(body).replace(/<pre>/g, '<pre class="prettyprint">')}}"
/>
</div>
`)}
</div>
`
}
ReactDOM.render(
html`
<${Header} />
<${Posts} />
`,
document.querySelector('#issuance')
)
</script>
</head>
<body>
<div id="issuance" />
</body>
</html>