Skip to content
← Public packages

@kentcdodds/photo-portfolio

A fast, photo-first portfolio site you update by chatting with your agent: galleries, about, contact, and one-step rollback.

FollowFork

Files

list-galleries.ts

35 lines · 1.4 KB · TypeScript
import { packageStorage } from 'kody:runtime'
import * as s from 'remix/data-schema'
import { summarizeGallery } from './domain/content.ts'
import { parseInput, strictObject } from './domain/validation.ts'
import { siteLinks } from './site-links.ts'
import { pendingChanges, readDraft, readLive } from './store/site-store.ts'

export type ListGalleriesInput = { from?: 'draft' | 'live' }

const listInput = strictObject({
	from: s.optional(s.enum_(['draft', 'live'] as const)),
})

/**
 * List galleries in display order with their photo ids, captions, and alt text.
 *
 * @param raw - `{ from?: 'draft' | 'live' }`, default `'draft'`
 * @returns `{ from, galleries: [{ id, slug, title, featured, photoCount, coverPhotoId, photos: [{ id, alt, caption?, width, height }] }], pending }`
 *
 * @example
 * import listGalleries from 'kody:@kentcdodds/photo-portfolio/list-galleries'
 * const { galleries } = await listGalleries({})
 */
export default async function listGalleries(raw: ListGalleriesInput = {}) {
	const input = parseInput<ListGalleriesInput>(listInput, raw, 'list-galleries')
	const storage = packageStorage()
	const content =
		input.from === 'live' ? await readLive(storage) : await readDraft(storage)
	return {
		from: input.from ?? 'draft',
		galleries: content.galleries.map(summarizeGallery),
		pending: await pendingChanges(storage),
		...(await siteLinks(storage, content.config, '/galleries')),
	}
}