代码拉取完成,页面将自动刷新
const dirTree = require("directory-tree");
const tree = dirTree(".", {
exclude: /node_modules|\.git/,
extensions: /^((?!js).)*$/
});
let prefix = `https://github.com/lib-pku/libpku/raw/master/`;
function solve(e, depth) {
let s = "";
let res = [];
if (depth == 1) {
res.push(`## toc`);
}
if (e.type == "directory") {
for (let i = 0; i < depth; ++i) s += "#";
res.push(`${s} [${e.name}](${prefix + encodeURIComponent(e.path)})`);
} else if (e.type == "file") {
res.push(`[${e.name}](${prefix + encodeURIComponent(e.path)})`);
}
if (e.children) {
e.children.forEach(ww => {
if (ww && ww.name) res.push(solve(ww, depth + 1));
});
}
return res.join("\n");
}
// console.log(solve(tree, 1));
let begin = `<html>
<head>
<meta charset='utf-8'>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>libpku - 贵校课程资料民间整理</title>
<meta property="og:url" content="https://lib-pku.github.io/" />
<meta property="og:site_name" content="lib-pku.github.io" />
<link rel="canonical" href="https://lib-pku.github.io/" />
<link rel="stylesheet" href="assets/css/index.css">
</head>
<body>
<header>
<div class="inner">
<br>
<a href="https://lib-pku.github.io/">
<h2>libpku - 贵校课程资料民间整理</h2>
</a>
<h2></h2>
<a href="https://github.com/lib-pku/libpku" class="button"><small>Fork this on</small> GitHub</a>
</div>
</header>
<div id="content-wrapper">
<div class="inner clearfix">
<section id="main-content"><aside id="sidebar">`;
let sd = `</section>`;
let ed = `<p>This page was generated by <a href="https://pages.github.com">GitHub Pages</a>.</p>
</div>
</div>
</body>
</html>`;
var remark = require("remark");
var html = require("remark-html");
var toc = require("remark-toc");
remark()
.use(toc)
.use(html)
.process(solve(tree, 1), function(err, file) {
if (err) {
console.error(err);
}
// console.log(file)
console.log(
begin + String(file).replace("<h1 id=", `</aside>` + "<h1 id=") + ed
);
// console.log(String(file))
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。