MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / insertArticle

Function insertArticle

lib/modifiers/summary/insertArticle.js:15–36  ·  view source on GitHub ↗

Returns a new Summary with the article at the given level, with subsequent article shifted. @param {Summary} summary @param {Article} article @param {String|Article} level: level to insert at @return {Summary}

(summary, article, level)

Source from the content-addressed store, hash-verified

13 @return {Summary}
14*/
15function insertArticle(summary, article, level) {
16 article = SummaryArticle(article);
17 level = is.string(level)? level : level.getLevel();
18
19 var parent = summary.getParent(level);
20 if (!parent) {
21 return summary;
22 }
23
24 // Find the index to insert at
25 var articles = parent.getArticles();
26 var index = getLeafIndex(level);
27
28 // Insert the article at the right index
29 articles = articles.insert(index, article);
30
31 // Reindex the level from here
32 parent = parent.set('articles', articles);
33 parent = indexArticleLevels(parent);
34
35 return mergeAtLevel(summary, parent.getLevel(), parent);
36}
37
38/**
39 @param {String}

Callers 3

moveArticleAfterFunction · 0.85
moveArticleFunction · 0.85
insertArticle.jsFile · 0.85

Calls 3

getLeafIndexFunction · 0.85
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…