Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
3a4e5ad
feat(portal): clean the reported page address
Nov 11, 2026
5e2b3ad
refactor(portal): keep the kept query names in a Set
Nov 11, 2026
0448f11
feat(portal): report page views to the data layer and GA4
Nov 11, 2026
b9312eb
feat(portal): hold vendor tags back while the address holds an OAuth …
Nov 12, 2026
2259787
refactor(portal): drop the replay list until listed scripts can subsc…
Nov 12, 2026
b41a5ce
feat(portal): start analytics from the portal bundle
Nov 12, 2026
ac5b704
refactor(portal): make the analytics instance a class with flat methods
Nov 12, 2026
7541922
refactor(portal): load vendor tags as soon as the bundle starts
Nov 12, 2026
b744687
feat(portal): add the site verification meta and keep the playground …
Nov 12, 2026
5c0a854
feat(portal): read portal.analytics and portal.seo from apimatic.json
Nov 12, 2026
7ea287d
refactor(portal): leave vendor value formats to the vendors
Nov 12, 2026
fe93025
feat(portal): add --no-analytics and leave the vendors out of the ide…
Nov 12, 2026
7b1bcf8
feat(portal): describe portal.analytics and portal.seo in the schema
Nov 12, 2026
5851a78
test(portal): prove analytics and the verification tag in a built portal
Nov 12, 2026
c860c27
docs(portal): document portal.analytics
Nov 12, 2026
3f76503
feat(portal): report Markdown copies, plugin installs and SDK downloads
Nov 12, 2026
7611487
feat(portal): report code copies with the block's language
Nov 12, 2026
18e68aa
feat(portal): report searches with the term, the pick and the count
Nov 12, 2026
64a98f9
feat(portal): report the not-found page with a clean referrer
Nov 12, 2026
a3657e0
feat(portal): report playground requests without their contents
Nov 12, 2026
cc31714
docs(portal): document the eight portal events
Nov 12, 2026
b162281
fix(portal): report each event once, from the page it belongs to
Nov 12, 2026
0fbf185
fix(portal): keep the GA4 warning quiet under --no-analytics
Nov 12, 2026
b8a13e6
docs(portal): add the analytics build plan
Nov 12, 2026
2dc7c47
fix(portal): report the first page view once the page's head is in place
Nov 13, 2026
be8cc92
refactor(portal): apply --no-analytics in the actions, not the service
Nov 13, 2026
90dc0e9
refactor(portal): share the required-field check between the parsers
Nov 13, 2026
f39de85
fix(portal): report a search once its close has rendered and its resu…
Nov 13, 2026
af91f01
refactor(portal): load whatever the adapter registry builds
Nov 13, 2026
99a4abe
fix(portal): name the page left whichever not-found report lands first
Nov 13, 2026
9518de4
fix(portal): mark only the dialog holding the request form for replays
Nov 13, 2026
54c8c60
fix(portal): forget a request's start when the playground leaves the …
Nov 13, 2026
eee78f6
docs(portal): record the review of 2026-11-13
Nov 13, 2026
d974f46
fix(portal): hold the vendor tags back at any address holding an OAut…
Nov 13, 2026
a2cfc95
fix(portal): start the analytics once per page load, not once per module
Nov 13, 2026
45945e6
fix(portal): report a missing page again when the reader comes back t…
Nov 13, 2026
246accb
fix(portal): keep the cURL sample out of session replays too
Nov 13, 2026
8c4be3f
test(portal): hold every adapter to naming no recording or capture
Nov 13, 2026
7252e77
docs(portal): record the reviewer's findings of 2026-11-13
Nov 13, 2026
42cae7a
refactor(portal): decide the build's vendor tags in one place
Nov 13, 2026
c810cb8
refactor(portal): write the appearance files from writeConfiguration …
Nov 13, 2026
beaecde
refactor(portal): report code copies and searches from their components
Nov 13, 2026
2c78cc1
refactor(portal): move the vendor adapters and the tag loader to vend…
Nov 13, 2026
9f32c1b
fix(portal): send to GA4 through the page's gtag from any instance
Nov 13, 2026
382e850
docs(portal): record the second review of analytics.ts
Nov 13, 2026
2a4f79c
test(portal): expect the cURL sample marked beside the playground header
Nov 13, 2026
09a22ba
refactor(portal): define --no-analytics once, saying what it leaves out
Nov 13, 2026
18b9a3b
refactor(portal): apply --no-analytics where the settings are read
Nov 13, 2026
9635ebb
fix(portal): warn about GA4's page changes on portal serve too
Nov 13, 2026
3f458d5
refactor(portal): leave analytics and seo out of the block quickstart…
Nov 13, 2026
353918b
test(portal): run the portal commands to see --no-analytics reach the…
Nov 13, 2026
1c5a5ff
refactor(portal): drop the import cycle, GTM's no-op send and the nul…
Nov 13, 2026
f9b415a
fix(portal): give GA4's own events the reported address
Nov 13, 2026
15460ba
fix(portal): reload the preview when a config save changes the vendors
Nov 13, 2026
c15f0d3
refactor(portal): time playground requests in the playground
Nov 13, 2026
fa93587
fix(portal): mark the playground dialog from one observer made at sta…
Nov 13, 2026
95c8187
refactor(portal): keep data-portal-playground on the playground wrapper
Nov 13, 2026
a7f1c62
fix(portal): report every code copy from its block's button, by langu…
Nov 13, 2026
97d7df2
test(portal): decide a search's report in a function, and test its se…
Nov 13, 2026
07092fd
fix(portal): show the endpoint bar while the playground loads
Nov 13, 2026
94e99c2
refactor(portal): cut the analytics comments to one line each
Nov 13, 2026
96885d4
chore(portal): keep the analytics plans out of the pull request
Nov 13, 2026
1bb6dfb
fix(portal): hold the vendor tags back on the page a sign-in returns to
Nov 15, 2026
f54b30e
fix(portal): report a missing page only once the router has settled o…
Nov 16, 2026
eba596e
fix(portal): send one value per language, for copies and downloads alike
Nov 16, 2026
5e8a9f5
fix(portal): report a search's result as a whole address, and cap its…
Nov 16, 2026
89f6b79
fix(portal): leave ref out of the query names every portal keeps
Nov 16, 2026
c69d66a
test(portal): pin the shipped event names and keys
Nov 16, 2026
1c93ac2
refactor(portal): make every caller choose the build's options
Nov 16, 2026
ec787d1
test(portal): hold a built page to the cURL sample's markers and the …
Nov 16, 2026
2c025b4
docs(portal): say in the schema that a GTM environment is for staging…
Nov 16, 2026
2ffa3b6
fix(portal): name a language outside the bundle by its ID, whichever …
Nov 16, 2026
02200bb
test(portal): pin an API request's status as text, digits or client_e…
Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,15 @@ Generate a static API Documentation Portal.

