* Compile sidebar * @param {String} text Text content * @param {Number} level Type of heading (h tag) * @returns {String} Sidebar element
(text, level)
| 266 | * @returns {String} Sidebar element |
| 267 | */ |
| 268 | sidebar(text, level) { |
| 269 | const { toc } = this; |
| 270 | const currentPath = this.router.getCurrentPath(); |
| 271 | let html = ''; |
| 272 | |
| 273 | if (text) { |
| 274 | html = this.compile(text); |
| 275 | } else { |
| 276 | for (let i = 0; i < toc.length; i++) { |
| 277 | if (toc[i].ignoreSubHeading) { |
| 278 | const deletedHeaderLevel = toc[i].level; |
| 279 | toc.splice(i, 1); |
| 280 | // Remove headers who are under current header |
| 281 | for ( |
| 282 | let j = i; |
| 283 | j < toc.length && deletedHeaderLevel < toc[j].level; |
| 284 | j++ |
| 285 | ) { |
| 286 | toc.splice(j, 1) && j-- && i++; |
| 287 | } |
| 288 | |
| 289 | i--; |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | const tree = this.cacheTree[currentPath] || genTree(toc, level); |
| 294 | html = treeTpl(tree, '<ul>{inner}</ul>'); |
| 295 | this.cacheTree[currentPath] = tree; |
| 296 | } |
| 297 | |
| 298 | return html; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Compile sub sidebar |
no test coverage detected