-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,464 additions
and
949 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { promises } from 'fs'; | ||
import { filter, traverse } from 'fs-match'; | ||
import { join } from 'path'; | ||
import { parse } from 'yaml'; | ||
|
||
const title = 'MDX index creator', | ||
[folder] = process.argv.slice(2); | ||
|
||
const MDXPattern = /\.(mdx?|markdown)$/, | ||
sourceCode: string[] = [], | ||
targetPath = join(folder, 'index.ts'); | ||
|
||
console.time(title); | ||
|
||
(async () => { | ||
for await (const filePath of filter(traverse(folder), MDXPattern)) { | ||
const content = await promises.readFile(filePath, { | ||
encoding: 'utf-8' | ||
}); | ||
const [_, frontMatter] = content.match(/^---([\s\S]*?)\n---/m) || []; | ||
|
||
const meta = JSON.stringify(parse(frontMatter), null, 4) | ||
.slice(1, -1) | ||
.trim(); | ||
const path = filePath.replaceAll('\\', '/').slice(folder.length); | ||
|
||
sourceCode.push(`{ | ||
path: '${path.replace(MDXPattern, '').toLowerCase()}', | ||
${meta}, | ||
component: lazy(loadMDX(() => import('./${path}'))) | ||
}`); | ||
} | ||
|
||
await promises.writeFile( | ||
targetPath, | ||
`// This file is created by "${title}" script, | ||
// please don't edit it manually! | ||
import { lazy } from 'web-cell'; | ||
import { loadMDX } from '../utility'; | ||
export default [ | ||
${sourceCode} | ||
]; | ||
` | ||
); | ||
|
||
console.log(`[save] ${targetPath}`); | ||
console.timeEnd(title); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
cb46d88
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.
Deploy preview for bootcell-document ready!
✅ Preview
https://bootcell-document-br3xg0ne9-techquery.vercel.app
Built with commit cb46d88.
This pull request is being automatically deployed with vercel-action