Creating dynamic events (ex. so it does the next tuesday, requires [[Javascript in Obsidian]]>
<html><a id="calendar-link" href="#">Add this to your calendar</a>
<script>
window.onload = function () {
function getNextTuesday() {
const now = new Date();
const day = now.getDay();
const daysUntilTuesday = (9 - day) % 7 || 7;
const nextTuesday = new Date(now.getFullYear(), now.getMonth(), now.getDate() + daysUntilTuesday);
nextTuesday.setUTCHours(15, 30, 0, 0);
const start = nextTuesday.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z';
const endTime = new Date(nextTuesday.getTime() + 60 * 60 * 1000);
const end = endTime.toISOString().replace(/[-:]/g, '').split('.')[0] + 'Z';
const params = new URLSearchParams({
action: 'TEMPLATE',
text: 'Yoga in the Park',
dates: `${start}/${end}`,
details: `Outdoor yoga under the trees.\n\nMore info: https://test.com`,
location: 'Civic Park by KPL',
add: '
[email protected],
[email protected]'
});
return `https://www.google.com/calendar/render?${params.toString()}`;
}
const link = document.getElementById('calendar-link');
link.href = getNextTuesday();
};
</script>
</html>
Does not work