import type { Reroute } from '@sveltejs/kit' import { SINGLE_COMMUNITY } from '$lib/app/single' import { resolvePrettyPath } from '$lib/app/slug' /** * Single-community mode: serve the community page for "/" and for every route that would * otherwise list or browse communities. The address bar keeps the original path, so the home * page stays "/". The community's own sub-pages (e.g. /c//settings) are left alone. */ export const reroute: Reroute = ({ url }) => { if (!SINGLE_COMMUNITY) return const path = url.pathname // Pretty post URLs: /p// -> /post//. const post = resolvePrettyPath(path) if (post) return post const home = `/c/${SINGLE_COMMUNITY}` if (path === '/' || path === '/communities' || path.startsWith('/explore')) return home const other = path.match(/^\/c\/([^/]+)\/?$/) if (other && other[1] !== SINGLE_COMMUNITY) return home }