diff --git a/src/plugins/markdown-pages/discover.test.ts b/src/plugins/markdown-pages/discover.test.ts index 1a3b264..4a846be 100644 --- a/src/plugins/markdown-pages/discover.test.ts +++ b/src/plugins/markdown-pages/discover.test.ts @@ -57,6 +57,7 @@ describe('discover', () => { "path": "/c/d/d-b.md", }, ], + "path": "d", }, { "first": "/c/e/e-b.md", @@ -75,10 +76,13 @@ describe('discover', () => { "path": "/c/e/e-a.md", }, ], + "path": "e", }, ], + "path": "c", }, ], + "path": "root", } `); }); @@ -102,8 +106,10 @@ describe('discover', () => { "path": "/main/index.md", }, ], + "path": "main", }, ], + "path": "root", } `); }); @@ -115,6 +121,7 @@ describe('discover', () => { { "name": "root", "pages": [], + "path": "root", } `); }); diff --git a/src/plugins/markdown-pages/hydrate.addInTheFirstPage.test.ts b/src/plugins/markdown-pages/hydrate.addInTheFirstPage.test.ts index 9c0de32..4f4e64a 100644 --- a/src/plugins/markdown-pages/hydrate.addInTheFirstPage.test.ts +++ b/src/plugins/markdown-pages/hydrate.addInTheFirstPage.test.ts @@ -8,6 +8,7 @@ describe('addInTheFirstPage', () => { test('adds in the first page to a shallow object', () => { let tree: Collection = { name: 'top', + path: 'top', pages: [ { name: 'foo.md', @@ -32,6 +33,7 @@ describe('addInTheFirstPage', () => { "path": "/top/foo.md", }, ], + "path": "top", } `); }); @@ -39,9 +41,11 @@ describe('addInTheFirstPage', () => { test('adds in the first page', () => { let tree: Collection = { name: 'top', + path: 'top', pages: [ { name: 'mid', + path: 'mid', pages: [ { name: 'foo.md', @@ -72,8 +76,10 @@ describe('addInTheFirstPage', () => { "path": "/top/mid/foo.md", }, ], + "path": "mid", }, ], + "path": "top", } `); }); @@ -81,9 +87,11 @@ describe('addInTheFirstPage', () => { test('adds in the index page', () => { let tree: Collection = { name: 'top', + path: 'top', pages: [ { name: 'mid', + path: 'mid', pages: [ { name: 'index.md', @@ -126,8 +134,10 @@ describe('addInTheFirstPage', () => { "path": "/top/mid/foo.md", }, ], + "path": "mid", }, ], + "path": "top", } `); }); diff --git a/src/plugins/markdown-pages/hydrate.prefixPaths.test.ts b/src/plugins/markdown-pages/hydrate.prefixPaths.test.ts index cb8fc87..cce4bf3 100644 --- a/src/plugins/markdown-pages/hydrate.prefixPaths.test.ts +++ b/src/plugins/markdown-pages/hydrate.prefixPaths.test.ts @@ -8,6 +8,7 @@ describe('prefixPaths', () => { test('it works', () => { let tree: Collection = { name: 'top', + path: 'top', pages: [ { name: 'foo.md', @@ -31,6 +32,7 @@ describe('prefixPaths', () => { "path": "/prefix/top/foo.md", }, ], + "path": "top", } `); }); @@ -38,9 +40,11 @@ describe('prefixPaths', () => { test('works on deep objects', () => { let tree: Collection = { name: 'top', + path: 'top', pages: [ { name: 'mid', + path: 'mid', pages: [ { name: 'index.md', @@ -81,8 +85,10 @@ describe('prefixPaths', () => { "path": "/prefix/top/mid/foo.md", }, ], + "path": "mid", }, ], + "path": "top", } `); }); diff --git a/src/plugins/markdown-pages/parse.build.test.ts b/src/plugins/markdown-pages/parse.build.test.ts index 7d808ee..67b4bd7 100644 --- a/src/plugins/markdown-pages/parse.build.test.ts +++ b/src/plugins/markdown-pages/parse.build.test.ts @@ -20,8 +20,10 @@ describe('build', () => { "path": "/top/nested.md", }, ], + "path": "top", }, ], + "path": "root", } `); }); @@ -43,8 +45,10 @@ describe('build', () => { "path": "/top-level/nested.md", }, ], + "path": "top-level", }, ], + "path": "root", } `); }); @@ -76,6 +80,7 @@ describe('build', () => { "path": "/top/nested-sibling.md", }, ], + "path": "top", }, { "name": "top ", @@ -87,8 +92,10 @@ describe('build', () => { "path": "/top-2/other.md", }, ], + "path": "top-2", }, ], + "path": "root", } `); }); @@ -113,10 +120,13 @@ describe('build', () => { "path": "/top/deep/path.md", }, ], + "path": "deep", }, ], + "path": "top", }, ], + "path": "root", } `); }); @@ -148,12 +158,16 @@ describe('build', () => { "path": "/top/deep/another/index.md", }, ], + "path": "another", }, ], + "path": "deep", }, ], + "path": "top", }, ], + "path": "root", } `); }); diff --git a/src/plugins/markdown-pages/parse.js b/src/plugins/markdown-pages/parse.js index c275966..b29d42a 100644 --- a/src/plugins/markdown-pages/parse.js +++ b/src/plugins/markdown-pages/parse.js @@ -57,7 +57,7 @@ function cleanSegment(segment) { */ export function build(docs) { /** @type {import('./types.ts').Collection} */ - let result = { name: 'root', pages: [] }; + let result = { name: 'root', pages: [], path: 'root' }; for (let { mdPath, config } of docs) { if (!mdPath.includes('/')) { @@ -92,6 +92,7 @@ export function build(docs) { if (!currentCollection) { /** @type {import('./types.ts').Collection} */ currentCollection = { + path: group, name: groupName, pages: [], }; diff --git a/src/plugins/markdown-pages/sort.js b/src/plugins/markdown-pages/sort.js index ce7d72b..7c00517 100644 --- a/src/plugins/markdown-pages/sort.js +++ b/src/plugins/markdown-pages/sort.js @@ -127,10 +127,10 @@ export function sortTree(tree, configs, parents = []) { return tree; } - tree.pages.map((subTree) => sortTree(subTree, configs, [...parents, tree.name])); + tree.pages.map((subTree) => sortTree(subTree, configs, [...parents, tree.path])); if (configs.length > 0) { - let subPath = `${[...parents, tree.name].join('/')}`; + let subPath = `${[...parents, tree.path].join('/')}`; let config = configs .filter(Boolean) .find((config) => findPathForJsonc(config.path) === subPath)?.config; diff --git a/src/plugins/markdown-pages/sort.sortTree.test.ts b/src/plugins/markdown-pages/sort.sortTree.test.ts index e9314fd..fd7170c 100644 --- a/src/plugins/markdown-pages/sort.sortTree.test.ts +++ b/src/plugins/markdown-pages/sort.sortTree.test.ts @@ -9,6 +9,7 @@ describe('sortTree', () => { let result = sortTree( { name: 'top', + path: 'top', pages: [ { path: '/top/second', @@ -39,6 +40,7 @@ describe('sortTree', () => { "path": "/top/first", }, ], + "path": "top", } `); }); @@ -47,6 +49,7 @@ describe('sortTree', () => { let result = sortTree( { name: 'top', + path: 'top', pages: [ { path: '/top/second', @@ -68,9 +71,11 @@ describe('sortTree', () => { let result = sortTree( { name: 'top', + path: 'top', pages: [ { name: 'child', + path: 'child', pages: [ { path: '/top/child/second', diff --git a/ui/src/services/kolay/types.ts b/ui/src/services/kolay/types.ts index a2df530..8243e7a 100644 --- a/ui/src/services/kolay/types.ts +++ b/ui/src/services/kolay/types.ts @@ -7,6 +7,7 @@ export interface Manifest { } export interface Collection { + path: string; name: string; first?: string; pages: (Collection | Page)[];