Skip to content

Commit

Permalink
feat(plugin-pages): implement logic for glob expansion
Browse files Browse the repository at this point in the history
Related to #132
  • Loading branch information
GerkinDev committed Jul 24, 2022
1 parent 34db47c commit 120ee01
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 40 deletions.
48 changes: 30 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
"typedoc": "^0.23.8",
"typescript": "^4.7.4",
"unionfs": "^4.4.0",
"yaml": "^2.1.1"
"yaml": "^2.1.1",
"@types/glob": "^7.2.0"
}
}
4 changes: 3 additions & 1 deletion packages/plugin-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
},
"dependencies": {
"lodash": "^4.17.21",
"@knodes/typedoc-pluginutils": "~0.23.1"
"@knodes/typedoc-pluginutils": "~0.23.1",
"glob": "^8.0.3"
},
"peerDependencies": {
"typedoc": "^0.23.0",
Expand Down Expand Up @@ -71,6 +72,7 @@
"typedoc": "^0.23.8",
"typescript": "^4.7.4",
"@types/fs-extra": "^9.0.13",
"@types/glob": "^7.2.0",
"@types/lunr": "^2.3.4",
"conventional-changelog-cli": "^2.2.2",
"type-fest": "^2.16.0"
Expand Down
36 changes: 36 additions & 0 deletions packages/plugin-pages/src/converter/page-tree/expand-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { basename, dirname, relative } from 'path/posix';

import { LoDashStatic, cloneDeep, isArray, isPlainObject, isString, template } from 'lodash';

export interface IExpandContext {
from: string;
match: string;
fullPath: string;
prev: IExpandContext[];
}

export interface IExpandContextImports{
_: LoDashStatic;
path: Pick<typeof import( 'path' ), 'dirname' | 'basename' | 'relative'>;
}
const imports: Omit<IExpandContextImports, '_'> = {
path: {
dirname,
basename,
relative,
},
};

export const expandNode = <T>( node: T, context: IExpandContext ): T => {
const nodeClone = cloneDeep( node ) as any;
Object.entries( nodeClone ).forEach( ( [ k, v ] ) => {
if( isString( v ) ){
nodeClone[k] = template( v, { variable: 'context', imports } )( context );
} else if( isArray( v ) ){
nodeClone[k] = v.map( vv => expandNode( vv, context ) );
} else if( isPlainObject( v ) ){
nodeClone[k] = expandNode( v, context );
}
} );
return nodeClone;
};
1 change: 1 addition & 0 deletions packages/plugin-pages/src/converter/page-tree/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './page-tree-builder';
export * from './utils';
export { IExpandContextImports as ExpandContextImports, IExpandContext } from './expand-context';
Loading

0 comments on commit 120ee01

Please sign in to comment.