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

Function moveArticleAfter

lib/modifiers/summary/moveArticleAfter.js:15–34  ·  view source on GitHub ↗

Returns a new summary, with the an article moved after another article. Unlike `moveArticle`, does not ensure that the article will be found at the target's level plus one. @param {Summary} summary @param {String|SummaryArticle} origin @param {String|SummaryArticle} afterTarget

(summary, origin, afterTarget)

Source from the content-addressed store, hash-verified

13 @return {Summary}
14*/
15function moveArticleAfter(summary, origin, afterTarget) {
16 // Coerce to level
17 var originLevel = is.string(origin)? origin : origin.getLevel();
18 var afterTargetLevel = is.string(afterTarget)? afterTarget : afterTarget.getLevel();
19 var article = summary.getByLevel(originLevel);
20
21 var targetLevel = increment(afterTargetLevel);
22
23 if (targetLevel < origin) {
24 // Remove first
25 var removed = removeArticle(summary, originLevel);
26 // Insert then
27 return insertArticle(removed, article, targetLevel);
28 } else {
29 // Insert right after first
30 var inserted = insertArticle(summary, article, targetLevel);
31 // Remove old one
32 return removeArticle(inserted, originLevel);
33 }
34}
35
36/**
37 @param {String}

Callers 1

Calls 3

incrementFunction · 0.85
removeArticleFunction · 0.85
insertArticleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…