feat: initial commit
This commit is contained in:
commit
e214116e40
253 changed files with 17406 additions and 0 deletions
41
config/collections/index.js
Normal file
41
config/collections/index.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
import ics from "ics";
|
||||
|
||||
export const albumReleasesCalendar = (collection) => {
|
||||
const collectionData = collection.getAll()[0];
|
||||
const { data } = collectionData;
|
||||
const { albumReleases: { all }, globals: { url } } = data;
|
||||
|
||||
if (!all || all.length === 0) return "";
|
||||
|
||||
const events = all
|
||||
.map((album) => {
|
||||
const date = new Date(album.release_date);
|
||||
|
||||
if (isNaN(date.getTime())) return null;
|
||||
|
||||
const albumUrl = album.url?.includes("http") ? album.url : `${url}${album.url}`;
|
||||
const artistUrl = album.artist.url?.includes("http") ? album.artust.url : `${url}${album.artist.url}`;
|
||||
|
||||
return {
|
||||
start: [date.getFullYear(), date.getMonth() + 1, date.getDate()],
|
||||
startInputType: "local",
|
||||
startOutputType: "local",
|
||||
title: `Release: ${album.artist.name} - ${album.title}`,
|
||||
description: `Check out this new album release: ${albumUrl}. Read more about ${album.artist.name} at ${artistUrl}`,
|
||||
url: albumUrl,
|
||||
uid: `${album.release_timestamp}-${album.artist.name}-${album.title}`,
|
||||
};
|
||||
})
|
||||
.filter((event) => event !== null);
|
||||
|
||||
const { error, value } = ics.createEvents(events, {
|
||||
calName: "Album releases calendar • coryd.dev",
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error("Error creating events: ", error);
|
||||
return "";
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue