Repository navigation
feat(portal): load Google Tag Manager and GA4 from portal.analytics #473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3a4e5ad
5e2b3ad
0448f11
b9312eb
2259787
b41a5ce
ac5b704
7541922
b744687
5c0a854
7ea287d
fe93025
7b1bcf8
5851a78
c860c27
3f76503
7611487
18e68aa
64a98f9
a3657e0
cc31714
b162281
0fbf185
b8a13e6
2dc7c47
be8cc92
90dc0e9
f39de85
af91f01
99a4abe
9518de4
54c8c60
eee78f6
d974f46
a2cfc95
45945e6
246accb
8c4be3f
7252e77
42cae7a
c810cb8
beaecde
2c78cc1
9f32c1b
382e850
2a4f79c
09a22ba
18b9a3b
9635ebb
3f458d5
353918b
1c5a5ff
f9b415a
15460ba
c15f0d3
fa93587
95c8187
a7f1c62
97d7df2
07092fd
94e99c2
96885d4
1bb6dfb
f54b30e
eba596e
5e8a9f5
89f6b79
c69d66a
1c93ac2
ec787d1
2c025b4
2ffa3b6
02200bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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)}` | ||
| }); |
| 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 }} />; | ||
| } |
| 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
|
||
| 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
|
||
| / | ||
| </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
|
||
| {part} | ||
| </span> | ||
| ); | ||
| })} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.