Skip to content

Commit

Permalink
address edge case situation to ensure all sections and subsections on…
Browse files Browse the repository at this point in the history
… a page are assigned unique key values
  • Loading branch information
derekwolpert committed Sep 27, 2022
1 parent 6d2ed24 commit f4774d0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions docs/Test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) : ''}`
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit f4774d0

Please sign in to comment.