-
Notifications
You must be signed in to change notification settings - Fork 1
Consolidate versions and AWS configuration in a single file #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "version": "4.1.0", | ||
| "region": "ap-south-1", | ||
| "linuxBucketName": "robonito-downloads", | ||
| "macBucketName": "robonito-downloads", | ||
| "winBucketName": "robonito-downloads" | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,14 +60,38 @@ type BaseMdxFrontmatter = { | |||||||||||||||||||||||||
| description: string; | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| let cachedConfig: Record<string, string> | null = null; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| async function loadDownloadConfig(): Promise<Record<string, string>> { | ||||||||||||||||||||||||||
| if (cachedConfig) return cachedConfig; | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| const configPath = path.join(process.cwd(), "download-config.json"); | ||||||||||||||||||||||||||
| const content = await fs.readFile(configPath, "utf-8"); | ||||||||||||||||||||||||||
| cachedConfig = JSON.parse(content); | ||||||||||||||||||||||||||
| return cachedConfig || {}; | ||||||||||||||||||||||||||
| } catch (err) { | ||||||||||||||||||||||||||
| console.error("Failed to load download-config.json", err); | ||||||||||||||||||||||||||
| return {}; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| function replacePlaceholders(content: string, config: Record<string, string>): string { | ||||||||||||||||||||||||||
| return content.replace(/\{\{([^}]+)\}\}/g, (match, key) => { | ||||||||||||||||||||||||||
| const trimmedKey = key.trim(); | ||||||||||||||||||||||||||
| return trimmedKey in config ? config[trimmedKey] : match; | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+78
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export async function getDocsForSlug(slug: string) { | ||||||||||||||||||||||||||
| // skip assets to prevent ENOENT errors on index.mdx | ||||||||||||||||||||||||||
| const assetExtensions = [".png", ".jpg", ".jpeg", ".gif", ".svg", ".ico", ".css", ".js"]; | ||||||||||||||||||||||||||
| if (assetExtensions.some(ext => slug.endsWith(ext))) return null; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| const contentPath = getDocsContentPath(slug); | ||||||||||||||||||||||||||
| const rawMdx = await fs.readFile(contentPath, "utf-8"); | ||||||||||||||||||||||||||
| let rawMdx = await fs.readFile(contentPath, "utf-8"); | ||||||||||||||||||||||||||
| const downloadConfig = await loadDownloadConfig(); | ||||||||||||||||||||||||||
| rawMdx = replacePlaceholders(rawMdx, downloadConfig); | ||||||||||||||||||||||||||
| const res = await parseMdx<BaseMdxFrontmatter>(rawMdx); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // If title/description are missing from frontmatter, extract from content | ||||||||||||||||||||||||||
|
|
@@ -99,7 +123,9 @@ function stripMdx(text: string) { | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| export async function getDocsTocs(slug: string) { | ||||||||||||||||||||||||||
| const contentPath = getDocsContentPath(slug); | ||||||||||||||||||||||||||
| const rawMdx = await fs.readFile(contentPath, "utf-8"); | ||||||||||||||||||||||||||
| let rawMdx = await fs.readFile(contentPath, "utf-8"); | ||||||||||||||||||||||||||
| const downloadConfig = await loadDownloadConfig(); | ||||||||||||||||||||||||||
| rawMdx = replacePlaceholders(rawMdx, downloadConfig); | ||||||||||||||||||||||||||
| // captures between ## - #### can modify accordingly | ||||||||||||||||||||||||||
| const headingsRegex = /^(#{2,4})\s(.+)$/gm; | ||||||||||||||||||||||||||
| let match; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When multiple documentation pages are requested concurrently,
loadDownloadConfigcan trigger multiple concurrentfs.readFileoperations becausecachedConfigis only assigned after the file read and JSON parsing complete. Caching the promise instead of the resolved configuration object avoids this race condition and ensures the file is read at most once.