-
Notifications
You must be signed in to change notification settings - Fork 0
/
snips.html
29 lines (26 loc) · 914 Bytes
/
snips.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>snips</title>
</head>
<body style="display: grid; justify-items: center">
<script type="module">
const renderSnip = (text = '') =>
`<div><pre><code>${text
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')}</code></pre> </div> <br />`;
const query = decodeURI(
new URL(window.location.href).searchParams.get('search') || '',
).toLowerCase();
const snips = await fetch('../public/data/snips.json').then((res) => res.json());
if (query) {
const filteredSnips = snips.filter((snip) => snip.toLowerCase().includes(query));
document.body.innerHTML = filteredSnips.map(renderSnip).join('\n');
} else {
document.body.innerHTML = snips.map(renderSnip).join('\n');
}
</script>
</body>
</html>