-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshows.js
More file actions
88 lines (77 loc) · 2.32 KB
/
Copy pathshows.js
File metadata and controls
88 lines (77 loc) · 2.32 KB
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
---
layout: none
---
const allShows = [
{% for post in site.categories.shows %}
{
date: {
human: "{{ post.date | date: '%B %-d, %Y' }}",
machine: "{{ post.date | date: '%Y-%m-%d' }}"
},
anchor: "{{ post.date | date: '%m%-d%Y' }}",
poster: "{{ post.poster }}",
bands: "{{ post.bands }}",
link: "{{ post.link }}",
title: "{{ post.date | date: '%B %-d, %Y' }} @ {{ post.venue }}, {{ post.location }}"
}{% unless forloop.last %},{% endunless %}
{% endfor %}
];
// a show is in the future, not in the past, until the next day
function getComparisonDate(show) {
const date = new Date(show.date.machine);
date.setDate(date.getDate() + 1);
return date;
}
const now = new Date();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
let nextShow = allShows[0];
// find next show
allShows.forEach(s => {
const thisShowDate = getComparisonDate(s),
nextShowDate = getComparisonDate(nextShow);
if (s !== nextShow &&
now <= thisShowDate &&
(thisShowDate - now) <
(nextShowDate - now)) {
// if the show is in the future, and the distance between now and the show is the smallest
nextShow = s;
}
});
const li = document.querySelector(".next-show");
const h2 = document.createElement("h2");
h2.textContent = "next show: ";
li.appendChild(h2);
const a = document.createElement("a");
a.href = `/tour/#${nextShow.anchor}`;
a.textContent = `${nextShow.title}`;
h2.appendChild(a);
if (nextShow.link) {
const linka = document.createElement("a");
linka.href = nextShow.link;
linka.textContent = `🔗 ${ nextShow.bands ? nextShow.bands : "Event Link" }`;
const p = document.createElement("p");
p.appendChild(linka);
li.appendChild(p);
} else {
const p = document.createElement("p");
p.textContent = nextShow.bands;
li.appendChild(p);
}
if (nextShow.poster) {
const p = document.createElement("p");
const img = document.createElement("img");
img.src = nextShow.poster;
img.alt = nextShow.title;
// p.appendChild(img);
if (nextShow.link) {
const linka = document.createElement("a");
linka.href = nextShow.link;
linka.alt = `${ nextShow.title }`;
linka.appendChild(p);
li.appendChild(linka);
} else {
li.appendChild(p);
}
}