mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2135] Updated tables of contents and tools (#2820)
This commit is contained in:
committed by
Eugenio Romano
parent
9e706d68e4
commit
994041fb23
@@ -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;
|
||||
}
|
Reference in New Issue
Block a user