From 8569347c274ef50efef91a4a43e7e7822c807b87 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 1 Mar 2026 22:36:11 -0600 Subject: [PATCH] Leverage adjacent meta for about description --- app/about/edit/page.tsx | 22 ++------------- app/about/page.tsx | 46 +++++++++++--------------------- src/about/AboutPageClient.tsx | 38 +++++++++++++------------- src/about/AdminAboutEditPage.tsx | 11 ++++---- src/about/data.ts | 37 +++++++++++++++++++++++++ src/about/index.ts | 7 +++++ 6 files changed, 84 insertions(+), 77 deletions(-) create mode 100644 src/about/data.ts diff --git a/app/about/edit/page.tsx b/app/about/edit/page.tsx index c02bbdd6..02f22404 100644 --- a/app/about/edit/page.tsx +++ b/app/about/edit/page.tsx @@ -1,12 +1,11 @@ import AdminAboutEditPage from '@/about/AdminAboutEditPage'; -import { getAbout } from '@/about/query'; +import { getAboutData } from '@/about/data'; import { PRESERVE_ORIGINAL_UPLOADS } from '@/app/config'; import { feedQueryOptions } from '@/feed'; import { getPhotosCached, getPhotosMetaCached, } from '@/photo/cache'; -import { getPhoto } from '@/photo/query'; import { TAG_FAVS } from '@/tag'; const PHOTO_CHOOSER_QUERY_OPTIONS = feedQueryOptions({ @@ -25,24 +24,7 @@ export default async function AboutEditPage() { photosCount, photosFavs, ] = await Promise.all([ - getAbout() - .then(async about => { - const photoAvatar = about?.photoIdAvatar - ? await getPhoto(about?.photoIdAvatar ?? '', true) - .catch(() => undefined) - : undefined; - - const photoHero = about?.photoIdHero - ? await getPhoto(about?.photoIdHero ?? '', true) - .catch(() => undefined) - : undefined; - - return { - about, - photoAvatar, - photoHero, - }; - }) + getAboutData() .catch(() => ({ about: undefined, photoAvatar: undefined, diff --git a/app/about/page.tsx b/app/about/page.tsx index 6d6706dc..874da7cb 100644 --- a/app/about/page.tsx +++ b/app/about/page.tsx @@ -1,5 +1,6 @@ +import { getDescriptionWithFallback } from '@/about'; import AboutPageClient from '@/about/AboutPageClient'; -import { getAboutCached } from '@/about/cache'; +import { getAboutDataCached } from '@/about/data'; import { SHOW_ABOUT_PAGE } from '@/app/config'; import { PATH_ROOT } from '@/app/path'; import { getDataForCategoriesCached } from '@/category/cache'; @@ -7,11 +8,7 @@ import { getLastModifiedForCategories, NULL_CATEGORY_DATA, } from '@/category/data'; -import { - getPhotoCached, - getPhotosCached, - getPhotosMetaCached, -} from '@/photo/cache'; +import { getPhotosMetaCached } from '@/photo/cache'; import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { getAllPhotoIdsWithUpdatedAt } from '@/photo/query'; import { TAG_FAVS } from '@/tag'; @@ -34,26 +31,8 @@ export default async function AboutPage() { photos, categories, ] = await Promise.all([ - getAboutCached() - .then(async about => { - const photoAvatar = await (about?.photoIdAvatar - ? getPhotoCached(about?.photoIdAvatar ?? '', true) - : undefined); - const photoHero = await (about?.photoIdHero - ? getPhotoCached(about?.photoIdHero ?? '', true) - // Fall back to favorite photos if no hero photo is set - : getPhotosCached({ tag: TAG_FAVS, limit: 1 }) - .then(photos => photos.length > 0 - ? photos[0] - // Fall back to oldest photo if no favorite photos exist - : getPhotosCached({ limit: 1, sortBy: 'takenAtAsc' }) - .then(photos => photos[0]))); - return { - about, - photoAvatar, - photoHero, - }; - }).catch(() => ({ + getAboutDataCached() + .catch(() => ({ about: undefined, photoAvatar: undefined, photoHero: undefined, @@ -63,10 +42,15 @@ export default async function AboutPage() { getDataForCategoriesCached().catch(() => (NULL_CATEGORY_DATA)), ]); - const description = about?.description - ?
+ const description = getDescriptionWithFallback(about); + + const descriptionHtml = description + ?
: undefined; const { @@ -88,7 +72,7 @@ export default async function AboutPage() { ? {isUserSignedIn && }
- {description - ?
- {description} -
+ {descriptionHtml + ? descriptionHtml : isUserSignedIn && - - } - includeContainer={false} - className="gap-3! p-6!" + - Add optional description - - } + } + includeContainer={false} + className="gap-3! p-6!" + > + Add optional description + + } >(about ?? {}); - const convertUrlToPhotoId = (url?: string) => url?.split('/').pop(); - return ( setAboutForm(form => ({ ...form, photoIdAvatar }))} photo={photoAvatar} @@ -74,15 +72,16 @@ export default function AdminAboutEditPage({ label="Description" type="textarea" value={aboutForm?.description ?? ''} + placeholder={getDescriptionWithFallback(about)} onChange={description => setAboutForm(form => ({ ...form, description }))} /> setAboutForm(form => - ({ ...form, photoIdHero: convertUrlToPhotoId(photoIdHero) }))} + ({ ...form, photoIdHero }))} photo={photoHero} photos={photos} photosCount={photosCount} diff --git a/src/about/data.ts b/src/about/data.ts new file mode 100644 index 00000000..93101f35 --- /dev/null +++ b/src/about/data.ts @@ -0,0 +1,37 @@ +import { getPhotoCached, getPhotosCached } from '@/photo/cache'; +import { About } from '.'; +import { TAG_FAVS } from '@/tag'; +import { getAbout } from './query'; +import { getAboutCached } from './cache'; + +const getAboutAvatar = (about?: About) => + about?.photoIdAvatar + ? getPhotoCached(about?.photoIdAvatar ?? '', true) + : undefined; + +const getAboutHero = (about?: About) => + about?.photoIdHero + ? getPhotoCached(about?.photoIdHero ?? '', true) + // Fall back to favorite photos if no hero photo is set + : getPhotosCached({ tag: TAG_FAVS, limit: 1 }) + .then(photos => photos.length > 0 + ? photos[0] + // Fall back to oldest photo if no favorite photos exist + : getPhotosCached({ limit: 1, sortBy: 'takenAtAsc' }) + .then(photos => photos[0])); + +export const getAboutData = () => + getAbout() + .then(async about => ({ + about, + photoAvatar: await getAboutAvatar(about), + photoHero: await getAboutHero(about), + })); + +export const getAboutDataCached = () => + getAboutCached() + .then(async about => ({ + about, + photoAvatar: await getAboutAvatar(about), + photoHero: await getAboutHero(about), + })); diff --git a/src/about/index.ts b/src/about/index.ts index 4d1f71bc..cf97a7a7 100644 --- a/src/about/index.ts +++ b/src/about/index.ts @@ -1,3 +1,5 @@ +import { META_DESCRIPTION, SIDEBAR_TEXT } from '@/app/config'; + export interface AboutInsert { id: number title?: string @@ -11,3 +13,8 @@ export interface About extends AboutInsert { createdAt: Date updatedAt: Date } + +export const getDescriptionWithFallback = (about?: About) => + about?.description || + META_DESCRIPTION || + SIDEBAR_TEXT;