linkingTo

tcmts.cli.files.linkingTo · #6f4yjpum · term · runs on the server

uses tcmts.cli.files.linkedName, which uses tcmts.cli.files.fileFormat, which uses node:path

The pages (Markdown files) that link to the file named name.

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { filesIn, formatOf, linkedName, markdownLinks } from "#codebase/tcmts/cli/files";

export function linkingTo(cb: Codebase, name: string): string[] {
  const out: string[] = [];
  for (const [page, rec] of filesIn(cb, "")) {
    if (page === name || formatOf(rec) !== "md") continue;
    if (markdownLinks(rec.sourceText).some((l) => !l.code && linkedName(page, l.target)?.name === name)) out.push(page);
  }
  return out;
}

uses

used by