```
USAGE
$ apimatic portal generate [--zip] [-i <value>] [-d <value>] [-f] [-k <value>]
$ apimatic portal generate [--zip] [--no-analytics] [-i <value>] [-d <value>] [-f] [-k <value>]

FLAGS
-d, --destination=<value> [default: <input>/portal] path where the portal will be generated.
-f, --force overwrite changes without asking for user consent.
-i, --input=<value> [default: ./] path to the parent directory containing the 'src' directory, which includes
API specifications and configuration files.
-k, --auth-key=<value> override current authentication state with an authentication key.
--no-analytics leave out the Google Tag Manager and Google Analytics tags set in 'portal.analytics'.
--zip write the generated portal as a .zip archive.

DESCRIPTION
Expand Down Expand Up @@ -338,14 +339,15 @@ Preview your API Documentation Portal with live reload.

```
USAGE
$ apimatic portal serve [-p 23513] [-o] [-i <value>] [-k <value>]
$ apimatic portal serve [-p 23513] [-o] [--no-analytics] [-i <value>] [-k <value>]

FLAGS
-i, --input=<value> [default: ./] path to the parent directory containing the 'src' directory, which includes API
specifications and configuration files.
-k, --auth-key=<value> override current authentication state with an authentication key.
-o, --open open the portal in the default browser.
-p, --port=23513 [default: 23513] port to serve the portal on.
--no-analytics leave out the Google Tag Manager and Google Analytics tags set in 'portal.analytics'.

