MCPcopy
hub / github.com/GitbookIO/gitbook / removeArticle

Function removeArticle

lib/modifiers/summary/removeArticle.js:12–35  ·  view source on GitHub ↗

Remove an article from a level. @param {Summary} summary @param {String|SummaryArticle} level: level to remove @return {Summary}

(summary, level)

Source from the content-addressed store, hash-verified

10 @return {Summary}
11*/
12function removeArticle(summary, level) {
13 // Coerce to level
14 level = is.string(level)? level : level.getLevel();
15
16 var parent = summary.getParent(level);
17
18 var articles = parent.getArticles();
19 // Find the index to remove
20 var index = articles.findIndex(function(art) {
21 return art.getLevel() === level;
22 });
23 if (index === -1) {
24 return summary;
25 }
26
27 // Remove from children
28 articles = articles.remove(index);
29 parent = parent.set('articles', articles);
30
31 // Reindex the level from here
32 parent = indexArticleLevels(parent);
33
34 return mergeAtLevel(summary, parent.getLevel(), parent);
35}
36
37module.exports = removeArticle;

Callers 3

moveArticleAfterFunction · 0.85
moveArticleFunction · 0.85
removeArticle.jsFile · 0.85

Calls 2

indexArticleLevelsFunction · 0.85
mergeAtLevelFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…