fix build issue

This commit is contained in:
Madison 2025-07-04 16:24:23 -05:00
parent b458542ae2
commit 44b82bcbfd
7 changed files with 79 additions and 27 deletions

View File

@ -12,25 +12,37 @@ const processor = remark()
.use(remarkGfm);
export async function getLLMText(page: InferPageType<typeof source> | InferPageType<typeof apiSource>) {
// 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.`;
}
}

View File

@ -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 [];
}
}

View File

@ -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<OpenAPISpec | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);

View File

@ -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);

View File

@ -29,7 +29,10 @@ export type TOCProps = {
export function Toc(props: HTMLAttributes<HTMLDivElement>) {
const { toc } = usePageStyles();
const { isTocOpen } = useSidebar();
const sidebarContext = useSidebar();
const { isTocOpen } = sidebarContext || {
isTocOpen: false,
};
// Hide TOC if not open
if (!isTocOpen) return null;

View File

@ -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(() => {

View File

@ -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(() => {