Skip to content

Commit

Permalink
fix: Fix build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 23, 2021
1 parent 740c78f commit de5c60b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
31 changes: 11 additions & 20 deletions build/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,42 +158,33 @@ const cssPath = path.resolve(deployDir, 'css', 'index.css');
function createTmpToHTML(fromPath, toPath, desJson, mdPath) {
return new Promise(async (resolve, reject) => {
try {
let relative_path = '';
const current_path = toPath.replace(new RegExp(`${deployDir}`), '');
const tmpStr = await FS.readFile(fromPath);
let mdPathName = '';
let mdhtml = '';
let relative_path = '';
if (mdPath) {
// CSS/JS 引用相对地址
relative_path = '../';
mdPathName = `/command/${desJson.n}.md`;
const READMESTR = await FS.readFile(path.resolve(mdPath, `${desJson.n}.md`));
mdhtml = await markdownToHTML(READMESTR.toString());
}
// 生成 HTML
let html = ejs.render(tmpStr.toString(), {
filename: fromPath,
relative_path, // 当前文件相对于根目录的相对路径
md_path: mdPathName || '', // markdown 路径
mdhtml: mdhtml || '',
current_path, // 当前 html 路径
describe: desJson ? desJson : {}, // 当前 md 的描述
}, { filename: fromPath });
}, {
filename: fromPath
});

if (mdPath) {
const READMESTR = await FS.readFile(path.resolve(mdPath, `${desJson.n}.md`));
const mdhtml = await markdownToHTML(READMESTR.toString());
html = html.replace(/{{content}}/, mdhtml);
await FS.outputFile(toPath, html);
console.log(` ${'♻️ →'.green} ${path.relative(process.cwd(), toPath)}`);
// marked(READMESTR.toString(), (err, mdhtml) => {
// if (err) return reject(err);
// html = html.replace(/{{content}}/, mdhtml);
// FS.outputFileSync(toPath, html);
// console.log(` ${'→'.green} ${toPath.replace(process.cwd(), '')}`);
// resolve(html);
// });
} else {
await FS.outputFile(toPath, html);
console.log(` ${'♻️ →'.green} ${path.relative(process.cwd(), toPath)}`);
resolve(html);
}
await FS.outputFile(toPath, html);
console.log(` ${'♻️ →'.green} ${path.relative(process.cwd(), toPath)}`);
resolve();
} catch (err) {
reject(err);
}
Expand Down
4 changes: 3 additions & 1 deletion template/details.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<a target="_blank" href="https://github.com/jaywcjlove/linux-command/edit/master<%=md_path%>">添加实例</a>
</span>
<% } %>
{{content}}

<%-mdhtml%>

</div>
<%- include('widget/footer',{type: "list"}); %>
<%- include('partial/footer'); %>

0 comments on commit de5c60b

Please sign in to comment.