feat: source upcoming albums from albums table
This commit is contained in:
parent
c63cdecff3
commit
925fa4d979
5 changed files with 51 additions and 49 deletions
1
.env
1
.env
|
@ -2,7 +2,6 @@ SITE_ID_CLICKY=
|
||||||
SITE_KEY_CLICKY=
|
SITE_KEY_CLICKY=
|
||||||
API_KEY_TRAKT=
|
API_KEY_TRAKT=
|
||||||
API_KEY_MOVIEDB=
|
API_KEY_MOVIEDB=
|
||||||
SECRET_FEED_ALBUM_RELEASES=
|
|
||||||
ACCOUNT_ID_PLEX=
|
ACCOUNT_ID_PLEX=
|
||||||
SUPABASE_URL=
|
SUPABASE_URL=
|
||||||
SUPABASE_KEY=
|
SUPABASE_KEY=
|
23
package-lock.json
generated
23
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "14.0.9",
|
"version": "14.0.11",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "14.0.9",
|
"version": "14.0.11",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@cdransf/api-text": "^1.2.2",
|
"@cdransf/api-text": "^1.2.2",
|
||||||
|
@ -30,7 +30,6 @@
|
||||||
"dotenv-flow": "^4.1.0",
|
"dotenv-flow": "^4.1.0",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"html-minifier-terser": "^7.2.0",
|
"html-minifier-terser": "^7.2.0",
|
||||||
"ics-to-json-extended": "^1.1.4",
|
|
||||||
"liquidjs": "^10.12.0",
|
"liquidjs": "^10.12.0",
|
||||||
"luxon": "^3.4.4",
|
"luxon": "^3.4.4",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
|
@ -2577,15 +2576,6 @@
|
||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/ics-to-json-extended": {
|
|
||||||
"version": "1.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/ics-to-json-extended/-/ics-to-json-extended-1.1.4.tgz",
|
|
||||||
"integrity": "sha512-5NtUG7GwN2uVp4Gg1++brlELbv/fkIU+N7rZGQCIKujQAf+l6LTjMjsNifma3bX2CrPcsxy2tf/9bqF/NWIDWA==",
|
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
|
||||||
"moment": "^2.29.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/inflight": {
|
"node_modules/inflight": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||||
|
@ -3445,15 +3435,6 @@
|
||||||
"mkdirp": "bin/cmd.js"
|
"mkdirp": "bin/cmd.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/moment": {
|
|
||||||
"version": "2.30.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz",
|
|
||||||
"integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==",
|
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/moo": {
|
"node_modules/moo": {
|
||||||
"version": "0.5.2",
|
"version": "0.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "coryd.dev",
|
"name": "coryd.dev",
|
||||||
"version": "14.0.11",
|
"version": "14.1.0",
|
||||||
"description": "The source for my personal site. Built using 11ty.",
|
"description": "The source for my personal site. Built using 11ty.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -40,7 +40,6 @@
|
||||||
"dotenv-flow": "^4.1.0",
|
"dotenv-flow": "^4.1.0",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"html-minifier-terser": "^7.2.0",
|
"html-minifier-terser": "^7.2.0",
|
||||||
"ics-to-json-extended": "^1.1.4",
|
|
||||||
"liquidjs": "^10.12.0",
|
"liquidjs": "^10.12.0",
|
||||||
"luxon": "^3.4.4",
|
"luxon": "^3.4.4",
|
||||||
"markdown-it": "^14.1.0",
|
"markdown-it": "^14.1.0",
|
||||||
|
|
|
@ -1,25 +1,48 @@
|
||||||
import { AssetCache } from '@11ty/eleventy-fetch'
|
import { createClient } from '@supabase/supabase-js'
|
||||||
import ics from 'ics-to-json-extended'
|
|
||||||
import { DateTime } from 'luxon'
|
import { DateTime } from 'luxon'
|
||||||
|
|
||||||
|
const SUPABASE_URL = process.env.SUPABASE_URL
|
||||||
|
const SUPABASE_KEY = process.env.SUPABASE_KEY
|
||||||
|
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
|
||||||
|
|
||||||
|
const deriveArtistName = (albumName, key) => {
|
||||||
|
const normalizedInput = albumName.toLowerCase().replace(/[\s.]+/g, '-').replace(/[^a-z0-9-]/g, '')
|
||||||
|
if (key.endsWith(normalizedInput)) {
|
||||||
|
const nonMatchingPart = key.slice(0, key.length - normalizedInput.length).replace(/-$/, '')
|
||||||
|
const capitalized = nonMatchingPart
|
||||||
|
.split('-')
|
||||||
|
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
||||||
|
.join(' ')
|
||||||
|
return capitalized
|
||||||
|
} else {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
const URL = process.env.SECRET_FEED_ALBUM_RELEASES
|
const today = DateTime.utc().toISO()
|
||||||
const icsToJson = ics.default
|
const { data, error } = await supabase
|
||||||
const asset = new AssetCache('album_release_data')
|
.from('albums')
|
||||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
.select(`
|
||||||
const icsRes = await fetch(URL)
|
name,
|
||||||
const icsData = await icsRes.text()
|
key,
|
||||||
const data = icsToJson(icsData)
|
image,
|
||||||
const albumReleases = data
|
release_date,
|
||||||
.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
|
release_link
|
||||||
.sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
|
`)
|
||||||
.map((release) => {
|
.gt('release_date', today)
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
console.error('Error fetching data:', error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.map(album => {
|
||||||
return {
|
return {
|
||||||
date: release.startDate,
|
artist: deriveArtistName(album['name'], album['key']),
|
||||||
url: release.location,
|
title: album['name'],
|
||||||
title: release.summary.replace(/\\/g, ''),
|
date: DateTime.fromISO(album['release_date']).toLocaleString(DateTime.DATE_FULL),
|
||||||
|
url: album['release_link']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await asset.save(albumReleases, 'json')
|
|
||||||
return albumReleases
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
<ul class="link-list">
|
<ul class="link-list">
|
||||||
{% for album in albumReleases %}
|
{% for album in albumReleases %}
|
||||||
<li>
|
<li>
|
||||||
<strong>{{ album.date | readableDate }}: </strong>
|
<strong>{{ album.date }}: </strong>
|
||||||
<a href="https://{{album.url}}" title="{{album.title | escape}}">
|
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
|
||||||
{{album.title}}
|
{{ album.title }} by {{ album.artist }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
Reference in a new issue