-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
85 lines (76 loc) · 2.46 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
<!DOCTYPE html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Les catégories de data-truc</title>
<style>
.boite{
display: flex;
flex-direction: row;
}
.categorie{
flex-grow: 1;
height: 7em;
border: 1px solid black;
}
.fiche{
flex-grow: 1;
border: 1px solid black;
margin: auto;
}
</style>
<div class="boite">
<ul class=categorie></ul>
<section class=fiche></section>
<template name=categorie>
<li><a data-tpl=categorie><span data-tpl=count></span></a></li>
</template>
<template name=fiche>
<h1><a data-tpl=title></a></h1>
<p data-tpl=description></p>
<ul>
<li data-tpl=licence></li>
<li data-tpl=author></li>
</ul>
<img data-tpl=image_url>
</template>
</div>
<script type="text/javascript">
const listen = evt => {
const container = document.querySelector('template[name=fiche]').cloneNode(true).content
container.querySelector('[data-tpl=title]').append(document.location.hash.replace('#', ''))
document.querySelector('.fiche').append(container)
}
window.addEventListener('hashchange', listen)
const uniq = array => array.filter((elt, pos, arr) => arr.indexOf(elt) === pos).sort()
const occurence = (array, key) => array.filter(item => item === key).length
//const createFiches
const createCategories = (allCategories, categorie) => {
const container = document.querySelector('template[name=categorie]').cloneNode(true).content
const a = container.querySelector('[data-tpl=categorie]')
const span = container.querySelector('[data-tpl=count]')
const ficheDesc = container.querySelector('[data-tpl=description]')
const licence = container.querySelector('[data-tpl=licence]')
const author = container.querySelector('[data-tpl=author]')
span.append(occurence(allCategories, categorie))
a.href = '#' + categorie
a.append(categorie)
/*
ficheDesc.innerHTML =
licence.innerHTML =
author.innerText =
*/
return container
}
fetch('http://api.daktary.com/infolab-cd33/datalunch/tree/master/fiches')
.then(response => response.json())
.then(fiches => {
//console.log(datatrucs.body);
const allCategories = fiches.body
.filter(fiche =>fiche.meta)
.map(fiche =>fiche.meta.categorie)
uniq(allCategories).map(categorie => {
document.querySelector('.categorie').append(createCategories(allCategories, categorie))
})
})
</script>