(node, context, opts)
| 83 | // Return a nested object that contains the bits and pieces we need |
| 84 | // for the tree which is used for sidebars and listing |
| 85 | async function getTocItems(node, context, opts) { |
| 86 | // Cleaner than trying to be too terse inside the `.filter()` inline callback. |
| 87 | function filterHidden(child) { |
| 88 | return opts.includeHidden || !child.page.hidden |
| 89 | } |
| 90 | |
| 91 | return await Promise.all( |
| 92 | node.childPages.filter(filterHidden).map(async (child) => { |
| 93 | const { page } = child |
| 94 | const title = await page.renderProp('rawTitle', context, { textOnly: true }) |
| 95 | let intro = null |
| 96 | if (opts.renderIntros) { |
| 97 | intro = '' |
| 98 | if (page.rawIntro) { |
| 99 | // The intro can contain Markdown even though it might not |
| 100 | // contain any Liquid. |
| 101 | // Deliberately don't use `textOnly:true` here because we intend |
| 102 | // to display the intro, in a table of contents component, |
| 103 | // with the HTML (dangerouslySetInnerHTML). |
| 104 | intro = await page.renderProp('rawIntro', context) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | let childTocItems = null |
| 109 | if (opts.recurse) { |
| 110 | childTocItems = [] |
| 111 | if (child.childPages) { |
| 112 | childTocItems.push(...(await getTocItems(child, context, opts))) |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | const fullPath = child.href |
| 117 | return { |
| 118 | title, |
| 119 | fullPath, |
| 120 | intro, |
| 121 | childTocItems, |
| 122 | } |
| 123 | }) |
| 124 | ) |
| 125 | } |
no test coverage detected