const INTERNAL_ORIGINS = [
  process.env.URL,
  "https://neuf.no",
].filter(Boolean) as string[];

/** Root-relative href if the URL points at this site, else null. */
export function internalHref(href: string): string | null {
  if (href.startsWith("/")) {
    return href;
  }
  const origin = INTERNAL_ORIGINS.find(
    (o) => href === o || href.startsWith(o + "/"),
  );
  if (!origin) {
    return null;
  }
  const url = new URL(href);
  return url.pathname + url.search + url.hash;
}
