Skip to content

Commit

Permalink
[add] MDX index creator (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery authored Feb 8, 2024
1 parent ad274f0 commit cb46d88
Show file tree
Hide file tree
Showing 13 changed files with 1,464 additions and 949 deletions.
51 changes: 51 additions & 0 deletions create-index.ts
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);
})();
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
"description": "Re-implemented Official Document site of BootStrap & FontAwesome based on WebCell, BootCell & MarkCell",
"dependencies": {
"@nuintun/qrcode": "^3.4.0",
"boot-cell": "^2.0.0-beta.9",
"boot-cell": "^2.0.0-beta.18",
"cell-router": "^3.0.0-rc.5",
"classnames": "^2.5.1",
"dom-renderer": "^2.0.6",
"dom-renderer": "^2.1.1",
"github-web-widget": "^4.0.0-rc.1",
"iterable-observer": "^1.0.1",
"koajax": "^0.9.6",
"lodash.groupby": "^4.6.0",
"markdown-ime": "^1.0.3",
"marked": "^11.1.1",
"marked": "^12.0.0",
"mobx": "^6.12.0",
"quill": "^1.3.7",
"quill-image-uploader": "^1.3.0",
"turndown": "^7.1.2",
"turndown-plugin-gfm": "^1.0.2",
"web-cell": "^3.0.0-rc.8",
"web-cell": "^3.0.0-rc.14",
"web-utility": "^4.1.3"
},
"devDependencies": {
Expand All @@ -30,17 +30,20 @@
"@parcel/transformer-typescript-tsc": "~2.11.0",
"@parcel/transformer-webmanifest": "~2.11.0",
"@types/lodash.groupby": "^4.6.9",
"@types/mdx": "^2.0.10",
"@types/node": "^18.19.9",
"husky": "^9.0.5",
"lint-staged": "^15.2.0",
"@types/mdx": "^2.0.11",
"@types/node": "^18.19.14",
"fs-match": "^1.7.1",
"husky": "^9.0.10",
"lint-staged": "^15.2.2",
"parcel": "~2.11.0",
"parcel-transformer-mdx": "^0.3.1",
"postcss": "^8.4.33",
"postcss": "^8.4.35",
"postcss-modules": "^4.3.1",
"prettier": "^3.2.4",
"prettier": "^3.2.5",
"tsx": "^4.7.0",
"typescript": "~5.3.3",
"workbox-cli": "^7.0.0"
"workbox-cli": "^7.0.0",
"yaml": "^2.3.4"
},
"prettier": {
"singleQuote": true,
Expand All @@ -52,9 +55,9 @@
"*.{html,md,mdx,less,json,yml,ts,tsx}": "prettier --write"
},
"scripts": {
"prepare": "husky",
"prepare": "husky && npm run clean",
"test": "lint-staged",
"clean": "rm -rf .parcel-cache/ dist/",
"clean": "rm -rf .parcel-cache/ dist/ && tsx create-index source/document/",
"pack-tsx": "parcel build source/index.html --public-url .",
"build": "npm run clean && npm run pack-tsx && workbox generateSW",
"start": "npm run clean && parcel source/index.html --open"
Expand Down
Loading

1 comment on commit cb46d88

@github-actions
Copy link

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

Please # to comment.