@@ -15,43 +15,48 @@ export default async function Page({
1515} ) {
1616 const { docs_id } = await params ;
1717
18- let mdContent : string ;
19- try {
20- if ( process . env . NODE_ENV === "development" ) {
21- mdContent = await readFile (
22- join ( process . cwd ( ) , "public" , "docs" , `${ docs_id } .md` ) ,
23- "utf-8"
24- ) ;
25- } else {
26- const cfAssets = getCloudflareContext ( ) . env . ASSETS ;
27- const mdRes = await cfAssets ! . fetch (
28- `https://assets.local/docs/${ docs_id } .md`
29- ) ;
30- if ( mdRes . ok ) {
31- mdContent = await mdRes . text ( ) ;
32- } else {
18+ let mdContent : Promise < string > ;
19+ if ( process . env . NODE_ENV === "development" ) {
20+ mdContent = readFile (
21+ join ( process . cwd ( ) , "public" , "docs" , `${ docs_id } .md` ) ,
22+ "utf-8"
23+ ) . catch ( ( e ) => {
24+ console . error ( e ) ;
25+ notFound ( ) ;
26+ } ) ;
27+ } else {
28+ const cfAssets = getCloudflareContext ( ) . env . ASSETS ;
29+ mdContent = cfAssets !
30+ . fetch ( `https://assets.local/docs/${ docs_id } .md` )
31+ . then ( async ( res ) => {
32+ if ( ! res . ok ) {
33+ notFound ( ) ;
34+ }
35+ return res . text ( ) ;
36+ } )
37+ . catch ( ( e ) => {
38+ console . error ( e ) ;
3339 notFound ( ) ;
34- }
35- }
36- } catch ( error ) {
37- console . error ( error ) ;
38- notFound ( ) ;
40+ } ) ;
3941 }
40-
41- mdContent = mdContent . replaceAll (
42- "{process.env.PYODIDE_PYTHON_VERSION}" ,
43- String ( pyodideLock . info . python )
42+ mdContent = mdContent . then ( ( text ) =>
43+ text . replaceAll (
44+ "{process.env.PYODIDE_PYTHON_VERSION}" ,
45+ String ( pyodideLock . info . python )
46+ )
4447 ) ;
4548
46- const splitMdContent : MarkdownSection [ ] = splitMarkdown ( mdContent ) ;
49+ const splitMdContent : Promise < MarkdownSection [ ] > = mdContent . then ( ( text ) =>
50+ splitMarkdown ( text )
51+ ) ;
4752
48- const initialChatHistories = await getChat ( docs_id ) ;
53+ const initialChatHistories = getChat ( docs_id ) ;
4954
5055 return (
51- < ChatHistoryProvider initialChatHistories = { initialChatHistories } >
56+ < ChatHistoryProvider initialChatHistories = { await initialChatHistories } >
5257 < PageContent
53- documentContent = { mdContent }
54- splitMdContent = { splitMdContent }
58+ documentContent = { await mdContent }
59+ splitMdContent = { await splitMdContent }
5560 docs_id = { docs_id }
5661 />
5762 </ ChatHistoryProvider >
0 commit comments