Skip to content
This repository was archived by the owner on May 2, 2021. It is now read-only.

Commit 9b4c648

Browse files
committed
automatic event details generation
1 parent 1b85a50 commit 9b4c648

4 files changed

Lines changed: 115 additions & 20 deletions

File tree

.eleventy.js

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
const yaml = require('js-yaml');
22
const rss = require('@11ty/eleventy-plugin-rss');
33
const { DateTime } = require('luxon');
4+
const markdown = require('markdown-it')({
5+
html: true,
6+
});
7+
8+
const WEEK = [
9+
'Lunedì',
10+
'Martedì',
11+
'Mercoledì',
12+
'Giovedì',
13+
'Venerdì',
14+
'Sabato',
15+
'Domenica',
16+
];
17+
18+
const MONTHS = [
19+
'Gennaio',
20+
'Febbraio',
21+
'Marzo',
22+
'Aprile',
23+
'Maggio',
24+
'Giugno',
25+
'Luglio',
26+
'Agosto',
27+
'Settembre',
28+
'Ottobre',
29+
'Novembre',
30+
'Dicembre',
31+
];
432

533
module.exports = function(eleventyConfig) {
634
const assets = ['js', 'css', 'fonts', 'img', 'odx-assets', 'admin'];
@@ -17,12 +45,39 @@ module.exports = function(eleventyConfig) {
1745
yaml.safeLoad(contents),
1846
);
1947

48+
eleventyConfig.addNunjucksShortcode('markdown', (content) =>
49+
markdown.render(content),
50+
);
51+
2052
eleventyConfig.addNunjucksFilter('dateformat', (date, format) => {
21-
return DateTime.fromJSDate(date, { zone: 'utc' }).toFormat(format);
53+
return DateTime.fromJSDate(date, { zone: 'Europe/Rome' }).toFormat(format);
54+
});
55+
56+
eleventyConfig.addNunjucksFilter('date_human', (start, end) => {
57+
const startDate = DateTime.fromJSDate(start, {
58+
zone: 'Europe/Rome',
59+
});
60+
61+
const startLocale = `${
62+
WEEK[startDate.weekday - 1]
63+
} ${startDate.day.toString().padStart(2, '0')} ${
64+
MONTHS[startDate.month - 1]
65+
} ${startDate.year}`;
66+
const startTime = startDate.toFormat('HH:mm');
67+
68+
if (!end) {
69+
return `${startLocale} alle ${startTime}`;
70+
}
71+
const endTime = DateTime.fromJSDate(end, { zone: 'Europe/Rome' }).toFormat(
72+
'HH:mm',
73+
);
74+
return `${startLocale} dalle ${startTime} alle ${endTime}`;
2275
});
2376

2477
eleventyConfig.addFilter('dateslug', (date) => {
25-
return DateTime.fromJSDate(date, { zone: 'utc' }).toFormat('yyyy/LL');
78+
return DateTime.fromJSDate(date, { zone: 'Europe/Rome' }).toFormat(
79+
'yyyy/LL',
80+
);
2681
});
2782

2883
eleventyConfig.addNunjucksFilter('published', (posts) => {

src/_data/site.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ social:
7676
name: Speakerdeck
7777
icon: list-alt
7878
url: 'https://speakerdeck.com/fevr'
79-
patreon:
80-
name: Patreon
81-
icon: eur
82-
url: 'https://www.patreon.com/fevr'
8379
spotify:
8480
name: Spotify
8581
url: https://open.spotify.com/show/24e51pmI7X0UXfIgRQiyMX

src/_includes/event-content.njk

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,39 @@
7676
</footer>
7777

7878
{{ content | safe }}
79+
80+
{% if event.auto_meta %}
81+
{% if event.speaker %}
82+
<h2>SPEAKER</h2>
83+
84+
<p><b>{{ event.speaker }}</b></p>
85+
86+
{% if event.speaker_bio %}
87+
{% markdown event.speaker_bio %}
88+
{% endif %}
89+
90+
91+
{% endif %}
92+
93+
94+
<h2>QUANDO</h2>
95+
<p>
96+
<time datetime="{{ date.toISOString() }}">{{date | date_human(date_end) }}</time>
97+
</p>
98+
99+
{% if event.location %}
100+
<h2>DOVE</h2>
101+
102+
<p>
103+
{{ event.location }}
104+
{% if event.location_url %}
105+
: <a href="{{event.location_url}}">{{ event.location_url }}</a>
106+
{% endif %}
107+
</p>
108+
109+
{% endif %}
110+
111+
{% endif %}
79112
</div>
80113
</div>
81114
</div>
@@ -110,19 +143,6 @@
110143
</li>
111144
</ul>
112145
</footer>
113-
<hr aria-hidden="true"/>
114-
115-
<footer class="support list-inline">
116-
<h2 class="sr-only">Supportaci su:</h2>
117-
<ul class="list-inline">
118-
<li aria-hidden="true">Supportaci su:</li>
119-
<li>
120-
<a class="btn red-btn" target="_blank" href="{{site.social.patreon.url}}">
121-
<span aria-hidden="true" class="fa fa-link"></span> Patreon
122-
</a>
123-
</li>
124-
</ul>
125-
</footer>
126146

127147
<footer>
128148

static/admin/config.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ collections:
2727
label: Copertina (Hero)
2828
- widget: datetime
2929
name: date
30-
label: Data Evento
30+
label: Data Inizio Evento
31+
- widget: datetime
32+
name: date_end
33+
label: Data Fine Evento
3134
- widget: hidden
3235
name: redirect_from
3336
required: false
@@ -46,15 +49,36 @@ collections:
4649
name: event
4750
label: Dettagli
4851
fields:
52+
- widget: boolean
53+
name: auto_meta
54+
label: Dettagli evento automatici
55+
default: false
56+
hint: Se attivato, bio dello speaker e dettagli dell'evento saranno generati in automatico nella pagina di dettaglio.
4957
- widget: string
5058
name: speaker
5159
label: Speaker
5260
required: false
61+
- widget: 'markdown'
62+
label: 'Biografia'
63+
name: 'speaker_bio'
64+
buttons:
65+
- bold
66+
- italic
67+
- code
68+
- link
69+
- quote
70+
- bulleted-list
71+
- numbered-list
5372
- widget: string
5473
name: location
5574
label: Location
5675
default: Officina 18
5776
required: false
77+
- widget: string
78+
name: location_url
79+
label: URL Location
80+
default:
81+
required: false
5882
- widget: string
5983
name: eventbrite
6084
label: Codice Eventbrite

0 commit comments

Comments
 (0)