// Links to Journal views, built from stable route names through // useLocalePath() (i18n gives every route a per-locale name), never from // concatenated paths. A link to a disabled view (journal.routes.: false) // is null; components then render plain text. import { JOURNAL_ROUTE_NAMES } from '../utils/routes.ts' import type { JournalRoutes } from '../utils/types.ts' export function useJournalLinks() { const localePath = useLocalePath() const routes = (useRuntimeConfig().public.journal as { routes: JournalRoutes }).routes const link = (key: keyof JournalRoutes, params?: Record, query?: Record) => routes[key] === false ? null : localePath({ name: JOURNAL_ROUTE_NAMES[key], params, query }) return { postLink: (slug: string) => link('post', { slug }), categoryLink: (slug: string) => link('category', { category: slug }), tagLink: (slug: string) => link('tag', { tag: slug }), authorLink: (slug: string) => link('author', { author: slug }), indexLink: (page: number = 1) => link('index', undefined, page > 1 ? { page: String(page) } : undefined), } }