1 Star 0 Fork 0

wangkang123123/libpku

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 2.15 KB
一键复制 编辑 原始数据 按行查看 历史
librarian-pku 提交于 2019-04-10 19:17 . Add files via upload
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))
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangkang123123123/libpku.git
git@gitee.com:wangkang123123123/libpku.git
wangkang123123123
libpku
libpku
master

搜索帮助