Add github link to website sidebar

This commit is contained in:
David Tolnay 2020-11-13 16:29:17 -08:00
parent 85e6489666
commit 3415e6db31
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
4 changed files with 55 additions and 0 deletions

1
book/.gitignore vendored
View File

@ -1,2 +1,3 @@
/build
/mdbook
/node_modules

37
book/build.js Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/env node
const fs = require('fs');
const cheerio = require('cheerio');
const githublink = `\
<li class="part-title">\
<a href="https://github.com/dtolnay/cxx">\
<i class="fa fa-github" style="font-size:20px;padding-right:5px;padding-top:12px;position:relative;top:1px"></i>\
https://github.com/dtolnay/cxx\
</a>\
</li>`;
const dirs = ['build'];
while (dirs.length) {
const dir = dirs.pop();
fs.readdirSync(dir).forEach((entry) => {
path = dir + '/' + entry;
const stat = fs.statSync(path);
if (stat.isDirectory()) {
dirs.push(path);
return;
}
if (!path.endsWith('.html')) {
return;
}
const index = fs.readFileSync(path, 'utf8');
const $ = cheerio.load(index, { decodeEntities: false });
$('nav#sidebar ol.chapter').append(githublink);
const out = $.html();
fs.writeFileSync(path, out);
});
}

View File

@ -9,3 +9,9 @@ if [ -f ./mdbook ]; then
else
mdbook build
fi
if [ ! -d node_modules ]; then
npm install
fi
./build.js

11
book/package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "cxx-book-build",
"version": "0.0.0",
"main": "build.js",
"dependencies": {
"cheerio": "^1.0.0-rc.3"
},
"prettier": {
"singleQuote": true
}
}