From f4774d06a4004030367f8cbf97b290c5e2ed5fe9 Mon Sep 17 00:00:00 2001 From: Derek Wolpert Date: Tue, 27 Sep 2022 15:35:45 -0400 Subject: [PATCH] address edge case situation to ensure all sections and subsections on a page are assigned unique key values --- docs/GettingStarted.md | 2 ++ docs/Test.md | 6 ++++++ lib/index.js | 14 +++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/GettingStarted.md b/docs/GettingStarted.md index bdd9cd7..52c92f0 100644 --- a/docs/GettingStarted.md +++ b/docs/GettingStarted.md @@ -35,6 +35,8 @@ In DevOps, tools only attempt to address specific areas. This leaves the chaleng [Components](/docs/Components.md) +[Tasks](/docs/Components.md#tasks) + ### Dummy SubSection One hello diff --git a/docs/Test.md b/docs/Test.md index 579ccd8..39fbe87 100644 --- a/docs/Test.md +++ b/docs/Test.md @@ -2,14 +2,20 @@ Integer molestie purus ut lorem malesuada euismod id quis nunc. Nam vel arcu diam. Fusce lectus nisi, hendrerit ac accumsan quis, lobortis vitae sem. Praesent hendrerit fermentum libero et varius. Vivamus sagittis vitae ex eget luctus. Ut felis risus, faucibus nec cursus nec, tincidunt quis mi. Sed vulputate odio odio, id bibendum purus egestas in. Etiam non arcu eget dui maximus varius quis a neque. Proin non diam vel elit aliquet dignissim. Curabitur vulputate mauris sem, vel molestie mauris semper sit amet. Integer vel ipsum id libero facilisis tincidunt. +[Components](/docs/Components.md) + ## Morbi fermentum a Fusce molestie at tortor nec molestie. Nunc cursus a quam ac eleifend. Vestibulum nec quam vel purus tempor luctus in a risus. Aenean pretium, tellus eu accumsan dignissim, leo nibh tincidunt velit, id lacinia justo sapien vitae orci. Donec ut risus elementum, maximus augue vel, tempus enim. Quisque iaculis blandit nibh vel dapibus. Aenean eleifend sapien eget diam semper aliquet. Proin porta, tortor sit amet blandit fermentum, dui lorem tincidunt felis, at facilisis lectus ante quis nisl. +![Noop Logo](/docs/assets/logo.png) + Aenean pharetra sit amet eros id rutrum. Praesent scelerisque at metus quis iaculis. Suspendisse consequat porttitor ipsum, eget rhoncus massa pretium in. In hac habitasse platea dictumst. Aenean elementum dictum lacus, in malesuada arcu pellentesque nec. Curabitur placerat est dolor, ac facilisis odio dignissim et. Interdum et malesuada fames ac ante ipsum primis in faucibus. Ut sed libero luctus, tincidunt massa a, pharetra nisi. Proin id imperdiet enim. Vivamus placerat eget dui non mattis. Vivamus maximus eu massa a faucibus. Pellentesque blandit nunc a eleifend cursus. ## Vestibulum molestie odio +### Morbi fermentum a + Fusce scelerisque, enim mattis interdum laoreet, arcu orci blandit ipsum, ornare bibendum risus mi nec lectus. Curabitur dapibus, nisi vitae lobortis aliquam, ex risus posuere orci, a lacinia dui lacus ac neque. Ut cursus purus sit amet nulla tincidunt, a convallis velit pretium. Fusce in egestas urna. Quisque vitae ipsum et erat tempor vulputate. Mauris lorem nibh, tincidunt in erat et, suscipit consequat tellus. Ut vitae nisi odio. Vestibulum sodales libero id magna consequat suscipit. Donec turpis nisl, molestie at magna et, pretium pharetra ante. Donec vitae sem mattis turpis lobortis faucibus. Nam non risus viverra ante mollis dapibus. In a rutrum dui. Phasellus mollis risus vitae magna euismod tristique. Integer fermentum lacinia risus. ### Mauris consequat malesuada diff --git a/lib/index.js b/lib/index.js index 8a8e0dd..0747aef 100644 --- a/lib/index.js +++ b/lib/index.js @@ -115,9 +115,9 @@ class Section { this.#parent = parent this.#entries = entries - const key = header.text.replace(/\W/g, '') - const prior = this.#parent?.subSections || this.#parent?.sections || [] - const existing = prior.filter(section => section.title.replace(/\W/g, '') === key) + const key = header.text.replace(/[^a-zA-Z0-9_]+/g, '') + const prior = this.page.sections.map(section => [section, ...section.subSections]).flat() + const existing = prior.filter(section => section.title.replace(/[^a-zA-Z0-9_]+/g, '') === key) this.title = header.text this.key = `${key}${existing.length ? (existing.length + 1) : ''}` @@ -154,6 +154,14 @@ class Section { get parent () { return this.#parent } + + get page () { + return this.parent.parent || this.parent + } + + get section () { + return this.parent.parent ? this.parent : null + } } const docs = await (new Documentation()).load()