From ece8444f81c9bf911aa6d02e5167dd21dc712565 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Sun, 28 Apr 2024 21:51:44 -0400 Subject: [PATCH] Fix name cleaning --- src/plugins/markdown-pages/discover.test.ts | 14 ++++---- .../markdown-pages/parse.build.test.ts | 32 +++++++++++++++++-- src/plugins/markdown-pages/parse.js | 2 +- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/plugins/markdown-pages/discover.test.ts b/src/plugins/markdown-pages/discover.test.ts index 5101a3f8..7708e4a7 100644 --- a/src/plugins/markdown-pages/discover.test.ts +++ b/src/plugins/markdown-pages/discover.test.ts @@ -23,13 +23,13 @@ describe('discover', () => { "name": "c", "pages": [ { - "cleanedName": "cb", + "cleanedName": "c b", "groupName": "c", "name": "c-b", "path": "/c/c-b.md", }, { - "cleanedName": "ca", + "cleanedName": "c a", "groupName": "c", "name": "c-a", "path": "/c/c-a.md", @@ -39,13 +39,13 @@ describe('discover', () => { "name": "d", "pages": [ { - "cleanedName": "da", + "cleanedName": "d a", "groupName": "d", "name": "d-a", "path": "/c/d/d-a.md", }, { - "cleanedName": "db", + "cleanedName": "d b", "groupName": "d", "name": "d-b", "path": "/c/d/d-b.md", @@ -57,13 +57,13 @@ describe('discover', () => { "name": "e", "pages": [ { - "cleanedName": "eb", + "cleanedName": "e b", "groupName": "e", "name": "e-b", "path": "/c/e/e-b.md", }, { - "cleanedName": "ea", + "cleanedName": "e a", "groupName": "e", "name": "e-a", "path": "/c/e/e-a.md", @@ -153,7 +153,7 @@ describe('discover', () => { expect(result.groups[1]?.list).toMatchInlineSnapshot(` [ { - "cleanedName": "somefile", + "cleanedName": "some file", "groupName": "components", "name": "some-file", "path": "/Group 1/components/some-file.md", diff --git a/src/plugins/markdown-pages/parse.build.test.ts b/src/plugins/markdown-pages/parse.build.test.ts index ca57bd94..7d808ee3 100644 --- a/src/plugins/markdown-pages/parse.build.test.ts +++ b/src/plugins/markdown-pages/parse.build.test.ts @@ -26,6 +26,29 @@ describe('build', () => { `); }); + test('hypehenated group', () => { + let result = build([{ mdPath: 'top-level/nested.md' }]); + + expect(result).toMatchInlineSnapshot(` + { + "name": "root", + "pages": [ + { + "name": "top level", + "pages": [ + { + "cleanedName": "nested", + "groupName": "top level", + "name": "nested", + "path": "/top-level/nested.md", + }, + ], + }, + ], + } + `); + }); + test('multiple shallow paths', () => { let result = build([ { mdPath: 'top/nested.md' }, @@ -47,14 +70,19 @@ describe('build', () => { "path": "/top/nested.md", }, { - "cleanedName": "nestedsibling", + "cleanedName": "nested sibling", "groupName": "top", "name": "nested-sibling", "path": "/top/nested-sibling.md", }, + ], + }, + { + "name": "top ", + "pages": [ { "cleanedName": "other", - "groupName": "top", + "groupName": "top ", "name": "other", "path": "/top-2/other.md", }, diff --git a/src/plugins/markdown-pages/parse.js b/src/plugins/markdown-pages/parse.js index ae55de13..c275966e 100644 --- a/src/plugins/markdown-pages/parse.js +++ b/src/plugins/markdown-pages/parse.js @@ -48,7 +48,7 @@ function deepSort(input) { * @returns {string} */ function cleanSegment(segment) { - return stripExt(segment.replaceAll(/[\d-]/g, '')); + return stripExt(segment.replaceAll(/\d/g, '').replaceAll('-', ' ')); } /**