fix: ics formatting

This commit is contained in:
Cory Dransfeldt 2024-08-06 13:46:59 -07:00
parent c9156f2346
commit 82e2fa887a
No known key found for this signature in database
5 changed files with 111 additions and 17 deletions

View file

@ -6,7 +6,7 @@ import markdownItAnchor from 'markdown-it-anchor'
import markdownItFootnote from 'markdown-it-footnote'
import filters from './config/filters/index.js'
import { copyErrorPages } from './config/events/index.js'
import { popularPosts, processContent } from './config/collections/index.js'
import { popularPosts, processContent, albumReleasesCalendar } from './config/collections/index.js'
import { DateTime } from 'luxon'
// load .env
@ -65,6 +65,7 @@ export default async function (eleventyConfig) {
const { siteMap } = processContent(collection)
return siteMap
})
eleventyConfig.addCollection('albumReleasesCalendar', albumReleasesCalendar)
const md = markdownIt({ html: true, linkify: true })
md.use(markdownItAnchor, {

View file

@ -1,4 +1,5 @@
import { DateTime } from 'luxon'
import ics from 'ics'
const BASE_URL = 'https://coryd.dev'
@ -160,4 +161,40 @@ export const processContent = (collection) => {
return dateB - dateA
})
}
}
export const albumReleasesCalendar = (collection) => {
const collectionData = collection.getAll()[0]
const { data } = collectionData
const { albumReleases } = data
if (!albumReleases || albumReleases.length === 0) return ''
const events = albumReleases.map(album => {
const date = DateTime.fromFormat(album.date, 'MMMM d, yyyy')
if (!date.isValid) return null
return {
start: [
date.year,
date.month,
date.day,
0, 0
],
title: `Release: ${album.artist} / ${album.title}`,
description: `Check out this new album release: ${album.url}`,
url: album.url,
uid: `${date.toFormat('yyyyMMdd')}-${album.artist}-${album.title}@coryd.dev`,
timestamp: DateTime.now().toUTC().toFormat('yyyyMMdd\'T\'HHmmss\'Z\'') // Correctly format DTSTAMP
}
}).filter(event => event !== null)
const { error, value } = ics.createEvents(events)
if (error) {
console.error('Error creating ICS events:', error)
events.forEach((event, index) => {
console.error(`Event ${index}:`, event)
})
return ''
}
return value
}

71
package-lock.json generated
View file

@ -1,12 +1,12 @@
{
"name": "coryd.dev",
"version": "21.5.0",
"version": "21.5.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coryd.dev",
"version": "21.5.0",
"version": "21.5.1",
"license": "MIT",
"dependencies": {
"@cdransf/api-text": "^1.4.0",
@ -23,6 +23,7 @@
"@cdransf/eleventy-plugin-tabler-icons": "^1.10.0",
"@supabase/supabase-js": "^2.45.1",
"dotenv-flow": "^4.1.0",
"ics": "^3.7.6",
"liquidjs": "^10.16.1",
"luxon": "^3.5.0",
"markdown-it": "^14.1.0",
@ -1783,6 +1784,18 @@
"node": ">= 0.8"
}
},
"node_modules/ics": {
"version": "3.7.6",
"resolved": "https://registry.npmjs.org/ics/-/ics-3.7.6.tgz",
"integrity": "sha512-Z1QIWoPzyzqKUSj2Ui9vD3ca0AS+uHyiCjkROFx9PiKtJu9vMuMo6KJ4aqFmMAqn5q3fLq/5tLTJRm4zr9jjgw==",
"dev": true,
"license": "ISC",
"dependencies": {
"nanoid": "^3.1.23",
"runes2": "^1.1.2",
"yup": "^1.2.0"
}
},
"node_modules/inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
@ -2877,6 +2890,13 @@
"asap": "~2.0.3"
}
},
"node_modules/property-expr": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz",
"integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==",
"dev": true,
"license": "MIT"
},
"node_modules/prr": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz",
@ -2989,6 +3009,13 @@
"queue-microtask": "^1.2.2"
}
},
"node_modules/runes2": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/runes2/-/runes2-1.1.4.tgz",
"integrity": "sha512-LNPnEDPOOU4ehF71m5JoQyzT2yxwD6ZreFJ7MxZUAoMKNMY1XrAo60H1CUoX5ncSm0rIuKlqn9JZNRrRkNou2g==",
"dev": true,
"license": "MIT"
},
"node_modules/sanitize-html": {
"version": "2.13.0",
"resolved": "https://registry.npmjs.org/sanitize-html/-/sanitize-html-2.13.0.tgz",
@ -3414,6 +3441,13 @@
"node": ">=0.10.0"
}
},
"node_modules/tiny-case": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz",
"integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==",
"dev": true,
"license": "MIT"
},
"node_modules/to-regex-range": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz",
@ -3437,6 +3471,13 @@
"node": ">=0.6"
}
},
"node_modules/toposort": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz",
"integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==",
"dev": true,
"license": "MIT"
},
"node_modules/tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
@ -3444,6 +3485,19 @@
"dev": true,
"license": "MIT"
},
"node_modules/type-fest": {
"version": "2.19.0",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz",
"integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==",
"dev": true,
"license": "(MIT OR CC0-1.0)",
"engines": {
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/uc.micro": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-2.1.0.tgz",
@ -3672,6 +3726,19 @@
"resolved": "https://registry.npmjs.org/youtube-video-element/-/youtube-video-element-1.1.6.tgz",
"integrity": "sha512-EaHyEh68twtuWn6S7cCEghJkLfaOD82wmJhczeWSTxT71yOG6lL7EXu6EAHADj6wPQJ9+lZpaos3f/Bh8Lzvjg==",
"license": "MIT"
},
"node_modules/yup": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/yup/-/yup-1.4.0.tgz",
"integrity": "sha512-wPbgkJRCqIf+OHyiTBQoJiP5PFuAXaWiJK6AmYkzQAh5/c2K9hzSApBZG5wV9KoKSePF7sAxmNSvh/13YHkFDg==",
"dev": true,
"license": "MIT",
"dependencies": {
"property-expr": "^2.0.5",
"tiny-case": "^1.0.3",
"toposort": "^2.0.2",
"type-fest": "^2.19.0"
}
}
}
}

View file

@ -1,6 +1,6 @@
{
"name": "coryd.dev",
"version": "21.5.0",
"version": "21.5.1",
"description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module",
"scripts": {
@ -38,6 +38,7 @@
"@cdransf/eleventy-plugin-tabler-icons": "^1.10.0",
"@supabase/supabase-js": "^2.45.1",
"dotenv-flow": "^4.1.0",
"ics": "^3.7.6",
"liquidjs": "^10.16.1",
"luxon": "^3.5.0",
"markdown-it": "^14.1.0",

View file

@ -3,16 +3,4 @@ layout: null
eleventyExcludeFromCollections: true
permalink: "/music/releases.ics"
---
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//coryd.dev//Album Releases//EN
{%- for album in albumReleases %}
BEGIN:VEVENT
SUMMARY:Release: {{ album.artist }} / {{ album.title }}
DTSTART;VALUE=DATE:{{ album.date }}
DESCRIPTION:Check out this new album release: {{ album.url }}
URL;VALUE=URI:{{ album.url }}
END:VEVENT
{%- endfor -%}
END:VCALENDAR
{{ collections.albumReleasesCalendar }}