diff --git a/config/collections/index.js b/config/collections/index.js index ac79cfd9..0ea10c4b 100644 --- a/config/collections/index.js +++ b/config/collections/index.js @@ -1,5 +1,5 @@ import { DateTime } from 'luxon' -import markdownIt from 'markdown-it'; +import markdownIt from 'markdown-it' import ics from 'ics' const BASE_URL = 'https://coryd.dev' @@ -28,6 +28,7 @@ export const processContent = (collection) => { const searchIndex = [] const aggregateContent = [] let id = 0 + const collectionData = collection.getAll()[0] const { data } = collectionData const { posts, links, movies, books, pages, artists, genres, tv, concerts, albumReleases } = data @@ -53,41 +54,51 @@ export const processContent = (collection) => { return null } + const absoluteUrl = (url) => new URL(url, BASE_URL).toString() + const isValidUrl = (url) => { + try { + new URL(url) + return true + } catch { + return false + } + } + const addSiteMapContent = (items, getTitle, getDate) => { const addedUrls = new Set() if (items) { items.forEach((item) => { - let url - if (item?.['url']) url = item['url'] - if (item?.['permalink']) url = item['permalink'] - if (item?.['slug']) url = item['slug'] + let url = item?.['permalink'] || item?.['url'] + if (!url || addedUrls.has(url)) return + if (!isValidUrl(url)) url = absoluteUrl(url) + if (addedUrls.has(url)) return const parsedDate = getDate ? parseDate(getDate(item)) : null const formattedDate = parsedDate ? parsedDate.toFormat("yyyy-MM-dd'T'HH:mm:ssZZ") : null - const content = { url, title: getTitle(item), date: formattedDate } + siteMapContent.push(content) addedUrls.add(url) }) } } - const movieData = movies['movies'].filter((movie) => movie['rating']) - const showData = tv['shows'].filter((show) => show['episodes']?.[0]?.['last_watched_at']) - const bookData = books.all.filter((book) => book['rating']) - const addItemToIndex = (items, icon, getUrl, getTitle, getTags) => { if (items) { items.forEach((item) => { + const url = getUrl(item) + if (!url) return + + const absoluteUrlString = isValidUrl(url) ? url : absoluteUrl(url) searchIndex.push({ id, - url: getUrl(item), + url: absoluteUrlString, title: `${icon}: ${getTitle(item)}`, tags: getTags ? getTags(item) : [] }) @@ -99,37 +110,31 @@ export const processContent = (collection) => { const addContent = (items, icon, getTitle, getDate) => { if (items) { items.forEach((item) => { - let attribution + let attribution = '' let hashTags = tagsToHashtags(item) ? ' ' + tagsToHashtags(item) : '' if (item['type'] === 'album-release') hashTags = ' #Music #NewMusic' if (item['type'] === 'concert') hashTags = ' #Music #Concert' - // link attribution if properties exist if (item?.['authors']?.['mastodon']) { const mastoUrl = new URL(item['authors']['mastodon']) attribution = `${mastoUrl.pathname.replace('/', '')}@${mastoUrl.host}` - } else if (!item?.['authors']?.['mastodon'] && item?.['authors']?.['name']) { + } else if (item?.['authors']?.['name']) { attribution = item['authors']['name'] } + let url = item['url'] || item['link'] + if (url && !isValidUrl(url)) url = absoluteUrl(url) + if (item['type'] === 'concert') url = `${item['artistUrl'] ? item['artistUrl'] : BASE_URL + '/music/concerts'}?t=${DateTime.fromISO(item['date']).toMillis()}${item['artistUrl'] ? '#concerts' : ''}` + const content = { - url: !item['url']?.includes('http') ? `${BASE_URL}${item['url']}` : item['url'], + url, title: `${icon}: ${getTitle(item)}${attribution ? ' via ' + attribution : ''}${hashTags}`, type: item['type'] } - // set url for link posts - if (item?.['link']) content['url'] = item?.['link'] - - // set url for posts - identified as slugs here - if (item?.['slug']) content['url'] = new URL(item['slug'], BASE_URL).toString() - - // set unique concert urls - if (item?.['type'] === 'concert') content['url'] = `${item['artistUrl'] ? item['artistUrl'] : BASE_URL + '/music/concerts'}?t=${DateTime.fromISO(item['date']).toMillis()}${item['artistUrl'] ? '#concerts' : ''}` - - if (item?.['description']) { + if (item['description']) { content['description'] = md.render(item['description']) - } else if (item?.['notes']) { + } else if (item['notes']) { content['notes'] = md.render(item['notes']) } else { content['description'] = '' @@ -143,9 +148,13 @@ export const processContent = (collection) => { } } - addItemToIndex(posts, '📝', (item) => new URL(item['slug'], BASE_URL).toString(), (item) => item['title'], (item) => item['tags']) + const movieData = movies['movies'].filter((movie) => movie['rating']) + const showData = tv['shows'].filter((show) => show['episodes']?.[0]?.['last_watched_at']) + const bookData = books.all.filter((book) => book['rating']) + + addItemToIndex(posts, '📝', (item) => item['url'], (item) => item['title'], (item) => item['tags']) addItemToIndex(links, '🔗', (item) => item['link'], (item) => item['title'], (item) => item['tags']) - addItemToIndex(artists, '🎙️', (item) => item['url'], (item) => `${item['name']} (${item['country']}) - ${item['genre']}`, (item) => `['${item['genre']}']`) + addItemToIndex(artists, '🎙️', (item) => item['url'], (item) => `${item['name']} (${item['country']}) - ${item['genre']['name']}`, (item) => `['${item['genre']}']`) addItemToIndex(genres, '🎵', (item) => item['url'], (item) => item['name'], (item) => item.artists.map(artist => artist['name_string'])) if (movieData) addItemToIndex(movieData, '🎥', (item) => item['url'], (item) => `${item['title']} (${item['rating']})`, (item) => item['tags']) if (showData) addItemToIndex(showData, '📺', (item) => item['url'], (item) => `${item['title']} (${item['year']})`, (item) => item['tags']) diff --git a/src/data/concerts.js b/src/data/concerts.js index a0b0b66a..8716c6e0 100644 --- a/src/data/concerts.js +++ b/src/data/concerts.js @@ -1,5 +1,4 @@ import { createClient } from '@supabase/supabase-js' -import { parseCountryField } from '../../config/utilities/index.js' const SUPABASE_URL = process.env.SUPABASE_URL const SUPABASE_KEY = process.env.SUPABASE_KEY @@ -16,17 +15,9 @@ const fetchAllConcerts = async () => { .select(` id, date, - artist_name_string, - venue, - concert_notes, artist, - venue_name, - latitude, - longitude, - bounding_box, - venue_notes, - artist_name, - artist_country + venue, + concert_notes `) .range(rangeStart, rangeStart + PAGE_SIZE - 1) @@ -48,21 +39,20 @@ const processConcerts = (concerts) => { id: concert['id'], type: 'concert', date: concert['date'], - artistNameString: concert['artist_name_string'], - venue: { - name: concert['venue_name'], - latitude: concert['latitude'], - longitude: concert['longitude'], - boundingBox: concert['bounding_box'], - notes: concert['venue_notes'] - }, + artist: concert['artist'] && typeof concert['artist'] === 'object' ? { + name: concert['artist'].name, + url: concert['artist'].url + } : { name: concert['artist'], url: null }, + venue: concert['venue'] && typeof concert['venue'] === 'object' ? { + name: concert['venue'].name, + latitude: concert['venue'].latitude, + longitude: concert['venue'].longitude, + notes: concert['venue'].notes + } : null, description: 'I went to (yet another) concert!', notes: concert['concert_notes'], - artist: concert['artist'] ? { - name: concert['artist_name'], - } : null, url: `/music/concerts?id=${concert['id']}`, - artistUrl: concert['artist'] ? concert['artist_url'] : null + artistUrl: concert['artist'] && typeof concert['artist'] === 'object' ? concert['artist'].url : null })).sort((a, b) => new Date(b['date']) - new Date(a['date'])) } diff --git a/src/pages/dynamic/music/concerts.html b/src/pages/dynamic/music/concerts.html index bcfa9f1e..4f419af3 100644 --- a/src/pages/dynamic/music/concerts.html +++ b/src/pages/dynamic/music/concerts.html @@ -15,10 +15,10 @@ permalink: "/music/concerts/{% if pagination.pageNumber > 0 %}{{ pagination.page