All files / src/components/docs PublishedDoc.tsx

100% Statements 3/3
50% Branches 1/2
100% Functions 2/2
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                                            11x 11x                                             11x                                
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
import { DocFigureViewer } from "@/components/docs/DocFigureViewer";
import {
  DocsLastUpdated,
  type DocsPage,
} from "@/components/docs/DocsLastUpdated";
import { ExternalA } from "@/components/docs/ExternalA";
import { LocalizedDocBody } from "@/components/docs/LocalizedDocBody";
import MermaidDiagram from "@/components/MermaidDiagram";
import { docSegments } from "@/lib/docs/markdown";
import { T } from "@/lib/i18n/translate";
import { REPO_URL, type PublishedDoc } from "@/lib/docs/published-docs";
 
/** One document published from docs/, rendered from its Markdown at build
 *  time, with the link back to its section and to its source on GitHub.
 *  `backLabel` is the section's menu label, translated from the nav area. */
export function PublishedDocPage({
  doc,
  backHref,
  backLabel,
  lastUpdatedPage,
}: {
  doc: PublishedDoc;
  backHref: string;
  backLabel: string;
  lastUpdatedPage: DocsPage;
}) {
  // Images go through the base-path placeholder (docSegments). In another
  // language LocalizedDocBody swaps in the translation (ADR-071).
  const segments = docSegments(doc.markdown);
  return (
    <div className="max-w-4xl mx-auto px-6 py-12">
      <Link
        href={backHref}
        className="inline-flex items-center gap-1 text-sm text-(--text-secondary) hover:text-(--text-primary) mb-6"
      >
        <ArrowLeft size={14} /> <T area="nav">{backLabel}</T>
      </Link>
      <div className="flex flex-wrap items-center gap-x-4 gap-y-1 mb-6">
        <DocsLastUpdated page={lastUpdatedPage} />
        <ExternalA
          href={`${REPO_URL}/blob/main/${doc.source}`}
          className="inline-flex items-center gap-1 text-xs text-(--accent) underline mb-4"
          iconSize={11}
        >
          <code>{doc.source}</code> <T area="docsCommon">{"on GitHub"}</T>
        </ExternalA>
      </div>
      {/* A click on a diagram or screenshot opens it full screen with zoom. */}
      <article className="doc-prose" data-testid="published-doc">
        <DocFigureViewer>
          <LocalizedDocBody section={doc.section} slug={doc.slug}>
            {segments.map((seg, i) =>
              seg.kind === "mermaid" ? (
                <MermaidDiagram key={i} chart={seg.chart} />
              ) : (
                <div
                  key={i}
                  // The HTML comes from the repository's own Markdown, rendered at build time.
                  dangerouslySetInnerHTML={{ __html: seg.html }}
                />
              ),
            )}
          </LocalizedDocBody>
        </DocFigureViewer>
      </article>
    </div>
  );
}