[ADF-2135] Updated tables of contents and tools (#2820)

This commit is contained in:
Andy Stark
2018-01-11 10:15:00 +00:00
committed by Eugenio Romano
parent 9e706d68e4
commit 994041fb23
23 changed files with 353 additions and 464 deletions

View File

@@ -17,6 +17,7 @@ var aggData = {};
var toolsFolderName = "tools";
var configFileName = "doctool.config.json";
var defaultFolder = path.resolve("..", "docs");
function initPhase(aggData) {
@@ -78,9 +79,8 @@ function updatePhase(srcFolder, destFolder, filenames, aggData) {
});
if (modified)
fs.writeFileSync(path.resolve(destFolder, filenames[i]), remark().stringify(tree));
//console.log(JSON.stringify(tree));
fs.writeFileSync(path.resolve(destFolder, filenames[i]), remark().data("settings", {paddedTable: false}).stringify(tree));
//console.log(JSON.stringify(tree));
}
}
@@ -119,7 +119,15 @@ if (program.args.length === 0) {
return 0;
}
/*
var sourcePath;
if (program.args.length > 0)
sourcePath = path.resolve(program.args[0]);
else
sourcePath = defaultFolder;
*/
var sourcePath = path.resolve(program.args[0]);
var sourceInfo = fs.statSync(sourcePath);
@@ -150,6 +158,7 @@ if (sourceInfo.isDirectory()) {
} else if (sourceInfo.isFile()) {
files = [ path.basename(sourcePath) ];
sourcePath = path.dirname(sourcePath);
destPath = path.dirname(destPath);
}
files = files.filter(filename =>

View File

@@ -1,5 +1,5 @@
{
"enabledTools": [
"index"
"toc"
]
}

View File

@@ -91,7 +91,7 @@ function aggPhase(aggData) {
]
});
fs.writeFileSync(path.resolve("..", "docs", "README.md"), remark().stringify(indexFileTree));
fs.writeFileSync(path.resolve("..", "docs", "README.md"), remark().data("settings", {paddedTable: false}).stringify(indexFileTree));
//fs.writeFileSync(indexMdFilePath, remark().stringify(indexFileTree));
//fs.writeFileSync(path.resolve(".", "testJson.md"), JSON.stringify(indexFileTree));
}

View File

@@ -8,7 +8,17 @@ const contentsHeading = "Contents";
const minHeadingsForToc = 8;
const maxTocHeadingDepth = 3;
module.exports = process;
module.exports = {
"initPhase": initPhase,
"readPhase": readPhase,
"aggPhase": aggPhase,
"updatePhase": updatePhase
}
function initPhase(aggData) {}
function readPhase(tree, pathname, aggData) {}
function aggPhase(aggData) {}
// Find an existing Contents section or add a new empty one if needed.
// Returns true if section is present/needed, false if not needed.
@@ -47,7 +57,7 @@ function establishContentsSection(mdTree) {
// If there are enough headings for a ToC to be necessary then
// add one in the right place.
if (!foundContentsHeading) {
var newContsHeading = unist.makeHeading(contentsHeading, 2);
var newContsHeading = unist.makeHeading(unist.makeText(contentsHeading), 2);
// If we found another L2 heading then add the Contents in just before it.
if (firstL2HeadingPos != -1) {
@@ -62,21 +72,22 @@ function establishContentsSection(mdTree) {
return numTocHeadings;
}
function process(mdTree, file) {
function updatePhase(tree, pathname, aggData) {
// If we need a contents section then add one or update the existing one.
var numTocHeadings = establishContentsSection(mdTree);
var numTocHeadings = establishContentsSection(tree);
if (numTocHeadings >= minHeadingsForToc) {
var newToc = tocGenerator(mdTree, {heading: contentsHeading, maxDepth: 3});
var newToc = tocGenerator(tree, {heading: contentsHeading, maxDepth: 3});
replaceSection(mdTree, contentsHeading, function(before, oldSection, after) {
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
return [before, newToc.map, after];
});
} else {
// Otherwise, we don't need one, so remove any existing one.
replaceSection(mdTree, contentsHeading, function(before, oldSection, after) {
replaceSection(tree, contentsHeading, function(before, oldSection, after) {
return [after];
});
}
return true;
}