From 44b82bcbfd89700591b12b17dcb108c2e578f9dc Mon Sep 17 00:00:00 2001 From: Madison Date: Fri, 4 Jul 2025 16:24:23 -0500 Subject: [PATCH] fix build issue --- docs/lib/get-llm-text.ts | 40 ++++++++++++------- docs/src/app/llms.mdx/[[...slug]]/route.ts | 25 ++++++++---- docs/src/components/api/enhanced-api-page.tsx | 9 ++++- docs/src/components/chat/ai-chat.tsx | 9 ++++- docs/src/components/layout/toc.tsx | 5 ++- docs/src/components/layouts/home-layout.tsx | 13 +++++- docs/src/components/layouts/page.tsx | 5 ++- 7 files changed, 79 insertions(+), 27 deletions(-) diff --git a/docs/lib/get-llm-text.ts b/docs/lib/get-llm-text.ts index e211c85d9..56f8adb94 100644 --- a/docs/lib/get-llm-text.ts +++ b/docs/lib/get-llm-text.ts @@ -12,25 +12,37 @@ const processor = remark() .use(remarkGfm); export async function getLLMText(page: InferPageType | InferPageType) { - // Remove the Fumadocs generated comment before processing - let content = page.data.content; - - // Remove the specific Fumadocs comment that appears in generated API docs - content = content.replace( - /\{\s*\/\*\s*This file was generated by Fumadocs\. Do not edit this file directly\. Any changes should be made by running the generation command again\.\s*\*\/\s*\}/g, - '' - ); - - const processed = await processor.process({ - path: page.data._file.absolutePath, - value: content, - }); + try { + // Remove the Fumadocs generated comment before processing + let content = page.data.content; + + // Remove the specific Fumadocs comment that appears in generated API docs + content = content.replace( + /\{\s*\/\*\s*This file was generated by Fumadocs\. Do not edit this file directly\. Any changes should be made by running the generation command again\.\s*\*\/\s*\}/g, + '' + ); + + const processed = await processor.process({ + path: page.data._file.absolutePath, + value: content, + }); - return `# ${page.data.title} + return `# ${page.data.title} URL: ${page.url} Source: ${page.data._file.absolutePath} ${page.data.description || ''} ${processed.value}`; + } catch (error) { + console.error('Error processing LLM text for page:', page.url, error); + // Return a basic fallback content instead of throwing + return `# ${page.data.title} +URL: ${page.url} +Source: ${page.data._file.absolutePath} + +${page.data.description || ''} + +Error: Could not process content for this page.`; + } } diff --git a/docs/src/app/llms.mdx/[[...slug]]/route.ts b/docs/src/app/llms.mdx/[[...slug]]/route.ts index adcb33f17..6b03d011d 100644 --- a/docs/src/app/llms.mdx/[[...slug]]/route.ts +++ b/docs/src/app/llms.mdx/[[...slug]]/route.ts @@ -1,7 +1,7 @@ -import { getLLMText } from 'lib/get-llm-text'; -import { apiSource, source } from 'lib/source'; import { notFound } from 'next/navigation'; import { type NextRequest, NextResponse } from 'next/server'; +import { getLLMText } from '../../../../lib/get-llm-text'; +import { apiSource, source } from '../../../../lib/source'; export const revalidate = false; @@ -21,13 +21,24 @@ export async function GET( if (!page) notFound(); - return new NextResponse(await getLLMText(page)); + try { + return new NextResponse(await getLLMText(page)); + } catch (error) { + console.error('Error generating LLM text:', error); + return new NextResponse('Error generating content', { status: 500 }); + } } export function generateStaticParams() { - // Generate static params for both main docs and API docs - const docsParams = source.generateParams(); - const apiParams = apiSource.generateParams(); + try { + // Generate static params for both main docs and API docs + const docsParams = source.generateParams(); + const apiParams = apiSource.generateParams(); - return [...docsParams, ...apiParams]; + return [...docsParams, ...apiParams]; + } catch (error) { + console.error('Error generating static params:', error); + // Return empty array to prevent build failure + return []; + } } diff --git a/docs/src/components/api/enhanced-api-page.tsx b/docs/src/components/api/enhanced-api-page.tsx index 0093059e2..a80e515e0 100644 --- a/docs/src/components/api/enhanced-api-page.tsx +++ b/docs/src/components/api/enhanced-api-page.tsx @@ -110,7 +110,14 @@ const HTTP_METHOD_COLORS = { export function EnhancedAPIPage({ document, operations, description }: EnhancedAPIPageProps) { - const { sharedHeaders, reportError } = useAPIPageContext(); + const apiContext = useAPIPageContext(); + + // Use default functions if API context is not available + const { sharedHeaders, reportError } = apiContext || { + sharedHeaders: {}, + reportError: () => {} + }; + const [spec, setSpec] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); diff --git a/docs/src/components/chat/ai-chat.tsx b/docs/src/components/chat/ai-chat.tsx index d8a00ead3..ec7c06889 100644 --- a/docs/src/components/chat/ai-chat.tsx +++ b/docs/src/components/chat/ai-chat.tsx @@ -23,7 +23,14 @@ function StackIcon({ size = 20, className }: { size?: number, className?: string } export function AIChatDrawer() { - const { isChatOpen, isChatExpanded, toggleChat, setChatExpanded } = useSidebar(); + const sidebarContext = useSidebar(); + const { isChatOpen, isChatExpanded, toggleChat, setChatExpanded } = sidebarContext || { + isChatOpen: false, + isChatExpanded: false, + toggleChat: () => {}, + setChatExpanded: () => {}, + }; + const [docsContent, setDocsContent] = useState(''); const [isHomePage, setIsHomePage] = useState(false); const [isScrolled, setIsScrolled] = useState(false); diff --git a/docs/src/components/layout/toc.tsx b/docs/src/components/layout/toc.tsx index e46638549..f09aa060d 100644 --- a/docs/src/components/layout/toc.tsx +++ b/docs/src/components/layout/toc.tsx @@ -29,7 +29,10 @@ export type TOCProps = { export function Toc(props: HTMLAttributes) { const { toc } = usePageStyles(); - const { isTocOpen } = useSidebar(); + const sidebarContext = useSidebar(); + const { isTocOpen } = sidebarContext || { + isTocOpen: false, + }; // Hide TOC if not open if (!isTocOpen) return null; diff --git a/docs/src/components/layouts/home-layout.tsx b/docs/src/components/layouts/home-layout.tsx index 3de2d83d9..18c520305 100644 --- a/docs/src/components/layouts/home-layout.tsx +++ b/docs/src/components/layouts/home-layout.tsx @@ -45,7 +45,12 @@ function StackAuthLogo() { // AI Chat Toggle Button for Home Layout function HomeAIChatToggleButton() { - const { isChatOpen, toggleChat } = useSidebar(); + const sidebarContext = useSidebar(); + const { isChatOpen, toggleChat } = sidebarContext || { + isChatOpen: false, + toggleChat: () => {}, + }; + const [animationVariant, setAnimationVariant] = useState(''); // Generate random variant when chat is opened @@ -81,7 +86,11 @@ function HomeNavbar() { const [searchOpen, setSearchOpen] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [isScrolled, setIsScrolled] = useState(false); - const { isChatOpen, isChatExpanded } = useSidebar(); + const sidebarContext = useSidebar(); + const { isChatOpen, isChatExpanded } = sidebarContext || { + isChatOpen: false, + isChatExpanded: false, + }; // Scroll detection useEffect(() => { diff --git a/docs/src/components/layouts/page.tsx b/docs/src/components/layouts/page.tsx index b6e2c2f13..e7515219b 100644 --- a/docs/src/components/layouts/page.tsx +++ b/docs/src/components/layouts/page.tsx @@ -118,7 +118,10 @@ export function DocsPage({ } = {}, ...props }: DocsPageProps) { - const { setIsFullPage } = useSidebar(); + const sidebarContext = useSidebar(); + const { setIsFullPage } = sidebarContext || { + setIsFullPage: () => {}, + }; // Update the full page state in the context useEffect(() => {