Skip to content

Commit

Permalink
ics js?
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor committed Jun 21, 2024
1 parent 952bb44 commit a9263b8
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 4 deletions.
3 changes: 2 additions & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ author:
# - label: "GitHub"
# icon: "fab fa-fw fa-github"
# # url: "https://github.com/"

head_scripts:
- /assets/js/ics.js
# Site Footer
footer:
links:
Expand Down
9 changes: 9 additions & 0 deletions _data/authors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,15 @@ sp5xmi:

## end SP5XMI

## begin SP6SP
sp6sp:
name : Marcin
callsign : SP6SP
constructor : no
speaker : yes

## end SP6SP

## begin Alek
alek:
name : Alek Zawada
Expand Down
18 changes: 16 additions & 2 deletions _pages/talks.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ <h3>Stołówka</h3>
<br>
{%if talk.where_exactly %}
{%if talk.where_exactly_geourl %}
Gdzie: <a href="{{ talk.where_exactly_geourl }}">{{ talk.where_exactly }}</a>
<b>Gdzie</b>: <a class="geolink" href="{{ talk.where_exactly_geourl }}">{{ talk.where_exactly }}</a>
<br>
{% else %}
Gdzie: {{ talk.where_exactly }}
Expand All @@ -213,7 +213,14 @@ <h3>Stołówka</h3>
{% endif %}
<br>
{% endfor %}
Kiedy: {{ talk.starttime | date: "%H:%M" }} - {{ talk.endtime | date: "%H:%M" }}<br>
<b>Kiedy</b>: {{ talk.starttime | date: "%H:%M" }} - {{ talk.endtime | date: "%H:%M" }}<br>
<a href="#" class="download-ics"
data-start="{{ talk.starttime }}"
data-end="{{ talk.endtime }}"
data-title="{{ talk.title }}"
data-description="---"
data-url="{{ talk.url | absolute_url }}"
data-location="Ośrodek Wypoczynkowy „SPORTOWA OSADA”, Zarzecze 12, 98-260 Strumiany, Poland">Dodaj do kalendarza</a><br>
</li>
{% endfor %}
</ul>
Expand Down Expand Up @@ -255,6 +262,13 @@ <h3>Inne</h3>
<br>
{% endfor %}
Kiedy: {{ talk.starttime | date: "%H:%M" }} - {{ talk.endtime | date: "%H:%M" }}<br>
<a href="#" class="download-ics"
data-start="{{ talk.starttime }}"
data-end="{{ talk.endtime }}"
data-title="{{ talk.title }}"
data-description="---"
data-url="#"
data-location="Ośrodek Wypoczynkowy „SPORTOWA OSADA”, Zarzecze 12, 98-260 Strumiany, Poland">Dodaj do kalendarza</a><br>
</li>
{% endfor %}
</ul>
Expand Down
18 changes: 17 additions & 1 deletion _sass/minimal-mistakes/_talks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,36 @@
&.breakfast {
background-color: #81ff7f24;
color: #787878;

strong:before {
content: "🥐 ";
}
}

&.dinner {
background-color: rgb(149 140 90 / 14%);
color: #787878;

strong:before {
content: "🍽️ ";
}
}

&.tba {
background-color: rgb(67 87 243 / 14%);

strong:before {
content: "🔜 ";
}

}

&.puk {
background-color: #fffb7f24
background-color: #fffb7f24;

strong:before {
content: "🛠️ ";
}

}
}
Expand Down
51 changes: 51 additions & 0 deletions assets/js/ics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
document.querySelectorAll('.download-ics').forEach(link => {
link.addEventListener('click', function (event) {
event.preventDefault();

// Get event details from data attributes
const eventDetails = {
start: this.getAttribute('data-start'),
end: this.getAttribute('data-end'),
title: this.getAttribute('data-title'),
description: this.getAttribute('data-description'),
location: this.getAttribute('data-location'),
url: this.getAttribute('data-url')
};

// Create iCal string
const icalString = `
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sample Corp//NONSGML Event//EN
BEGIN:VEVENT
UID:${new Date().toISOString()}@sample.com
DTSTAMP:${new Date().toISOString().replace(/[-:]/g, '').split('.')[0]}Z
DTSTART:${eventDetails.start}
DTEND:${eventDetails.end}
SUMMARY:${eventDetails.title}
DESCRIPTION:${eventDetails.description}
LOCATION:${eventDetails.location}
URL:${eventDetails.url}
END:VEVENT
END:VCALENDAR
`.trim();

// Encode iCal string in Base64
const base64String = btoa(icalString);

// Create a download link
const downloadLink = document.createElement('a');
downloadLink.href = 'data:text/calendar;base64,' + base64String;
downloadLink.download = `${eventDetails.title.replace(/[^a-z0-9]/gi, '_').toLowerCase()}.ics`;
downloadLink.style.display = 'none';

// Append the link to the body
document.body.appendChild(downloadLink);

// Programmatically click the download link
downloadLink.click();

// Remove the link from the document
document.body.removeChild(downloadLink);
});
});

0 comments on commit a9263b8

Please sign in to comment.