Skip to content

Commit

Permalink
Prepend the filename to each summary link
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter authored and rwaldron committed Apr 17, 2018
1 parent 9fdf8ff commit 598fa9c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"common-tags": "^1.4.0",
"glob": "^7.1.2",
"highlight.js": "^9.12.0",
"markdown-link": "^0.1.1",
"markdown-toc": "^1.1.0",
"minimist": "^1.2.0",
"remarkable": "^1.7.1"
Expand Down
27 changes: 20 additions & 7 deletions scripts/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require("path");
// Third party objects
const glob = require("glob");
const toc = require("markdown-toc");
const mdlink = require("markdown-link", "mdlink");
const argv = require("minimist")(process.argv.slice(2), {
string: ["_"]
});
Expand All @@ -30,18 +31,30 @@ function main() {

const writable = fs.createWriteStream(`${folder}/summary.md`, { flags: 'w' });
const filePattern = /^\w*-\d+\.[mM][dD]$/;
const notes = results.filter(file => {
return filePattern.test(path.basename(file));
});

notes.forEach(file => {
results.forEach(file => {
if (!filePattern.test(path.basename(file))) {
return;
}
const contents = fs.readFileSync(file, "utf8");
const rendered = toc(contents, {
const fileToc = toc(contents, {
filter(str, ele) {
return ele.lvl < 3;
},
append: "\n"
}).content;
append: "\n",
linkify({ lvl }, title, slug) {
// prepends the filename to the link
let content = mdlink(title, `${path.basename(file)}#${slug}`);
return {
content,

// lvl is required to find the highest level links and order it
lvl
};;
}
});

const rendered = fileToc.content;

writable.write(rendered);
});
Expand Down

0 comments on commit 598fa9c

Please sign in to comment.