actions try #1
This commit is contained in:
parent
4d88199408
commit
828d9bd7b0
3 changed files with 79 additions and 1 deletions
27
.github/workflows/mdx-content.yml
vendored
Normal file
27
.github/workflows/mdx-content.yml
vendored
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
name: Deploy MDX Content
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "data/pages/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: "18"
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Run MDX build or processing script
|
||||||
|
run: npm run build-mdx
|
|
@ -6,7 +6,8 @@
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint"
|
"lint": "next lint",
|
||||||
|
"build-mdx": "node scripts/build-mdx.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hookform/resolvers": "^3.6.0",
|
"@hookform/resolvers": "^3.6.0",
|
||||||
|
|
50
scripts/build-mdx.js
Normal file
50
scripts/build-mdx.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
const { compile } = require("@mdx-js/mdx");
|
||||||
|
const { remark } = require("remark");
|
||||||
|
const { toVFile } = require("to-vfile");
|
||||||
|
const { format } = require("prettier");
|
||||||
|
const rehypeStringify = require("rehype-stringify");
|
||||||
|
const remarkParse = require("remark-parse");
|
||||||
|
const rehypeParse = require("rehype-parse");
|
||||||
|
const { unified } = require("unified");
|
||||||
|
|
||||||
|
const mdxDir = path.join(__dirname, "../data/pages");
|
||||||
|
const outputDir = path.join(__dirname, "../data/mdx");
|
||||||
|
|
||||||
|
if (!fs.existsSync(outputDir)) {
|
||||||
|
fs.mkdirSync(outputDir, { recursive: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.readdir(mdxDir, (err, files) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
files.forEach(async (file) => {
|
||||||
|
if (path.extname(file) === ".mdx") {
|
||||||
|
const filePath = path.join(mdxDir, file);
|
||||||
|
const outputFilePath = path.join(
|
||||||
|
outputDir,
|
||||||
|
path.basename(file, ".mdx") + ".html"
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const mdxContent = fs.readFileSync(filePath, "utf8");
|
||||||
|
|
||||||
|
const processedContent = await compile(mdxContent, {
|
||||||
|
remarkPlugins: [remarkParse],
|
||||||
|
rehypePlugins: [rehypeStringify],
|
||||||
|
});
|
||||||
|
|
||||||
|
const html = processedContent.toString();
|
||||||
|
|
||||||
|
// ig optional?
|
||||||
|
const formattedHtml = format(html, { parser: "html" });
|
||||||
|
|
||||||
|
fs.writeFileSync(outputFilePath, formattedHtml);
|
||||||
|
console.log(`Processed ${file} -> ${outputFilePath}`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to process ${file}:`, error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue