From 9bfd8c043fe67b23cbd791f7802ee619c599b7df Mon Sep 17 00:00:00 2001 From: Derek Wolpert Date: Wed, 28 Sep 2022 14:49:34 -0400 Subject: [PATCH] add title key generation for a page --- lib/index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4ca10e4..e6e3e7b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -64,6 +64,7 @@ class Documentation { class Page { key title + titleKey body sections = [] #documentation @@ -77,6 +78,11 @@ class Page { this.#index = index this.#entries = entries this.title = header.text + this.titleKey = this.title + .replace(/[^a-zA-Z0-9]+/g, ' ') + .trim() + .replace(/\s+/g, '-') + .toLowerCase() } async load () { @@ -152,11 +158,7 @@ class Section { // assigns unique key value for section const prior = [ - this.page.title - .replace(/[^a-zA-Z0-9]+/g, ' ') - .trim() - .replace(/\s+/g, '-') - .toLowerCase(), + this.page.titleKey, ...this.page.sections .map(section => [section, ...section.subsections]) .flat()