diff --git a/.vscode/settings.json b/.vscode/settings.json index 2c11cb1..1d2895a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "Bandcamp", "bradleyshellnut", "iconify", "Mullvad", diff --git a/src/lib/components/bandcamp/index.svelte b/src/lib/components/bandcamp/index.svelte new file mode 100644 index 0000000..37921e7 --- /dev/null +++ b/src/lib/components/bandcamp/index.svelte @@ -0,0 +1,90 @@ + + +
+

Currently listening to:

+
+ {#each displayAlbums as album} +
+
+ + {`Album + +
+ +

{album.title.length > 20 ? `${album.title.slice(0, 20)}...` : album.title}

+

by {album.artist}

+
+
+ {/each} +
+
+ + \ No newline at end of file diff --git a/src/lib/types/album.ts b/src/lib/types/album.ts new file mode 100644 index 0000000..b0e2c03 --- /dev/null +++ b/src/lib/types/album.ts @@ -0,0 +1,6 @@ +export type Album = { + url: string; + artwork: string; + title: string; + artist: string; +}; diff --git a/src/lib/util/fetchBandcampAlbums.ts b/src/lib/util/fetchBandcampAlbums.ts new file mode 100644 index 0000000..3578e84 --- /dev/null +++ b/src/lib/util/fetchBandcampAlbums.ts @@ -0,0 +1,40 @@ +// import * as htmlparser2 from 'htmlparser2'; +import scrapeIt from 'scrape-it'; +import type { Album } from '../types/album'; + +export async function fetchBandcampAlbums() { + try { + const { data } = await scrapeIt('https://bandcamp.com/royvalentine', { + collectionItems: { + listItem: '.collection-item-container', + data: { + url: { + selector: '.collection-title-details > a.item-link', + attr: 'href' + }, + artwork: { + selector: 'div.collection-item-art-container a img', + attr: 'src' + }, + title: { + selector: 'span.item-link-alt > div.collection-item-title' + }, + artist: { + selector: 'span.item-link-alt > div.collection-item-artist' + } + } + } + }); + + const albums: Album[] = data?.collectionItems || []; + console.log(`Albums ${JSON.stringify(albums)}`); + + if (albums && albums?.length > 0) { + return albums; + } else { + return []; + } + } catch (error) { + console.log(error); + } +} diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts new file mode 100644 index 0000000..07ecbce --- /dev/null +++ b/src/routes/+page.server.ts @@ -0,0 +1,12 @@ +import type { PageServerLoad } from './lib/$types'; +import { fetchBandcampAlbums } from '$root/lib/util/fetchBandcampAlbums'; + +export const load: PageServerLoad = async ({ setHeaders }) => { + const albums = await fetchBandcampAlbums(); + setHeaders({ + 'cache-control': 'max-age=43200' + }); + return { + albums + }; +}; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3c58e7f..4300c57 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,7 +1,13 @@ - + + Portfolio | Bradley Shellnut +

Portfolio!