Skip to content

Commit

Permalink
feat: adapt rst to html
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyunWan committed Oct 17, 2024
1 parent e8b2def commit ca63947
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 161 deletions.
1 change: 1 addition & 0 deletions docusaurus/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# Production
/build
/docs

# Generated files
.docusaurus
Expand Down
7 changes: 5 additions & 2 deletions docusaurus/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const config: Config = {
{
docs: {
sidebarPath: './sidebars.ts',
path: '../docs/zh-CN/source',
path: './docs/zh-CN/source',
routeBasePath: 'zh',
// Please change this to your repo.
// Remove this to remove the "edit this page" links.
Expand All @@ -49,7 +49,7 @@ const config: Config = {
'content-docs',
{
id: 'en',
path: '../docs/en-US/source',
path: './docs/en-US/source',
routeBasePath: 'en',
editCurrentVersion: true,
sidebarPath: './sidebarsEn.ts',
Expand All @@ -62,6 +62,9 @@ const config: Config = {
themeConfig: {
// Replace with your project's social card‘
image: 'img/docusaurus-social-card.jpg',
tableOfContents: {
maxHeadingLevel: 5,
},
navbar: {
logo: {
alt: 'Tugraph Site Logo',
Expand Down
1 change: 1 addition & 0 deletions docusaurus/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"private": true,
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start",
"build": "docusaurus build",
"start": "node script/convert.js start",
"build": "node script/convert.js build",
"docusaurus:start": "docusaurus start && node script/demo.js",
"docusaurus:build": "docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
Expand All @@ -19,6 +21,7 @@
"@docusaurus/preset-classic": "3.5.2",
"@mdx-js/react": "^3.0.0",
"clsx": "^2.0.0",
"fs-extra": "^11.2.0",
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
63 changes: 0 additions & 63 deletions docusaurus/script/buildAfter.js

This file was deleted.

74 changes: 0 additions & 74 deletions docusaurus/script/buildBefore.js

This file was deleted.

85 changes: 85 additions & 0 deletions docusaurus/script/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const fs = require('fs-extra');
const path = require('path');
const { exec } = require('child_process');

const originalDocsDir = '../docs';
const tempDocsDir = './docs';

async function convertRstToMd() {
try {

/** 先清除 docusaurus/docs 目录, 复制原始文档目录到临时目录 */
await fs.remove(tempDocsDir);
await fs.copy(originalDocsDir, tempDocsDir);
console.log('文档已复制到临时目录');

// 递归转换函数
async function convertDir(dir) {
const items = await fs.readdir(dir);

for (const item of items) {
const fullPath = path.join(dir, item);
const stat = await fs.stat(fullPath);

if (stat.isDirectory()) {
await convertDir(fullPath);
}

else if (path.extname(item) === '.rst' && !['index.rst'].includes(item)) {
const outputFile = path.join(dir, path.basename(item, '.rst') + '.md');
const command = `pandoc -f rst -t gfm -o "${outputFile}" "${fullPath}"`;
await new Promise((resolve, reject) => {
exec(command, (err, stdout, stderr) => {
if (err) {
console.error(`转换文件时出错: ${stderr}`);
reject(err);
} else {
console.log(`已成功转换: ${fullPath}${outputFile}`);
resolve();
}
});
});
/** 删除转换后的rst文件 */
await fs.unlink(fullPath);
}
}
}
await convertDir(tempDocsDir);

// 执行Docusaurus构建
await new Promise((resolve, reject) => {
const args = process.argv.slice(2)[0];
const execArgs = 'yarn docusaurus:' + args;
exec(execArgs, { cwd: tempDocsDir }, (err, stdout, stderr) => {
if (err) {
console.error(`构建时出错: ${stderr}`);
reject(err);
} else {
console.log('Docusaurus构建成功');
resolve();
}
});
});

// 删除临时目录
await fs.remove(tempDocsDir);
console.log('临时目录已删除');
} catch (err) {
console.error(`处理过程中出错: ${err}`);
}
}

process.on('SIGINT', async () => {
console.log('捕捉到主进程 SIGINT 信号');
await fs.remove(tempDocsDir);
process.exit();
});

// 监听主进程的 SIGTERM 信号
process.on('SIGTERM', async () => {
console.log('捕捉到主进程 SIGTERM 信号');
await fs.remove(tempDocsDir);
process.exit();
});

convertRstToMd();
3 changes: 3 additions & 0 deletions docusaurus/script/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const fs = require('fs-extra'););

fs.remove(tempDocsDir);
19 changes: 0 additions & 19 deletions docusaurus/script/folderMappings.json

This file was deleted.

7 changes: 6 additions & 1 deletion docusaurus/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,14 @@ const sidebars: SidebarsConfig = {
{
type: 'category',
label: '存储过程',
link: {
type: 'doc',
id: 'olap&procedure/procedure/procedure',
},
items: [
'olap&procedure/procedure/procedure',
'olap&procedure/procedure/traversal',
'olap&procedure/procedure/C++-procedure',
'olap&procedure/procedure/Python-procedure',
'olap&procedure/procedure/Rust-procedure'
]
},
Expand Down

0 comments on commit ca63947

Please sign in to comment.