Moving base page to load data on return.

This commit is contained in:
Bradley Shellnut 2024-12-13 11:58:30 -08:00
parent 4b3a1280f6
commit 036b5ae290

View file

@ -1,60 +1,60 @@
import type { MetaTagsProps } from 'svelte-meta-tags'; import type { MetaTagsProps } from "svelte-meta-tags";
import { PUBLIC_SITE_URL } from '$env/static/public'; import { PUBLIC_SITE_URL } from "$env/static/public";
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from "./$types";
import { fetchBandcampAlbums } from '$lib/util/fetchBandcampAlbums'; import { fetchBandcampAlbums } from "$lib/util/fetchBandcampAlbums";
import type { Album } from '$lib/types/album'; import type { Album } from "$lib/types/album";
import type { ArticlePageLoad } from '$lib/types/article'; import type { ArticlePageLoad } from "$lib/types/article";
export const load: PageServerLoad = async ({ fetch, setHeaders, url }) => { export const load: PageServerLoad = async ({ fetch, setHeaders, url }) => {
let baseUrl; let baseUrl;
if (url.origin.includes('prerender')) { if (url.origin.includes("prerender")) {
baseUrl = PUBLIC_SITE_URL || 'https://bradleyshellnut.com'; baseUrl = PUBLIC_SITE_URL || "https://bradleyshellnut.com";
} else { } else {
baseUrl = new URL(url.origin).href || PUBLIC_SITE_URL || 'https://bradleyshellnut.com'; baseUrl =
new URL(url.origin).href ||
PUBLIC_SITE_URL ||
"https://bradleyshellnut.com";
} }
const currentPageUrl = new URL(url.pathname, url.origin).href; const currentPageUrl = new URL(url.pathname, url.origin).href;
const metaTags: MetaTagsProps = Object.freeze({ const metaTags: MetaTagsProps = Object.freeze({
title: 'Home', title: "Home",
description: "My name is Bradley Shellnut and I'm a Full Stack Software Engineer.", description:
"My name is Bradley Shellnut and I'm a Full Stack Software Engineer.",
openGraph: { openGraph: {
title: 'Home', title: "Home",
description: "My name is Bradley Shellnut and I'm a Full Stack Software Engineer.", description:
"My name is Bradley Shellnut and I'm a Full Stack Software Engineer.",
url: currentPageUrl, url: currentPageUrl,
siteName: 'Bradley Shellnut Personal Website', siteName: "Bradley Shellnut Personal Website",
type: 'website', type: "website",
locale: 'en_US', locale: "en_US",
images: [ images: [
{ {
url: `${baseUrl}og?header=Home | bradleyshellnut.com&page=Hi I'm Bradley Shellnut.&content=I'm a full stack software engineer currently working on Java Spring, PostgreSQL, and React / Angular JS.`, url: `${baseUrl}og?header=Home | bradleyshellnut.com&page=Hi I'm Bradley Shellnut.&content=I'm a full stack software engineer currently working on Java Spring, PostgreSQL, and React / Angular JS.`,
alt: 'Bradley Shellnut Website Home Page', alt: "Bradley Shellnut Website Home Page",
width: 1200, width: 1200,
height: 630 height: 630,
} },
] ],
}, },
twitter: { twitter: {
title: 'Home', title: "Home",
description: 'Home page', description: "Home page",
card: 'summary_large_image', card: "summary_large_image",
image: `${baseUrl}og?header=Home | bradleyshellnut.com&page=Hi I'm Bradley Shellnut.&content=I'm a full stack software engineer currently working on Java Spring, PostgreSQL, and React / Angular JS.`, image: `${baseUrl}og?header=Home | bradleyshellnut.com&page=Hi I'm Bradley Shellnut.&content=I'm a full stack software engineer currently working on Java Spring, PostgreSQL, and React / Angular JS.`,
imageAlt: 'Bradley Shellnut Website Logo' imageAlt: "Bradley Shellnut Website Logo",
}, },
url: currentPageUrl url: currentPageUrl,
}); });
const [albums, articles]: [Album[], ArticlePageLoad] = await Promise.all([
await fetchBandcampAlbums(),
(await fetch(`/api/articles?page=1&limit=3`)).json()
]);
setHeaders({ setHeaders({
'cache-control': 'max-age=43200' "cache-control": "max-age=43200",
}); });
return { return {
baseUrl, baseUrl,
metaTagsChild: metaTags, metaTagsChild: metaTags,
albums, albums: await fetchBandcampAlbums(),
articlesData: articles articlesData: await (await fetch("/api/articles?page=1&limit=3")).json(),
}; };
}; };