pageAt

tcmts.site.pageAt · #kpkybjig · term · runs anywhere

The page of the site a path of the docs app is: / (the index), /apps or /apps.html; undefined for any other path (the code browser's, an example's), which isn't the app's.

import type { Page } from "#codebase/tcmts/site";

export function pageAt(path: string, pages: Page[]): Page | undefined {
  const m = /^\/([^/]*?)(?:\.html)?$/.exec(path);
  return m ? pages.find((p) => p.file === `${m[1] || "index"}.html`) : undefined;
}

uses

used by