chore: lighter builds

This commit is contained in:
Cory Dransfeldt 2024-10-18 07:27:18 -07:00
parent e3cec3c374
commit 8b2648f23f
No known key found for this signature in database
18 changed files with 84 additions and 408 deletions

View file

@ -86,9 +86,9 @@ async function fetchGlobals(supabase) {
function generateMetadata(data, type, globals) {
let title = globals['site_name']
let description = data.description || globals.site_description
const canonicalUrl = data.url ? `${globals.url}${data.url}` : globals.url
const ogImage = `${globals['cdn_url']}${data.image || globals.avatar}?class=w800`
let description = data['description'] || globals['site_description']
const canonicalUrl = data['url'] ? `${globals['url']}${data['url']}` : globals['url']
const ogImage = `${globals['cdn_url']}${data['image'] || globals['avatar']}?class=w800`
description = convert(truncateHtml(md.render(description), 100, {
byWords: true,
@ -140,14 +140,14 @@ function updateDynamicContent(html, metadata, mediaHtml) {
const { document } = parseHTML(html)
const titleTag = document.querySelector('title[data-dynamic="title"]')
if (titleTag) titleTag.textContent = metadata['title']
if (titleTag) titleTag['textContent'] = metadata['title']
const dynamicMetaSelectors = [
{ selector: 'meta[data-dynamic="description"]', attribute: 'content', value: metadata.description },
{ selector: 'meta[data-dynamic="description"]', attribute: 'content', value: metadata['description'] },
{ selector: 'meta[data-dynamic="og:title"]', attribute: 'content', value: metadata['og:title'] },
{ selector: 'meta[data-dynamic="og:description"]', attribute: 'content', value: metadata['og:description'] },
{ selector: 'meta[data-dynamic="og:image"]', attribute: 'content', value: metadata['og:image'] },
{ selector: 'meta[data-dynamic="og:url"]', attribute: 'content', value: metadata.canonical },
{ selector: 'meta[data-dynamic="og:url"]', attribute: 'content', value: metadata['canonical'] },
]
dynamicMetaSelectors.forEach(({ selector, attribute, value }) => {
@ -156,7 +156,7 @@ function updateDynamicContent(html, metadata, mediaHtml) {
})
const canonicalLink = document.querySelector('link[rel="canonical"]')
if (canonicalLink) canonicalLink.setAttribute('href', metadata.canonical)
if (canonicalLink) canonicalLink.setAttribute('href', metadata['canonical'])
const pageElement = document.querySelector('[data-dynamic="page"]')
if (pageElement) pageElement.innerHTML = mediaHtml
@ -182,7 +182,7 @@ function generateAssociatedMediaHTML(data, isGenre = false) {
data[key] && data[key].length
? `<div class="associated-media">
<p class="${category}">${ICON_MAP[icon]} ${title}</p>
<ul>${data[key].map(item => `<li><a href="${item.url}">${item.name || item.title} ${item.year ? `(${item.year})` : ''}</a></li>`).join('')}</ul>
<ul>${data[key].map(item => `<li><a href="${item['url']}">${item['name'] || item['title']} ${item['year'] ? `(${item['year']})` : ''}</a></li>`).join('')}</ul>
</div>`
: ''
)
@ -192,22 +192,22 @@ function generateAssociatedMediaHTML(data, isGenre = false) {
function generateWatchingHTML(media, globals, type) {
const isShow = type === 'show'
const label = isShow ? 'show' : 'movie'
const lastWatched = media.last_watched || (isShow && media.episode?.last_watched_at)
const lastWatched = media['last_watched'] || (isShow && media['episode']?.['last_watched_at'])
return `
<a class="icon-link" href="/watching">${ICON_MAP.arrowLeft} Back to watching</a>
<article class="watching focus">
<img
srcset="
${globals['cdn_url']}${media.backdrop}?class=bannersm&type=webp 256w,
${globals['cdn_url']}${media.backdrop}?class=bannermd&type=webp 512w,
${globals['cdn_url']}${media.backdrop}?class=bannerbase&type=webp 1024w
${globals['cdn_url']}${media['backdrop']}?class=bannersm&type=webp 256w,
${globals['cdn_url']}${media['backdrop']}?class=bannermd&type=webp 512w,
${globals['cdn_url']}${media['backdrop']}?class=bannerbase&type=webp 1024w
"
sizes="(max-width: 450px) 256px,
(max-width: 850px) 512px,
1024px"
src="${globals['cdn_url']}${media.backdrop}?class=bannersm&type=webp"
alt="${media.title} / ${media.year}"
src="${globals['cdn_url']}${media['backdrop']}?class=bannersm&type=webp"
alt="${media['title']} / ${media['year']}"
class="image-banner"
loading="eager"
decoding="async"
@ -215,35 +215,35 @@ function generateWatchingHTML(media, globals, type) {
height="180"
/>
<div class="meta">
<p class="title"><strong>${media.title}</strong> (${media.year})</p>
${media.favorite ? `<p class="sub-meta favorite">${ICON_MAP.heart} This is one of my favorite ${label}s!</p>` : ''}
${media.tattoo ? `<p class="sub-meta tattoo">${ICON_MAP.needle} I have a tattoo inspired by this ${label}!</p>` : ''}
${media.collected ? `<p class="sub-meta collected">${ICON_MAP.circleCheck} This ${label} is in my collection!</p>` : ''}
<p class="title"><strong>${media['title']}</strong> (${media['year']})</p>
${media['favorite'] ? `<p class="sub-meta favorite">${ICON_MAP['heart']} This is one of my favorite ${label}s!</p>` : ''}
${media['tattoo'] ? `<p class="sub-meta tattoo">${ICON_MAP['needle']} I have a tattoo inspired by this ${label}!</p>` : ''}
${media['collected'] ? `<p class="sub-meta collected">${ICON_MAP['circleCheck']} This ${label} is in my collection!</p>` : ''}
${lastWatched ? `<p class="sub-meta">Last watched on <strong class="highlight-text">${formatDate(lastWatched)}</strong></p>` : ''}
</div>
${media.review ? `${warningBanner}<h2>My thoughts</h2><p>${md.render(media.review)}</p>` : ''}
${media['review'] ? `${warningBanner}<h2>My thoughts</h2><p>${md.render(media['review'])}</p>` : ''}
${generateAssociatedMediaHTML(media)}
${media.description ? `<h2>Overview</h2><p>${md.render(media.description)}</p>` : ''}
${media['description'] ? `<h2>Overview</h2><p>${md.render(media['description'])}</p>` : ''}
</article>
`
}
function generateConcertModal(concert) {
const venue = concert.venue_name
? concert.venue_latitude && concert.venue_longitude
? `<a href="https://www.openstreetmap.org/?mlat=${concert.venue_latitude}&mlon=${concert.venue_longitude}#map=18/${concert.venue_latitude}/${concert.venue_longitude}">${concert.venue_name_short}</a>`
: concert.venue_name_short
const venue = concert['venue_name']
? concert['venue_latitude'] && concert['venue_longitude']
? `<a href="https://www.openstreetmap.org/?mlat=${concert['venue_latitude']}&mlon=${concert['venue_longitude']}#map=18/${concert['venue_latitude']}/${concert['venue_longitude']}">${concert['venue_name_short']}</a>`
: concert['venue_name_short']
: ''
const notesModal = concert.notes
? `<input class="modal-input" id="${concert.id}" type="checkbox" tabindex="0" />
<label class="modal-toggle" for="${concert.id}">${ICON_MAP['infoCircle']}</label>
const notesModal = concert['notes']
? `<input class="modal-input" id="${concert['id']}" type="checkbox" tabindex="0" />
<label class="modal-toggle" for="${concert['id']}">${ICON_MAP['infoCircle']}</label>
<div class="modal-wrapper">
<div class="modal-body">
<label class="modal-close" for="${concert.id}">${ICON_MAP['circleX']}</label>
<label class="modal-close" for="${concert['id']}">${ICON_MAP['circleX']}</label>
<div>
<h3>Notes</h3>
${md.render(concert.notes)}
${md.render(concert['notes'])}
</div>
</div>
</div>`
@ -251,30 +251,30 @@ function generateConcertModal(concert) {
return `
<li>
<strong class="highlight-text">${formatDate(concert.date)}</strong> at ${venue}
<strong class="highlight-text">${formatDate(concert['date'])}</strong> at ${venue}
${notesModal}
</li>
`
}
function generateArtistHTML(artist, globals) {
const playLabel = artist?.total_plays === 1 ? 'play' : 'plays'
const concertsList = artist.concerts?.length
const playLabel = artist?.['total_plays'] === 1 ? 'play' : 'plays'
const concertsList = artist['concerts']?.length
? `<hr />
<p id="concerts" class="concerts">
${ICON_MAP['deviceSpeaker']}
I've seen this artist live!
</p>
<ul>${artist.concerts.map(generateConcertModal).join('')}</ul>`
<ul>${artist['concerts'].map(generateConcertModal).join('')}</ul>`
: ''
const albumsTable = artist.albums?.length
const albumsTable = artist['albums']?.length
? `<table>
<tr><th>Album</th><th>Plays</th><th>Year</th></tr>
${artist.albums.map(album => `
${artist['albums'].map(album => `
<tr>
<td>${album.name}</td>
<td>${album.total_plays || 0}</td>
<td>${album.release_year}</td>
<td>${album['name']}</td>
<td>${album['total_plays'] || 0}</td>
<td>${album['release_year']}</td>
</tr>`).join('')}
</table>
<p><em>These are the albums by this artist that are in my collection, not necessarily a comprehensive discography.</em></p>
@ -287,32 +287,32 @@ function generateArtistHTML(artist, globals) {
<div class="artist-display">
<img
srcset="
${globals['cdn_url']}${artist.image}?class=w200&type=webp 200w,
${globals['cdn_url']}${artist.image}?class=w600&type=webp 400w,
${globals['cdn_url']}${artist.image}?class=w800&type=webp 800w
${globals['cdn_url']}${artist['image']}?class=w200&type=webp 200w,
${globals['cdn_url']}${artist['image']}?class=w600&type=webp 400w,
${globals['cdn_url']}${artist['image']}?class=w800&type=webp 800w
"
sizes="(max-width: 450px) 200px,
(max-width: 850px) 400px,
800px"
src="${globals['cdn_url']}${artist.image}?class=w200&type=webp"
alt="${artist.name} / ${artist.country}"
src="${globals['cdn_url']}${artist['image']}?class=w200&type=webp"
alt="${artist['name']} / ${artist['country']}"
loading="eager"
decoding="async"
width="200"
height="200"
/>
<div class="artist-meta">
<p class="title"><strong>${artist.name}</strong></p>
<p class="sub-meta country">${ICON_MAP['mapPin']} ${parseCountryField(artist.country)}</p>
${artist.favorite ? `<p class="sub-meta favorite">${ICON_MAP['heart']} This is one of my favorite artists!</p>` : ''}
${artist.tattoo ? `<p class="sub-meta tattoo">${ICON_MAP['needle']} I have a tattoo inspired by this artist!</p>` : ''}
${artist.total_plays ? `<p class="sub-meta"><strong class="highlight-text">${artist.total_plays} ${playLabel}</strong></p>` : ''}
<p class="sub-meta">${artist.genre ? `<a href="${artist.genre.url}">${artist.genre.name}</a>` : ''}</p>
<p class="title"><strong>${artist['name']}</strong></p>
<p class="sub-meta country">${ICON_MAP['mapPin']} ${parseCountryField(artist['country'])}</p>
${artist['favorite'] ? `<p class="sub-meta favorite">${ICON_MAP['heart']} This is one of my favorite artists!</p>` : ''}
${artist['tattoo'] ? `<p class="sub-meta tattoo">${ICON_MAP['needle']} I have a tattoo inspired by this artist!</p>` : ''}
${artist['total_plays'] ? `<p class="sub-meta"><strong class="highlight-text">${artist['total_plays']} ${playLabel}</strong></p>` : ''}
<p class="sub-meta">${artist['genre'] ? `<a href="${artist['genre']['url']}">${artist['genre']['name']}</a>` : ''}</p>
</div>
</div>
${artist.description ? `
${artist['description'] ? `
<h2>Overview</h2>
<div data-toggle-content class="text-toggle-hidden">${md.render(artist.description)}</div>
<div data-toggle-content class="text-toggle-hidden">${md.render(artist['description'])}</div>
<button data-toggle-button>Show more</button>` : ''
}
${concertsList}
@ -351,40 +351,40 @@ function generateBookHTML(book, globals) {
height="307"
/>
<div class="book-meta">
<p class="title"><strong>${book.title}</strong></p>
${book.rating ? `<p>${book.rating}</p>` : ''}
${book.author ? `<p class="sub-meta">By ${book.author}</p>` : ''}
${book.favorite ? `<p class="sub-meta favorite">${ICON_MAP.heart} This is one of my favorite books!</p>` : ''}
${book.tattoo ? `<p class="sub-meta tattoo">${ICON_MAP.needle} I have a tattoo inspired by this book!</p>` : ''}
<p class="title"><strong>${book['title']}</strong></p>
${book['rating'] ? `<p>${book['rating']}</p>` : ''}
${book['author'] ? `<p class="sub-meta">By ${book['author']}</p>` : ''}
${book['favorite'] ? `<p class="sub-meta favorite">${ICON_MAP['heart']} This is one of my favorite books!</p>` : ''}
${book['tattoo'] ? `<p class="sub-meta tattoo">${ICON_MAP['needle']} I have a tattoo inspired by this book!</p>` : ''}
${status ? `<p class="sub-meta">${status}</p>` : ''}
</div>
</div>
${book.review ? `${warningBanner}<h2>My thoughts</h2><p>${book.review}</p>` : ''}
${book['review'] ? `${warningBanner}<h2>My thoughts</h2><p>${book['review']}</p>` : ''}
${generateAssociatedMediaHTML(book)}
<h2>Overview</h2>
<p>${md.render(book.description)}</p>
<p>${md.render(book['description'])}</p>
</article>
`
}
function generateGenreHTML(genre) {
const artistCount = genre.artists?.length || 0
const artistCount = genre['artists']?.length || 0
const connectingWords = artistCount > 1 ? 'artists are' : 'artist is'
const mediaLinks = generateMediaLinks(genre.artists, 'artist', 5)
const mediaLinks = generateMediaLinks(genre['artists'], 'artist', 5)
return `
<a class="icon-link" href="/music">${ICON_MAP.arrowLeft} Back to music</a>
<h2>${genre.name}</h2>
<a class="icon-link" href="/music">${ICON_MAP['arrowLeft']} Back to music</a>
<h2>${genre['name']}</h2>
<article class="genre-focus">
${mediaLinks ? `
<p>My top <strong class="highlight-text">${genre.name}</strong> ${connectingWords} ${mediaLinks}. I've listened to <strong class="highlight-text">${genre.total_plays}</strong> tracks from this genre.</p>
<p>My top <strong class="highlight-text">${genre['name']}</strong> ${connectingWords} ${mediaLinks}. I've listened to <strong class="highlight-text">${genre['total_plays']}</strong> tracks from this genre.</p>
<hr />` : ''}
${generateAssociatedMediaHTML(genre, true)}
${genre.description ? `
${genre['description'] ? `
<h3>Overview</h3>
<div data-toggle-content class="text-toggle-hidden">
${md.render(genre.description)}
<p><a href="${genre.wiki_link}">Continue reading at Wikipedia.</a></p>
${md.render(genre['description'])}
<p><a href="${genre['wiki_link']}">Continue reading at Wikipedia.</a></p>
<p><em>Wikipedia content provided under the terms of the <a href="https://creativecommons.org/licenses/by-sa/3.0/">Creative Commons BY-SA license</a>.</em></p>
</div>
<button data-toggle-button>Show more</button>` : ''}