diff --git a/packages/gitbook/src/components/PageActions/PageActions.tsx b/packages/gitbook/src/components/PageActions/PageActions.tsx
index 55b9b2c3db..09c7819df5 100644
--- a/packages/gitbook/src/components/PageActions/PageActions.tsx
+++ b/packages/gitbook/src/components/PageActions/PageActions.tsx
@@ -171,9 +171,6 @@ export function ActionOpenInLLM(props: {
const providerLabel = provider === 'chatgpt' ? 'ChatGPT' : 'Claude';
- // Remove the .md extension from the URL to avoid sending a bad request to the LLM.
- const urlWithoutExtension = url.replace(/\.md$/, '');
-
return (
);
}
diff --git a/packages/gitbook/src/components/PageActions/PageActionsDropdown.tsx b/packages/gitbook/src/components/PageActions/PageActionsDropdown.tsx
index e1f15a83d8..b39df21115 100644
--- a/packages/gitbook/src/components/PageActions/PageActionsDropdown.tsx
+++ b/packages/gitbook/src/components/PageActions/PageActionsDropdown.tsx
@@ -18,17 +18,22 @@ import {
ActionViewAsPDF,
} from './PageActions';
-interface PageActionsDropdownProps {
- siteTitle: string;
- markdownPageURL: string;
- mcpURL?: string;
- pdfURL?: string;
- className?: string;
- actions: SiteCustomizationSettings['pageActions'];
+export type PageActionsDropdownURLs = {
+ html: string;
+ markdown: string;
+ mcp?: string;
+ pdf?: string;
editOnGit?: {
provider: GitSyncState['installationProvider'];
url: string;
};
+};
+
+interface PageActionsDropdownProps {
+ siteTitle: string;
+ urls: PageActionsDropdownURLs;
+ className?: string;
+ actions: SiteCustomizationSettings['pageActions'];
}
/**
@@ -75,7 +80,7 @@ export function PageActionsDropdown(props: PageActionsDropdownProps) {
* Return the list of actions to show in the dropdown menu.
*/
function getPageDropdownActions(props: PageActionsDropdownProps): React.ReactNode[] {
- const { siteTitle, markdownPageURL, mcpURL, actions } = props;
+ const { siteTitle, urls, actions } = props;
const assistants = useAI().assistants.filter(
(assistant) => assistant.ui === true && assistant.pageAction
);
@@ -94,55 +99,45 @@ function getPageDropdownActions(props: PageActionsDropdownProps): React.ReactNod
-
+
) : null,
actions.externalAI ? (
-
-
+
+
) : null,
- actions.mcp && mcpURL ? (
+ actions.mcp && urls.mcp ? (
-
+
) : null,
- props.editOnGit || props.pdfURL ? (
+ urls.editOnGit || urls.pdf ? (
- {props.editOnGit ? (
+ {urls.editOnGit ? (
) : null}
- {props.pdfURL ? (
-
- ) : null}
+ {urls.pdf ? : null}
) : null,
].filter(Boolean);
@@ -152,7 +147,7 @@ function getPageDropdownActions(props: PageActionsDropdownProps): React.ReactNod
* A default action shown as a quick-access button beside the dropdown menu
*/
function getPageDefaultAction(props: PageActionsDropdownProps) {
- const { markdownPageURL, actions } = props;
+ const { urls, actions } = props;
const assistants = useAI().assistants.filter(
(assistant) => assistant.ui === true && assistant.pageAction
);
@@ -162,12 +157,12 @@ function getPageDefaultAction(props: PageActionsDropdownProps) {
return ;
}
- if (props.editOnGit) {
+ if (urls.editOnGit) {
return (
);
}
@@ -176,7 +171,7 @@ function getPageDefaultAction(props: PageActionsDropdownProps) {
return (
);
diff --git a/packages/gitbook/src/components/PageBody/PageHeader.tsx b/packages/gitbook/src/components/PageBody/PageHeader.tsx
index e6d1c1c44f..66d483a9be 100644
--- a/packages/gitbook/src/components/PageBody/PageHeader.tsx
+++ b/packages/gitbook/src/components/PageBody/PageHeader.tsx
@@ -5,7 +5,10 @@ import { type RevisionPageDocument, SiteVisibility } from '@gitbook/api';
import { Icon } from '@gitbook/icons';
import urlJoin from 'url-join';
import { getPDFURLSearchParams } from '../PDF';
-import { PageActionsDropdown } from '../PageActions/PageActionsDropdown';
+import {
+ PageActionsDropdown,
+ type PageActionsDropdownURLs,
+} from '../PageActions/PageActionsDropdown';
import { PageIcon } from '../PageIcon';
import { StyledLink } from '../primitives';
@@ -40,35 +43,7 @@ export async function PageHeader(props: {
// Show page actions if *any* of the actions are enabled
);
}
+
+/**
+ * Return the URLs for the page actions.
+ */
+function getPageActionsURLs(
+ context: GitBookSiteContext,
+ page: RevisionPageDocument
+): PageActionsDropdownURLs {
+ return {
+ html: context.linker.toAbsoluteURL(
+ context.linker.toPathForPage({ pages: context.revision.pages, page })
+ ),
+ markdown: `${context.linker.toAbsoluteURL(context.linker.toPathInSpace(page.path))}.md`,
+ editOnGit:
+ context.customization.git.showEditLink && context.space.gitSync?.url && page.git
+ ? {
+ provider: context.space?.gitSync?.installationProvider,
+ url: urlJoin(context.space.gitSync.url, page.git.path),
+ }
+ : undefined,
+ pdf: context.customization.pdf.enabled
+ ? context.linker.toPathInSpace(
+ `~gitbook/pdf?${getPDFURLSearchParams({
+ page: page.id,
+ only: true,
+ limit: 100,
+ }).toString()}`
+ )
+ : undefined,
+ mcp:
+ context.site.visibility !== SiteVisibility.VisitorAuth
+ ? context.linker.toAbsoluteURL(context.linker.toPathInSpace('~gitbook/mcp'))
+ : undefined,
+ };
+}