From 61f9f33c7a10fb469d23c7106949b54c5f46a474 Mon Sep 17 00:00:00 2001 From: Escande Guillaume Date: Fri, 15 Dec 2023 15:08:51 +0100 Subject: [PATCH 1/2] Add title filtering --- packages/assembler/lib/produce-aggregate-document.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/assembler/lib/produce-aggregate-document.js b/packages/assembler/lib/produce-aggregate-document.js index dd6cb60..9fb3eca 100644 --- a/packages/assembler/lib/produce-aggregate-document.js +++ b/packages/assembler/lib/produce-aggregate-document.js @@ -52,6 +52,7 @@ function produceAggregateDocument ( function buildAsciiDocHeader (componentVersion, navtitle, doctype = 'book') { const [navtitlePlain, navtitleAsciiDoc] = sanitize(navtitle) let doctitle = navtitleAsciiDoc + doctitle = doctitle.replace(/(<([^>]+)>)/gi, '') if (navtitlePlain !== componentVersion.title) doctitle = `${componentVersion.title}: ${doctitle}` const version = componentVersion.version === 'master' ? '' : componentVersion.version return [ @@ -479,9 +480,11 @@ function generateStem (componentVersion, title) { segments.push( title .toLowerCase() + .replace(/(<([^>]+)>)/gi, '') .replace(/&.+?;|[^ \p{Alpha}0-9_\-.]/gu, '') .replace(/[ _.]/g, '-') .replace(/--+/g, '-') + .replace(/^-*/, '') ) return path.join(...segments) } -- GitLab From 81fcf8b5265d92c5c454f6893c6b3729c4983e6f Mon Sep 17 00:00:00 2001 From: Escande Guillaume Date: Fri, 15 Dec 2023 15:28:28 +0100 Subject: [PATCH 2/2] 40 extend root_entry capabilities --- .../lib/produce-aggregate-documents.js | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/assembler/lib/produce-aggregate-documents.js b/packages/assembler/lib/produce-aggregate-documents.js index 9fd4910..d4405b8 100644 --- a/packages/assembler/lib/produce-aggregate-documents.js +++ b/packages/assembler/lib/produce-aggregate-documents.js @@ -117,14 +117,48 @@ function includedInNav (items, url) { // when root level is 1, create navigation per navigation menu // in this case, if there's only a single navigation menu with no title, promote each top-level item to a menu function prepareOutlines (navigation, rootEntry, rootLevel) { + if (isNaN(rootLevel)) { + let items = navigation + if (navigation.length === 1) { + items = navigation[0].items + } + const documents = [] + Object.entries(rootLevel).forEach((entry) => { + const [docName, docUrls] = entry + const buildeditems = items.reduce((navTree, it) => { + if (it.url) { + if ( + docUrls + .map((url) => { + return new RegExp(url).test(it.url) + }) + .includes(true) + ) { + return navTree.concat(it.content ? it : it.items) + } + } + return navTree + }, []) + if (buildeditems.length > 0) { + documents.push({ + content: docName, + items: buildeditems, + }) + } + }) + + return documents + } if (rootLevel === 0 || navigation.length === 1) { const navBranch = navigation.length === 1 ? navigation[0] : { items: navigation.reduce((navTree, it) => navTree.concat(it.content ? it : it.items), []) } - return rootLevel === 0 || navBranch.content ? [Object.assign(rootEntry, navBranch)] : navBranch.items + const result = rootLevel === 0 || navBranch.content ? [Object.assign(rootEntry, navBranch)] : navBranch.items + return result } - return navigation.reduce((navTree, it) => navTree.concat(it.content ? it : it.items), [rootEntry]) + const result = navigation.reduce((navTree, it) => navTree.concat(it.content ? it : it.items), [rootEntry]) + return result } module.exports = produceAggregateDocuments -- GitLab