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=
|
||||
API_KEY_TRAKT=
|
||||
API_KEY_MOVIEDB=
|
||||
SECRET_FEED_ALBUM_RELEASES=
|
||||
ACCOUNT_ID_PLEX=
|
||||
SUPABASE_URL=
|
||||
SUPABASE_KEY=
|
23
package-lock.json
generated
23
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "14.0.9",
|
||||
"version": "14.0.11",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "coryd.dev",
|
||||
"version": "14.0.9",
|
||||
"version": "14.0.11",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@cdransf/api-text": "^1.2.2",
|
||||
|
@ -30,7 +30,6 @@
|
|||
"dotenv-flow": "^4.1.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
"ics-to-json-extended": "^1.1.4",
|
||||
"liquidjs": "^10.12.0",
|
||||
"luxon": "^3.4.4",
|
||||
"markdown-it": "^14.1.0",
|
||||
|
@ -2577,15 +2576,6 @@
|
|||
"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": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
|
@ -3445,15 +3435,6 @@
|
|||
"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": {
|
||||
"version": "0.5.2",
|
||||
"resolved": "https://registry.npmjs.org/moo/-/moo-0.5.2.tgz",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "coryd.dev",
|
||||
"version": "14.0.11",
|
||||
"version": "14.1.0",
|
||||
"description": "The source for my personal site. Built using 11ty.",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
@ -40,7 +40,6 @@
|
|||
"dotenv-flow": "^4.1.0",
|
||||
"gray-matter": "^4.0.3",
|
||||
"html-minifier-terser": "^7.2.0",
|
||||
"ics-to-json-extended": "^1.1.4",
|
||||
"liquidjs": "^10.12.0",
|
||||
"luxon": "^3.4.4",
|
||||
"markdown-it": "^14.1.0",
|
||||
|
|
|
@ -1,25 +1,48 @@
|
|||
import { AssetCache } from '@11ty/eleventy-fetch'
|
||||
import ics from 'ics-to-json-extended'
|
||||
import { createClient } from '@supabase/supabase-js'
|
||||
import { DateTime } from 'luxon'
|
||||
|
||||
export default async function () {
|
||||
const URL = process.env.SECRET_FEED_ALBUM_RELEASES
|
||||
const icsToJson = ics.default
|
||||
const asset = new AssetCache('album_release_data')
|
||||
if (asset.isCacheValid('1h')) return await asset.getCachedValue()
|
||||
const icsRes = await fetch(URL)
|
||||
const icsData = await icsRes.text()
|
||||
const data = icsToJson(icsData)
|
||||
const albumReleases = data
|
||||
.filter((d) => DateTime.fromISO(d.startDate) > DateTime.now())
|
||||
.sort((a, b) => new Date(a.startDate) - new Date(b.startDate))
|
||||
.map((release) => {
|
||||
return {
|
||||
date: release.startDate,
|
||||
url: release.location,
|
||||
title: release.summary.replace(/\\/g, ''),
|
||||
}
|
||||
})
|
||||
await asset.save(albumReleases, 'json')
|
||||
return albumReleases
|
||||
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 () {
|
||||
const today = DateTime.utc().toISO()
|
||||
const { data, error } = await supabase
|
||||
.from('albums')
|
||||
.select(`
|
||||
name,
|
||||
key,
|
||||
image,
|
||||
release_date,
|
||||
release_link
|
||||
`)
|
||||
.gt('release_date', today)
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching data:', error)
|
||||
return
|
||||
}
|
||||
|
||||
return data.map(album => {
|
||||
return {
|
||||
artist: deriveArtistName(album['name'], album['key']),
|
||||
title: album['name'],
|
||||
date: DateTime.fromISO(album['release_date']).toLocaleString(DateTime.DATE_FULL),
|
||||
url: album['release_link']
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
<ul class="link-list">
|
||||
{% for album in albumReleases %}
|
||||
<li>
|
||||
<strong>{{ album.date | readableDate }}: </strong>
|
||||
<a href="https://{{album.url}}" title="{{album.title | escape}}">
|
||||
{{album.title}}
|
||||
<strong>{{ album.date }}: </strong>
|
||||
<a href="{{ album.url}}" title="{{ album.title | escape}} by {{ album.artist | escape}}">
|
||||
{{ album.title }} by {{ album.artist }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
|
Reference in a new issue