1
0
mirror of synced 2026-01-07 09:01:31 -05:00

make miniToc pure data and no html strings (#28517)

* make miniToc pure data and no html strings

* fixups

* some types refactoring
This commit is contained in:
Peter Bengtsson
2022-06-15 14:31:36 -04:00
committed by GitHub
parent 47c9f87cd0
commit 071c95a91c
9 changed files with 17 additions and 22 deletions

View File

@@ -43,9 +43,7 @@ export default function getMiniTocItems(
// remove any <strong> tags but leave content
$('strong', item).map((i, el) => $(el).replaceWith($(el).contents()))
const contents = isRestPage
? { href: `${href}`, title: `${$(item).text()}` }
: `<a class="d-block width-auto" href="${href}">${$(item).html()}</a>`
const contents = { href, title: $(item).text().trim() }
const headingLevel = parseInt($(item)[0].name.match(/\d+/)[0], 10) || 0 // the `2` from `h2`
const platform = $(item).parent('.extended-markdown').attr('class') || ''

View File

@@ -103,7 +103,7 @@ export async function getRestMiniTocItems(
// is needed to generate the toc
const titles = restOperations.map((operation) => `### ${operation.title}\n`).join('')
toc += await renderContent(titles, context)
const restOperationsMiniTocItems = getMiniTocItems(toc, 3, '', true)
const restOperationsMiniTocItems = getMiniTocItems(toc, 3, '')
languageTree.get(version).get(category).set(subCategory, {
restOperationsMiniTocItems,
})