Skip to content

Commit

Permalink
Merge pull request #101 from rtablada/fix-find-config
Browse files Browse the repository at this point in the history
Fixes Configs Not Found In Dasherized Paths
  • Loading branch information
NullVoxPopuli committed Jul 16, 2024
2 parents 61136cc + 513b07a commit 5d1e68e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/plugins/markdown-pages/discover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('discover', () => {
"path": "/c/d/d-b.md",
},
],
"path": "d",
},
{
"first": "/c/e/e-b.md",
Expand All @@ -75,10 +76,13 @@ describe('discover', () => {
"path": "/c/e/e-a.md",
},
],
"path": "e",
},
],
"path": "c",
},
],
"path": "root",
}
`);
});
Expand All @@ -102,8 +106,10 @@ describe('discover', () => {
"path": "/main/index.md",
},
],
"path": "main",
},
],
"path": "root",
}
`);
});
Expand All @@ -115,6 +121,7 @@ describe('discover', () => {
{
"name": "root",
"pages": [],
"path": "root",
}
`);
});
Expand Down
10 changes: 10 additions & 0 deletions src/plugins/markdown-pages/hydrate.addInTheFirstPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -32,16 +33,19 @@ describe('addInTheFirstPage', () => {
"path": "/top/foo.md",
},
],
"path": "top",
}
`);
});

test('adds in the first page', () => {
let tree: Collection = {
name: 'top',
path: 'top',
pages: [
{
name: 'mid',
path: 'mid',
pages: [
{
name: 'foo.md',
Expand Down Expand Up @@ -72,18 +76,22 @@ describe('addInTheFirstPage', () => {
"path": "/top/mid/foo.md",
},
],
"path": "mid",
},
],
"path": "top",
}
`);
});

test('adds in the index page', () => {
let tree: Collection = {
name: 'top',
path: 'top',
pages: [
{
name: 'mid',
path: 'mid',
pages: [
{
name: 'index.md',
Expand Down Expand Up @@ -126,8 +134,10 @@ describe('addInTheFirstPage', () => {
"path": "/top/mid/foo.md",
},
],
"path": "mid",
},
],
"path": "top",
}
`);
});
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/markdown-pages/hydrate.prefixPaths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('prefixPaths', () => {
test('it works', () => {
let tree: Collection = {
name: 'top',
path: 'top',
pages: [
{
name: 'foo.md',
Expand All @@ -31,16 +32,19 @@ describe('prefixPaths', () => {
"path": "/prefix/top/foo.md",
},
],
"path": "top",
}
`);
});

test('works on deep objects', () => {
let tree: Collection = {
name: 'top',
path: 'top',
pages: [
{
name: 'mid',
path: 'mid',
pages: [
{
name: 'index.md',
Expand Down Expand Up @@ -81,8 +85,10 @@ describe('prefixPaths', () => {
"path": "/prefix/top/mid/foo.md",
},
],
"path": "mid",
},
],
"path": "top",
}
`);
});
Expand Down
14 changes: 14 additions & 0 deletions src/plugins/markdown-pages/parse.build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ describe('build', () => {
"path": "/top/nested.md",
},
],
"path": "top",
},
],
"path": "root",
}
`);
});
Expand All @@ -43,8 +45,10 @@ describe('build', () => {
"path": "/top-level/nested.md",
},
],
"path": "top-level",
},
],
"path": "root",
}
`);
});
Expand Down Expand Up @@ -76,6 +80,7 @@ describe('build', () => {
"path": "/top/nested-sibling.md",
},
],
"path": "top",
},
{
"name": "top ",
Expand All @@ -87,8 +92,10 @@ describe('build', () => {
"path": "/top-2/other.md",
},
],
"path": "top-2",
},
],
"path": "root",
}
`);
});
Expand All @@ -113,10 +120,13 @@ describe('build', () => {
"path": "/top/deep/path.md",
},
],
"path": "deep",
},
],
"path": "top",
},
],
"path": "root",
}
`);
});
Expand Down Expand Up @@ -148,12 +158,16 @@ describe('build', () => {
"path": "/top/deep/another/index.md",
},
],
"path": "another",
},
],
"path": "deep",
},
],
"path": "top",
},
],
"path": "root",
}
`);
});
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/markdown-pages/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')) {
Expand Down Expand Up @@ -92,6 +92,7 @@ export function build(docs) {
if (!currentCollection) {
/** @type {import('./types.ts').Collection} */
currentCollection = {
path: group,
name: groupName,
pages: [],
};
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/markdown-pages/sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/markdown-pages/sort.sortTree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('sortTree', () => {
let result = sortTree(
{
name: 'top',
path: 'top',
pages: [
{
path: '/top/second',
Expand Down Expand Up @@ -39,6 +40,7 @@ describe('sortTree', () => {
"path": "/top/first",
},
],
"path": "top",
}
`);
});
Expand All @@ -47,6 +49,7 @@ describe('sortTree', () => {
let result = sortTree(
{
name: 'top',
path: 'top',
pages: [
{
path: '/top/second',
Expand All @@ -68,9 +71,11 @@ describe('sortTree', () => {
let result = sortTree(
{
name: 'top',
path: 'top',
pages: [
{
name: 'child',
path: 'child',
pages: [
{
path: '/top/child/second',
Expand Down
1 change: 1 addition & 0 deletions ui/src/services/kolay/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Manifest {
}

export interface Collection {
path: string;
name: string;
first?: string;
pages: (Collection | Page)[];
Expand Down

0 comments on commit 5d1e68e

Please sign in to comment.