diff --git a/oi-wiki-export-typst/index.js b/oi-wiki-export-typst/index.js index 0112c9c..a24288e 100644 --- a/oi-wiki-export-typst/index.js +++ b/oi-wiki-export-typst/index.js @@ -9,7 +9,7 @@ import remarkMath from 'remark-math' import remarkDetails from 'remark-details' import remarkGfm from 'remark-gfm' import remarkTabbed from 'remark-tabbed' -import { read, writeSync } from 'to-vfile' +import { read, write } from 'to-vfile' import { Type, Schema, load } from 'js-yaml' import { snippet as _snippet } from './snippet.js' @@ -81,11 +81,13 @@ async function main() { const catalog = config.nav // 文档目录 let includes = '' + const exportPromises = [] for (const id in catalog) { const texModule = join('typ', id.toString()) - await fs.writeFile(texModule + '.typ', await exportRecursive(catalog[id], 0)) + await fs.writeFile(texModule + '.typ', exportRecursive(catalog[id], 0)) includes += '#include "' + texModule + '.typ"\n' // 输出 includes.typ 章节目录文件 } + await Promise.all(exportPromises) await fs.writeFile('includes.typ', includes) console.log(INFO + 'Export successful.') @@ -107,7 +109,6 @@ async function main() { .use(remarkGfm) .use(remarkDetails) .use(remarkTabbed) - // .use(remarkTabbed) .use(remarkTypst, { prefix: filename.replace(PREFIX_REGEX, '').replace(/md$/, ''), // 根据路径生成 ID,用作 label depth: depth, // 标题 h1 深度 @@ -118,19 +119,19 @@ async function main() { path: filename.replace(/\.md$/, '/'), // 由文件名转换而来的路径 title: title, }) - .process(await read(filename), (err, file) => { + .process(await read(filename), async (err, file) => { if (err) { throw err } file.dirname = 'typ' file.stem = filename.replace(PREFIX_REGEX, '') file.extname = '.typ' - writeSync(file) + await write(file) }) } // 递归处理各个 chapter - async function exportRecursive(object, depth) { + function exportRecursive(object, depth) { let result = '' depth = Math.min(depth, 6) @@ -138,7 +139,8 @@ async function main() { console.log(INFO + 'Exporting: ' + key) if (typeof object[key] === 'string') { // 对应页面 - await convertMarkdown(join(oiwikiRoot, 'docs', object[key]), depth + 1, object[key]) + const convert_promise = convertMarkdown(join(oiwikiRoot, 'docs', object[key]), depth + 1, object[key]) + exportPromises.push(convert_promise) const moduleName = escape(getModuleName(object[key])) result += '{0} {1} <{2}>\n'.format( @@ -158,7 +160,7 @@ async function main() { } for (const id in object[key]) { - result += await exportRecursive(object[key][id], depth + 1) + result += exportRecursive(object[key][id], depth + 1) } } }