forked from la-contree/baseline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
176 lines (140 loc) · 3.52 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
<!DOCTYPE html>
<html lang="fr">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script crossorigin="anonymous" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.2/moment.js"></script>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
color: black;
}
#events {
position: relative;
border-left: 2px solid #111;
}
#events:before {
content: '';
position: absolute;
top: -6px;
left: -12px;
width: 0;
height: 0;
border-left:12px solid transparent;
border-right: 12px solid transparent;
border-bottom: 12px solid #111;
}
#events article {
display: flex;
margin-bottom: 2rem;
}
#events article::before {
content: '';
display: inline-block;
width: 4rem;
height: 2px;
margin-top: 1rem;
background-color: #111;
}
#events .card {
width: 400px;
border: 1px solid #aaa;
border-radius: 4px;
display: block;
padding: 2rem;
color: #000;
text-decoration: none;
}
#events a h2 {
text-decoration: underline;
transition: color 0.3s ease-in-out;
}
#events a:hover h2 {
color: red;
}
#events h2 {
margin: 0 0 1.5rem;
}
#events time:nth-of-type(2)::before {
content: '-';
margin: 0 .5rem;
}
#events ul {
display: flex;
flex-wrap: wrap;
margin: 1rem 0;
padding: 0;
list-style-type: none;
}
#events li {
padding: 5px;
border-radius: 3px;
background-color: #ccc;
}
#events li:not(:first-child) {
margin-left: .5rem;
}
#events p {
margin: 0;
}
</style>
<title>Document</title>
<h1>Fraise chronophagique</h1>
<section id="events">
</section>
<script>
'use strict';
const renderEvents = () => {
const container = document.querySelector('#events');
fetch('https://api.daktary.com/dtc-innovation/baseline/tree/master/events')
.then(response => response.json())
.then(events => {
events.body.sort((e1,e2) => {
return new Date(e2.meta['date-start']).getTime() - new Date(e1.meta['date-start']).getTime()
}).forEach(event => {
const article = TimelineEvent(event);
container.append(article);
});
});
};
const TimelineEvent = (event) => {
const article = document.createElement('article');
const buzzer = document.createElement(event.meta.url ? 'a' : 'div');
if (event.meta.url) {
buzzer.href = event.meta.url;
}
buzzer.classList.add('card');
const title = document.createElement('h2');
title.textContent = event.meta.name || event.meta.title;
buzzer.append(title);
const dateStart = document.createElement('time');
dateStart.datetime = event.meta['date-start'];
dateStart.textContent = moment(event.meta['date-start']).format('MMMM Do YYYY');
buzzer.append(dateStart);
const endDate = event.meta['date-end'];
if(endDate){
const dateEnd = document.createElement('time');
dateEnd.datetime = endDate;
dateEnd.textContent = moment(endDate).format('MMMM Do YYYY');
buzzer.append(dateEnd);
}
const people = event.meta['people'] || [];
const peopleList = document.createElement('ul');
people.forEach(person => {
const li = document.createElement('li');
li.textContent = person;
peopleList.append(li);
})
buzzer.append(peopleList);
const content = document.createElement('div');
content.innerHTML = event.body;
buzzer.append(content);
article.append(buzzer);
return article;
}
renderEvents();
</script>
</html>