DESCRIPTION
Preview your API Documentation Portal with live reload.
Expand Down
73 changes: 73 additions & 0 deletions apimatic.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,79 @@
}
}
},
"analytics": {
"type": "object",
"description": "Analytics the portal loads. Every page view goes to window.dataLayer as docs_page_view, and to GA4 when a measurement ID is set.",
"additionalProperties": false,
"properties": {
"googleTagManager": {
"type": "object",
"additionalProperties": false,
"required": ["containerId"],
"properties": {
"containerId": {
"allOf": [
{
"$ref": "#/definitions/nonBlank"
}
],
"description": "The container's ID, for example 'GTM-ABC123'."
},
"environment": {
"type": "object",
"description": "A GTM environment, for a staging build only, which loads the container's staging version: the gtm_auth and gtm_preview values from the environment's snippet. Both are public in the built portal, so a production portal sets none.",
"additionalProperties": false,
"required": ["auth", "preview"],
"properties": {
"auth": {
"$ref": "#/definitions/nonBlank"
},
"preview": {
"$ref": "#/definitions/nonBlank"
}
}
}
}
},
"googleAnalytics": {
"type": "object",
"additionalProperties": false,
"required": ["measurementId"],
"properties": {
"measurementId": {
"allOf": [
{
"$ref": "#/definitions/nonBlank"
}
],
"description": "The GA4 web stream's measurement ID, for example 'G-ABC123'. The portal sends its own page views, so turn off the stream's 'Page changes based on browser history events'. Don't also add a GA4 tag to the GTM container: every hit would count twice."
}
}
},
"keepQueryParams": {
"type": "array",
"description": "Your own link tags to keep in reported page addresses. Campaign (utm_), ad-click and cross-domain tags are kept already; every other query parameter is dropped.",
"items": {
"$ref": "#/definitions/nonBlank"
}
}
}
},
"seo": {
"type": "object",
"description": "Search engine settings.",
"additionalProperties": false,
"properties": {
"googleSiteVerification": {
"allOf": [
{
"$ref": "#/definitions/nonBlank"
}
],
"description": "The content value of Google's site verification meta tag, for Search Console. Not needed for a Domain property verified by DNS."
}
}
},
"pluginUrl": {
"type": "string",
"description": "Where the context plugin is hosted, starting with 'https://' and with no spaces. The Context Plugin page installs it from here, and the portal carries no copy of its own.",
Expand Down
2 changes: 1 addition & 1 deletion portal-pages/sdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ title: "{{name}} SDK"
description: "Install and start using the {{name}} SDK."
---

<SdkActions download="{{download}}" source="{{source}}" packageUrl="{{packageUrl}}" registry="{{registry}}" />
<SdkActions language="{{language}}" download="{{download}}" source="{{source}}" packageUrl="{{packageUrl}}" registry="{{registry}}" />

<include>{{docs}}</include>
4 changes: 2 additions & 2 deletions portal-template/src/components/api-markdown.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createMarkdownRenderer } from 'fumadocs-core/content/md';
import { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
import defaultMdxComponents from 'fumadocs-ui/mdx';
import { Children, type ComponentProps, type ReactElement } from 'react';
import { withBasePath } from '@/lib/base-path';
import { languageOf } from '@/lib/code-titles';
import { ReportedCodeBlock } from './code-copy';

const { Markdown } = createMarkdownRenderer({ remarkPlugins: [remarkGfm] });

Expand All @@ -28,5 +28,5 @@ function CodeBlock({ children }: ComponentProps<'pre'>) {
const text = code.props.children;
if (typeof text !== 'string') return null;
const language = languageOf(code.props.className?.split(' ') ?? []) ?? 'text';
return <DynamicCodeBlock lang={language} code={text.trimEnd()} />;
return <ReportedCodeBlock lang={language} code={text.trimEnd()} />;
}
18 changes: 17 additions & 1 deletion portal-template/src/components/api-page.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { lazy, Suspense } from 'react';
import { createOpenAPIPage } from 'fumadocs-openapi/ui';
import { withBasePath } from '@/lib/base-path';
import { mediaAdapters } from '@/lib/media-adapters';
import { oauthCallbackPath } from '@/lib/oauth-callback';
import { REPLAY_MARKERS } from '@/lib/replay-markers';
import { ApiMarkdown } from './api-markdown';
import { ReportedCodeBlock } from './code-copy';
import { EndpointBar } from './endpoint-bar';
import { renderExampleLayout } from './example-layout';
import { codeUsages, renderUsageTabs } from './usage-tabs';

// Its own chunk, as Fumadocs loads it: the playground's forms are not in every page's bundle.
const Playground = lazy(() => import('./playground'));

export const OpenAPIPage = createOpenAPIPage({
codeUsages,
generateTypeScriptDefinitions: false,
content: { renderAPIExampleLayout: renderExampleLayout, renderAPIExampleUsageTabs: renderUsageTabs },
components: { Markdown: ApiMarkdown },
components: { Markdown: ApiMarkdown, CodeBlock: ReportedCodeBlock },
mediaAdapters,
oauthRedirectUrl: withBasePath(oauthCallbackPath),
playground: {
render: ({ method, path }) => (
<div {...REPLAY_MARKERS} data-portal-playground="">
<Suspense fallback={<EndpointBar method={method} route={path} />}>
<Playground />
</Suspense>
</div>
)
},
// Portals under paths of one host keep their playground's saved values apart; at the root the keys stay Fumadocs' own.
storageKeyPrefix: `fumadocs-openapi-${withBasePath('/').slice(1)}`
});
34 changes: 34 additions & 0 deletions portal-template/src/components/code-copy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { CodeBlockProps as BlockProps } from 'fumadocs-ui/components/codeblock';
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
import type { CodeBlockProps } from 'fumadocs-openapi';
import { languageId } from '@/lib/languages';
import { analytics } from '@/lib/portal-analytics';

type Actions = NonNullable<BlockProps['Actions']>;

export const reportCodeCopy = (language: string) =>
analytics.report('docs_code_copy', { language: languageId(language) });

// Fumadocs' own, which any Actions a block is given replaces.
const DefaultActions: Actions = ({ className, children }) => (
<div className={className ? `empty:hidden ${className}` : 'empty:hidden'}>{children}</div>
);

/** A block's Actions slot, which Fumadocs hands the copy button: a click on it calls `onCopy`. */
export function reportCopies(onCopy: () => void, Actions: Actions = DefaultActions): Actions {
return ({ className, children }) =>
Actions({
className,
children: children && (
<span className="contents" onClickCapture={onCopy}>
{children}
</span>
)
});
}

/** Fumadocs' highlighted block, as the API reference renders each, reporting its copies with its language. */
export function ReportedCodeBlock({ codeblock, ...props }: CodeBlockProps) {
const Actions = reportCopies(() => reportCodeCopy(props.lang), codeblock?.Actions);
return <DynamicCodeBlock {...props} codeblock={{ ...codeblock, Actions }} />;
}
11 changes: 8 additions & 3 deletions portal-template/src/components/command-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import type { ReactNode } from 'react';
import { asMarkdown } from 'fumadocs-core/server';
import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
import { CODE_BLOCK_TITLES } from '@/lib/code-titles';
import { reportCodeCopy, reportCopies } from './code-copy';

interface CommandBlockProps {
command: string;
/** One line that truncates, for a card; the full command is still what the button copies. */
compact?: boolean;
/** Called as the copy button is clicked; a copy of a shell command otherwise. */
onCopy?: () => void;
}

// Centred on the one line, where the block's own placement pins the button to the top corner.
Expand All @@ -15,13 +18,15 @@ function CentredActions({ children }: Readonly<{ children?: ReactNode }>) {
}

/** One shell command in a copyable block: an MDX page has no highlighter to hand, so it is plain. */
export function CommandBlock({ command, compact = false }: Readonly<CommandBlockProps>) {
const reportShellCopy = () => reportCodeCopy('shellscript');

export function CommandBlock({ command, compact = false, onCopy = reportShellCopy }: Readonly<CommandBlockProps>) {
if (asMarkdown()) {
return `\`\`\`bash\n${command}\n\`\`\``;
}
if (!compact) {
return (
<CodeBlock title={CODE_BLOCK_TITLES.shellscript}>
<CodeBlock title={CODE_BLOCK_TITLES.shellscript} Actions={reportCopies(onCopy)}>
<Pre>
<code>
{/* A highlighted block's lines carry this class, which is what the block pads. */}
Expand All @@ -35,7 +40,7 @@ export function CommandBlock({ command, compact = false }: Readonly<CommandBlock
<CodeBlock
className="my-0 rounded-lg bg-fd-secondary shadow-none"
viewportProps={{ className: 'py-2 text-xs' }}
Actions={CentredActions}
Actions={reportCopies(onCopy, CentredActions)}
>
<Pre className="w-full">
<code>
Expand Down
35 changes: 35 additions & 0 deletions portal-template/src/components/endpoint-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const METHOD_COLORS: Record<string, string> = {
PUT: 'text-yellow-600 dark:text-yellow-400',
PATCH: 'text-orange-600 dark:text-orange-400',
POST: 'text-blue-600 dark:text-blue-400',
DELETE: 'text-red-600 dark:text-red-400'
};

/** Fumadocs' endpoint bar, which it shows while the playground loads but does not export: the method and the route. */
export function EndpointBar({ method, route }: Readonly<{ method: string; route: string }>) {
const verb = method.toUpperCase();
return (
<div className="not-prose flex min-h-11 items-center gap-3 rounded-xl border bg-fd-card p-1.5 ps-3.5 text-sm text-fd-card-foreground">
<span className={`font-mono font-medium text-xs ${METHOD_COLORS[verb] ?? 'text-green-600 dark:text-green-400'}`}>
{verb}
</span>
<div className="flex min-w-0 flex-1 items-center overflow-x-auto font-mono text-[0.8125rem] text-nowrap [scrollbar-width:none]">
{route.split(/(\{[^}]*\}|\/)/).map((part, index) => {

Check warning on line 17 in portal-template/src/components/endpoint-bar.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Simplify this regular expression to reduce its runtime, as it has super-linear performance due to backtracking.

See more on https://sonarcloud.io/project/issues?id=apimatic_apimatic-cli&issues=AaHU6CvnjGuGvO81Xx-E&open=AaHU6CvnjGuGvO81Xx-E&pullRequest=473
if (index % 2 === 0) return part;
if (part === '/') {
return (
<span key={index} className="text-fd-muted-foreground">

Check warning on line 21 in portal-template/src/components/endpoint-bar.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a stable ID as key, because the index changes when the list changes.

See more on https://sonarcloud.io/project/issues?id=apimatic_apimatic-cli&issues=AaHU6CvnjGuGvO81Xx-F&open=AaHU6CvnjGuGvO81Xx-F&pullRequest=473
/
</span>
);
}
return (
<span key={index} className="rounded-md bg-fd-primary/10 px-1 text-fd-primary">

Check warning on line 27 in portal-template/src/components/endpoint-bar.tsx

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use a stable ID as key, because the index changes when the list changes.

See more on https://sonarcloud.io/project/issues?id=apimatic_apimatic-cli&issues=AaHU6CvnjGuGvO81Xx-G&open=AaHU6CvnjGuGvO81Xx-G&pullRequest=473
{part}
</span>
);
})}
</div>
</div>
);
}
12 changes: 10 additions & 2 deletions portal-template/src/components/example-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createContext, useContext, useMemo, useState, type ReactNode } from 'react';
import { createContext, useContext, useMemo, useState, type MouseEvent, type ReactNode } from 'react';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@fumadocs/api-docs/components/select';
import { useOpenAPI } from 'fumadocs-openapi';
import { useExampleRequests, useOperation } from 'fumadocs-openapi/operation';
import { CodeSample } from '@/lib/code-samples';
import { Parameter, requestExamples, type RequestExample } from '@/lib/request-examples';
import { reportCodeCopy } from './code-copy';

interface ExampleSelection {
operation: unknown;
Expand All @@ -20,6 +21,11 @@ interface LayoutSlots {

const SelectionContext = createContext<ExampleSelection | undefined>(undefined);

// "Example Response" copies through a button of Fumadocs' own in the card's header, which takes no callback.
const reportResponseCopy = (event: MouseEvent) => {
if (event.target instanceof Element && event.target.closest('button[aria-live]') !== null) reportCodeCopy('json');
Comment thread
sohail2721 marked this conversation as resolved.
Resolved
};

export function useExampleSelection(): ExampleSelection {
const selection = useContext(SelectionContext);
if (selection === undefined) throw new Error('useExampleSelection needs an ExampleLayout above it');
Expand Down Expand Up @@ -63,7 +69,9 @@ function ExampleLayout({ selector, usageTabs, responseTabs }: Readonly<LayoutSlo
<div className="prose-no-margin">
{selector === null ? null : <ExampleSelector />}
{usageTabs}
{responseTabs}
<div className="contents" onClickCapture={reportResponseCopy}>
{responseTabs}
</div>
</div>
</SelectionContext.Provider>
);
Expand Down
6 changes: 5 additions & 1 deletion portal-template/src/components/markdown-copy-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect, useState } from 'react';
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
import { Check, Copy, X } from 'lucide-react';
import { copyMarkdown } from '@/lib/copy-markdown';
import { analytics } from '@/lib/portal-analytics';

type CopyState = 'idle' | 'copying' | 'copied' | 'failed';

Expand All @@ -24,7 +25,10 @@ export function MarkdownCopyButton({ markdownUrl }: Readonly<{ markdownUrl: stri
const copy = () => {
setState('copying');
copyMarkdown(markdownUrl).then(
() => setState('copied'),
() => {
setState('copied');
analytics.report('docs_markdown_copy', {});
},
(error: unknown) => {
console.error(error);
setState('failed');
Expand Down
11 changes: 11 additions & 0 deletions portal-template/src/components/mdx.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import type { HTMLAttributes } from 'react';
import defaultMdxComponents from 'fumadocs-ui/mdx';
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
import { File, Files, Folder } from 'fumadocs-ui/components/files';
import { InlineTOC } from 'fumadocs-ui/components/inline-toc';
import { Step, Steps } from 'fumadocs-ui/components/steps';
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
import { TypeTable } from 'fumadocs-ui/components/type-table';
import { reportCodeCopy, reportCopies } from './code-copy';
import { PluginInstall } from './plugin-install';
import { PluginLanguage, PluginLanguages, PluginPlatforms } from './plugin-support';
import { SdkActions } from './sdk-actions';
import { SdkCard, SdkCards } from './sdk-cards';

type MDXComponents = Record<string, unknown>;

type HighlightedPre = HTMLAttributes<HTMLPreElement> & { 'data-language'?: string };

export function getMDXComponents(components?: MDXComponents) {
return {
...defaultMdxComponents,
// Fumadocs' own, its copy button reporting the language the build names on the block.
pre: ({ 'data-language': language = 'plaintext', ...props }: HighlightedPre) => (
<CodeBlock {...props} Actions={reportCopies(() => reportCodeCopy(language))}>
<Pre>{props.children}</Pre>
</CodeBlock>
),
// Fumadocs' components beyond its defaults, so an author's page can use them without importing.
Accordion,
Accordions,
Expand Down
12 changes: 12 additions & 0 deletions portal-template/src/components/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import { useEffect } from 'react';
import { useRouterState } from '@tanstack/react-router';
import { baseOptions } from '@/lib/layout.shared';
import { analytics } from '@/lib/portal-analytics';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import { DefaultNotFound } from 'fumadocs-ui/layouts/home/not-found';

export function NotFound() {
// The path the router has settled on: its location alone already names the page a reader is leaving this one for.
const settled = useRouterState({
select: ({ location, resolvedLocation }) =>
resolvedLocation?.pathname === location.pathname ? location.pathname : null
});
// Keyed on the path: the same component shows the next missing page too.
useEffect(() => {
if (settled !== null) analytics.reportNotFound();
}, [settled]);
return (
<HomeLayout {...baseOptions()}>
<DefaultNotFound />
Expand Down
Loading
Loading