1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-03 12:46:38 -04:00

more caching and error handling

This commit is contained in:
2025-03-24 11:45:48 -04:00
parent 8890c1d08d
commit d3250bd00e
18 changed files with 335 additions and 327 deletions

View File

@ -54,9 +54,9 @@ export const sendMessage = async (
throw new Error(`[contact form] turnstile validation failed: ${turnstileResponse.status}`);
}
const turnstileData = await turnstileResponse?.json();
const turnstileData = (await turnstileResponse.json()) as { success: boolean };
if (!turnstileData?.success) {
if (!turnstileData.success) {
return {
success: false,
message: "Did you complete the CAPTCHA? (If you're human, that is...)",

View File

@ -54,7 +54,7 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => {
const { slug } = await params;
// get the post's title and image filename from its frontmatter
const { title, image: imagePath } = await getFrontMatter(slug);
const frontmatter = await getFrontMatter(slug);
return new ImageResponse(
(
@ -67,7 +67,7 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => {
background: "linear-gradient(0deg, hsla(197, 14%, 57%, 1) 0%, hsla(192, 17%, 94%, 1) 100%)",
}}
>
{imagePath && (
{frontmatter!.image && (
<div
style={{
display: "flex",
@ -78,7 +78,7 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => {
{/* eslint-disable-next-line jsx-a11y/alt-text */}
<img
// @ts-expect-error
src={await getLocalImage(`${POSTS_DIR}/${slug}/${imagePath}`)}
src={await getLocalImage(`${POSTS_DIR}/${slug}/${frontmatter!.image}`)}
style={{ objectFit: "cover", height: "100%", width: "100%" }}
/>
</div>
@ -117,7 +117,7 @@ const Image = async ({ params }: { params: Promise<{ slug: string }> }) => {
color: "#fefefe",
}}
>
{title}
{frontmatter!.title}
</div>
</div>
),

View File

@ -65,7 +65,7 @@
margin-top: 2em;
padding-top: 2em;
border-top: 2px solid var(--colors-light);
min-height: 360px;
min-height: 140px;
}
@media (max-width: 768px) {

View File

@ -37,14 +37,14 @@ export const generateMetadata = async ({ params }: { params: Promise<{ slug: str
const frontmatter = await getFrontMatter(slug);
return addMetadata({
title: frontmatter.title,
description: frontmatter.description,
title: frontmatter!.title,
description: frontmatter!.description,
openGraph: {
type: "article",
authors: [config.authorName],
tags: frontmatter.tags,
publishedTime: frontmatter.date,
modifiedTime: frontmatter.date,
tags: frontmatter!.tags,
publishedTime: frontmatter!.date,
modifiedTime: frontmatter!.date,
},
twitter: {
card: "summary_large_image",
@ -67,13 +67,13 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
item={{
"@context": "https://schema.org",
"@type": "Article",
headline: frontmatter.title,
description: frontmatter.description,
url: frontmatter.permalink,
headline: frontmatter!.title,
description: frontmatter!.description,
url: frontmatter!.permalink,
image: [`${BASE_URL}/notes/${slug}/opengraph-image`],
keywords: frontmatter.tags,
datePublished: frontmatter.date,
dateModified: frontmatter.date,
keywords: frontmatter!.tags,
datePublished: frontmatter!.date,
dateModified: frontmatter!.date,
inLanguage: config.siteLocale,
license: config.licenseUrl,
author: {
@ -85,17 +85,17 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
<div className={styles.meta}>
<div className={styles.metaItem}>
<Link href={`/notes/${frontmatter.slug}` as Route} plain className={styles.metaLink}>
<Link href={`/notes/${frontmatter!.slug}` as Route} plain className={styles.metaLink}>
<CalendarIcon size="1.2em" className={styles.metaIcon} />
<Time date={frontmatter.date} format="MMMM d, y" />
<Time date={frontmatter!.date} format="MMMM d, y" />
</Link>
</div>
{frontmatter.tags && (
{frontmatter!.tags && (
<div className={styles.metaItem}>
<TagIcon size="1.2em" className={styles.metaIcon} />
<span className={styles.metaTags}>
{frontmatter.tags.map((tag) => (
{frontmatter!.tags.map((tag) => (
<span key={tag} title={tag} className={styles.metaTag} aria-label={`Tagged with ${tag}`}>
{tag}
</span>
@ -106,8 +106,8 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
<div className={styles.metaItem}>
<Link
href={`https://github.com/${config.githubRepo}/blob/main/notes/${frontmatter.slug}/index.mdx`}
title={`Edit "${frontmatter.title}" on GitHub`}
href={`https://github.com/${config.githubRepo}/blob/main/notes/${frontmatter!.slug}/index.mdx`}
title={`Edit "${frontmatter!.title}" on GitHub`}
plain
className={styles.metaLink}
>
@ -129,7 +129,7 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
>
<EyeIcon size="1.2em" className={styles.metaIcon} />
<Suspense fallback={<Loading boxes={3} width={20} />}>
<HitCounter slug={`notes/${frontmatter.slug}`} />
<HitCounter slug={`notes/${frontmatter!.slug}`} />
</Suspense>
</div>
</ErrorBoundary>
@ -138,8 +138,8 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
<h1 className={styles.title}>
<Link
href={`/notes/${frontmatter.slug}` as Route}
dangerouslySetInnerHTML={{ __html: frontmatter.htmlTitle || frontmatter.title }}
href={`/notes/${frontmatter!.slug}` as Route}
dangerouslySetInnerHTML={{ __html: frontmatter!.htmlTitle || frontmatter!.title }}
plain
className={styles.link}
/>
@ -147,9 +147,11 @@ const Page = async ({ params }: { params: Promise<{ slug: string }> }) => {
<MDXContent />
{!frontmatter.noComments && (
{!frontmatter!.noComments && (
<div id="comments" className={styles.comments}>
<Comments title={frontmatter.title} />
<Suspense fallback={<Loading boxes={3} width={40} style={{ display: "block", margin: "2em auto" }} />}>
<Comments title={frontmatter!.title} />
</Suspense>
</div>
)}
</>