Skip to content

Commit

Permalink
ICS fix (config switch)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wiktor committed Jun 23, 2024
1 parent 47a245f commit 215ff82
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
4 changes: 2 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ author:
# - label: "GitHub"
# icon: "fab fa-fw fa-github"
# # url: "https://github.com/"
head_scripts:
- /assets/js/ics.js
# head_scripts:
# - /assets/js/ics.js
# Site Footer
footer:
links:
Expand Down
45 changes: 44 additions & 1 deletion _pages/talks.html
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,47 @@ <h3>Inne</h3>
<p>No talks scheduled.</p>
{% endif %}
</div>
{% endfor %}
{% endfor %}

<script>
function downloadICS(event, start, end, title, description, location, url) {
// Prevent default action
event.preventDefault();

// 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:${start}
DTEND:${end}
SUMMARY:${title}
DESCRIPTION:${description}
LOCATION:${location}
URL:${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 = `${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);
}
</script>

0 comments on commit 215ff82

Please sign in to comment.