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

about.tsx

69 lines · 2.0 KB · TypeScript
/** @jsxRuntime automatic */
/** @jsxImportSource remix/component */
import { unsafeHTML } from 'remix/component'
import type { Action } from 'remix/router'
import { markdownToText, renderMarkdown } from '../../src/domain/markdown.ts'
import { canonicalUrl, loadSite } from '../data/site.ts'
import { routes } from '../routes.ts'
import { contactLinks } from '../ui/contact-links.tsx'
import { icon } from '../ui/icons.tsx'
import { ogImage } from '../ui/og-image.ts'
import { picture } from '../ui/picture.tsx'
import { render } from '../ui/render.tsx'

function initials(name: string) {
	const letters = name
		.split(/\s+/)
		.filter(Boolean)
		.map((word) => word[0]!.toUpperCase())
	return letters.length > 1
		? letters[0]! + letters[letters.length - 1]!
		: (letters[0] ?? '·')
}

export default {
	async handler(context) {
		const site = await loadSite(context)
		const { config } = site.content
		return render(
			site,
			{
				title: 'About',
				description: markdownToText(config.bio, 160),
				canonical: canonicalUrl(site, routes.about.href()),
				nav: 'about',
				...ogImage(site, config.headshot),
			},
			<section class="wrap section about">
				<div class="about-portrait">
					{config.headshot ? (
						picture(site, config.headshot, {
							sizes: '(max-width: 760px) 70vw, 360px',
							priority: true,
							class: 'headshot',
						})
					) : (
						<div class="monogram" aria-hidden="true">
							{initials(config.photographerName)}
						</div>
					)}
				</div>
				<div class="about-text">
					<h1>{config.photographerName}</h1>
					{config.location ? <p class="eyebrow">{config.location}</p> : null}
					{/* renderMarkdown escapes all text and only emits a fixed set of tags and safe links. */}
					<div
						class="prose"
						innerHTML={unsafeHTML(renderMarkdown(config.bio))}
					/>
					<p class="actions">
						<a class="button" href={routes.contact.index.href()}>
							{icon('mail')} Get in touch
						</a>
					</p>
					{contactLinks(config)}
				</div>
			</section>,
		)
	},
} satisfies Action<typeof routes.about>