Skip to content

Commit

Permalink
page loadre
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity committed Jan 23, 2025
1 parent 8566968 commit b4d67b9
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/fern-docs/bundle/src/server/DocsLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,41 @@ export class DocsLoader {
return root;
}

private cache: Record<
FernNavigation.PageId,
{ markdown: string; editThisPageUrl: string | undefined }
> = {};

public async getPage(
pageId: FernNavigation.PageId
): Promise<
{ markdown: string; editThisPageUrl: string | undefined } | undefined
> {
if (this.cache[pageId] != null) {
return this.cache[pageId];
}
const docs = await this.loadDocs();
const page = docs?.definition.pages[pageId];
if (!page) {
return undefined;
}
let markdown = page.markdown;
if (markdown == null && page.fileId != null) {
const fileUrl = docs.definition.filesV2[page.fileId]?.url;
if (fileUrl != null) {
const fileResponse = await fetch(fileUrl);
if (fileResponse.ok) {
markdown = await fileResponse.text();
}
}
}
if (!markdown) {
return undefined;
}
this.cache[pageId] = { markdown, editThisPageUrl: page.editThisPageUrl };
return this.cache[pageId];
}

// NOTE: authentication is based on the navigation nodes, so we don't need to check it here,
// as long as these pages are NOT shipped to the client-side.
public async pages(): Promise<
Expand Down

0 comments on commit b4d67b9

Please sign in to comment.