-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (49 loc) · 1.44 KB
/
index.js
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
import {unified} from 'unified';
import remarkGfm from 'remark-gfm';
import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import rehypeStringify from 'rehype-stringify';
function component() {
let md;
const element = document.createElement('div');
if (window.location.pathname !== '/') {
import(`.${window.location.pathname}/index.js`);
md = import(`.${window.location.pathname }/readme.md`);
md.then(file => {
unified()
.use(remarkParse)
.use(remarkGfm)
.use(remarkRehype)
.use(rehypeStringify)
.process(file.default)
.then((html) => {
element.innerHTML = html;
});
}).catch(e => {
element.innerHTML = '<p>This kata kata has no description.</p>';
})
} else {
console.log('here')
//
fetch('https://api.github.com/repos/PRO100Spike/codewars-training/contents')
.then((response) => {
return response.json();
})
.then((data) => {
const ul = document.createElement('ul');
element.appendChild(ul);
data.map(el => {
if (el.type === "dir") {
let li = document.createElement('li');
let a = document.createElement('a');
a.href = `/${el.name}`
a.append(el.name);
li.appendChild(a);
ul.appendChild(li);
}
})
});
}
return element;
}
document.body.appendChild(component());