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

site-links.ts

35 lines · 1002 B · TypeScript
import { packageContext } from 'kody:runtime'
import type { SiteConfig } from './domain/types.ts'
import { joinUrl, previewLink, publicBaseUrl } from './domain/urls.ts'
import {
	getPreviewToken,
	readHostedUrl,
	type SiteStorage,
} from './store/site-store.ts'

/**
 * Live and preview links for export results. Both are `null` until the app has
 * been opened once (that is when it records its hosted URL) unless `siteUrl` is set.
 */
export async function siteLinks(
	storage: SiteStorage,
	config: SiteConfig,
	path = '/',
) {
	const base = publicBaseUrl(
		config,
		packageContext?.hostedUrl ?? (await readHostedUrl(storage)),
	)
	if (!base) return { liveUrl: null, previewUrl: null }
	const token = await getPreviewToken(storage)
	const liveUrl = joinUrl(base, path)
	const previewUrl =
		path === '/'
			? previewLink(base, token)
			: `${previewLink(base, token)}&to=${encodeURIComponent(path)}`
	return { liveUrl, previewUrl }
}

export function nowIso() {
	return new Date().toISOString()
}