Fixing eslint and types. Cleaning up bandcamp scrape and tests.

This commit is contained in:
Bradley Shellnut 2023-12-11 16:26:10 -08:00
parent 6013181aa1
commit 47340c102e
9 changed files with 34 additions and 25 deletions

View file

@ -1,20 +1,30 @@
module.exports = { module.exports = {
root: true, root: true,
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier'
],
parser: '@typescript-eslint/parser', parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'], plugins: ['@typescript-eslint'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: { parserOptions: {
sourceType: 'module', sourceType: 'module',
ecmaVersion: 2020 ecmaVersion: 2020,
extraFileExtensions: ['.svelte']
}, },
env: { env: {
browser: true, browser: true,
es2017: true, es2017: true,
node: true node: true
} },
}; overrides: [
{
files: ['*.svelte'],
parser: 'svelte-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
]
};

View file

@ -6,7 +6,9 @@ import { html as toReactNode } from 'satori-html';
import firaSansSemiBold from '$lib/fonts/FiraSans-SemiBold.ttf'; import firaSansSemiBold from '$lib/fonts/FiraSans-SemiBold.ttf';
import { dev } from '$app/environment'; import { dev } from '$app/environment';
export async function componentToPng(component, props, height, width) { export async function componentToPng(component,
props: Record<string, string | undefined>,
height: number, width: number) {
const result = component.render(props); const result = component.render(props);
const markup = toReactNode(`${result.html}<style lang="css">${result.css.code}</style>`); const markup = toReactNode(`${result.html}<style lang="css">${result.css.code}</style>`);

View file

@ -1,9 +1,12 @@
export type BandCampResults = {
collectionItems: Album[];
}
export type Album = { export type Album = {
url: string; url: string;
artwork: string; artwork: string;
title: string; title: string;
artist: string; artist: string;
src?: ExternalImageSource[];
}; };
export type ExternalImageSource = { export type ExternalImageSource = {

View file

@ -4,14 +4,12 @@ import { fetchBandcampAlbums } from './fetchBandcampAlbums';
describe('test fetchBandcampAlbums', () => { describe('test fetchBandcampAlbums', () => {
it('fetches bandcamp albums', async () => { it('fetches bandcamp albums', async () => {
const albums = await fetchBandcampAlbums(); const albums = await fetchBandcampAlbums();
console.log('albums');
expect(albums).not.toBeNull(); expect(albums).not.toBeNull();
expect(albums).toBeTruthy(); expect(albums).toBeTruthy();
expect(albums?.length).toBeGreaterThan(0); expect(albums?.length).toBeGreaterThan(0);
for (const album of albums) { for (const album of albums) {
expect(album?.artist).toHaveLength; expect(album?.artist).toHaveLength;
expect(album?.artwork).toHaveLength; expect(album?.artwork).toHaveLength;
expect(album?.src).toHaveLength;
expect(album?.title).toHaveLength; expect(album?.title).toHaveLength;
expect(album?.url).toHaveLength; expect(album?.url).toHaveLength;
} }

View file

@ -2,7 +2,7 @@ import { BANDCAMP_USERNAME, USE_REDIS_CACHE } from '$env/static/private';
import scrapeIt from 'scrape-it'; import scrapeIt from 'scrape-it';
import type { ScrapeResult } from 'scrape-it'; import type { ScrapeResult } from 'scrape-it';
import { redis } from '$lib/server/redis'; import { redis } from '$lib/server/redis';
import type { Album } from '../types/album'; import type { Album, BandCampResults } from '../types/album';
export async function fetchBandcampAlbums() { export async function fetchBandcampAlbums() {
try { try {
@ -18,7 +18,7 @@ export async function fetchBandcampAlbums() {
} }
} }
const { data }: ScrapeResult<Album[]> = await scrapeIt( const { data }: ScrapeResult<BandCampResults> = await scrapeIt(
`https://bandcamp.com/${BANDCAMP_USERNAME}`, `https://bandcamp.com/${BANDCAMP_USERNAME}`,
{ {
collectionItems: { collectionItems: {

View file

@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import Img from '@zerodevx/svelte-img';
import Graphql from '@iconify-icons/simple-icons/graphql'; import Graphql from '@iconify-icons/simple-icons/graphql';
import Nextdotjs from '@iconify-icons/simple-icons/nextdotjs'; import Nextdotjs from '@iconify-icons/simple-icons/nextdotjs';
import Prisma from '@iconify-icons/simple-icons/prisma'; import Prisma from '@iconify-icons/simple-icons/prisma';
@ -300,7 +299,6 @@
& p { & p {
margin: 1rem; margin: 1rem;
/* padding: 0.2rem; */
} }
} }
@ -319,7 +317,6 @@
font-weight: bold; font-weight: bold;
margin-right: 0; margin-right: 0;
padding: 0;
text-decoration: none; text-decoration: none;
padding: 0.3rem; padding: 0.3rem;
margin-left: 1rem; margin-left: 1rem;

View file

@ -1,5 +1,4 @@
import { redirect } from '@sveltejs/kit'; import { redirect } from '@sveltejs/kit';
import type { PageServerLoad } from './$types';
export const load = async () => { export const load = async () => {
throw redirect(302, '/articles/1'); throw redirect(302, '/articles/1');

View file

@ -3,6 +3,7 @@ import type { PageServerLoad } from './$types';
import { WALLABAG_MAX_PAGES } from '$env/static/private'; import { WALLABAG_MAX_PAGES } from '$env/static/private';
import { PUBLIC_SITE_URL } from '$env/static/public'; import { PUBLIC_SITE_URL } from '$env/static/public';
import type { Article } from '$lib/types/article'; import type { Article } from '$lib/types/article';
import type { MetaTagsProps } from 'svelte-meta-tags';
export type ArticlePageLoad = { export type ArticlePageLoad = {
articles: Article[]; articles: Article[];

View file

@ -1,11 +1,10 @@
import type { RequestHandler } from '@sveltejs/kit';
import SocialImageCard from '$lib/components/socialImageCard.svelte'; import SocialImageCard from '$lib/components/socialImageCard.svelte';
import { componentToPng } from '$root/lib/renderImage'; import { componentToPng } from '$root/lib/renderImage';
const height = 630; const height = 630;
const width = 1200; const width = 1200;
export const GET: RequestHandler = async ({ url }) => { export async function GET({ url }) {
try { try {
const ogImage = `${new URL(url.origin).href}/b_shell_nut_favicon.png`; const ogImage = `${new URL(url.origin).href}/b_shell_nut_favicon.png`;
const header = url.searchParams.get('header') ?? undefined; const header = url.searchParams.get('header') ?? undefined;
@ -17,11 +16,11 @@ export const GET: RequestHandler = async ({ url }) => {
page, page,
content, content,
image: ogImage, image: ogImage,
width, width: `${width}`,
height, height: `${height}`,
url: new URL(url.origin).href url: new URL(url.origin).href
}, height, width); }, height, width);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
}; }