Skip to content

Commit

Permalink
feat: inherit icon & color from every previous page
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Jul 13, 2024
1 parent 6ee663c commit aff207e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/modules/pageIcons/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const getPropsByPageName = async (pageTitle: string): Promise<propsObject
if (pageProps) {
resultedPageProps = { ...pageProps, ...resultedPageProps };
}
if ((!resultedPageProps['icon'] || !resultedPageProps['color']) && globals.pluginConfig.inheritFromProp) {
if (globals.pluginConfig.inheritFromProp && (!resultedPageProps['icon'] || !resultedPageProps['color'])) {
// inherited from page props, when props linked to page
pageProps = await getInheritedPropsProps(pageTitle);
if (pageProps) {
Expand All @@ -137,7 +137,7 @@ export const getPropsByPageName = async (pageTitle: string): Promise<propsObject
}
}
if (globals.pluginConfig.inheritFromHierarchy && pageTitle.includes('/') && (!resultedPageProps['icon'] || !resultedPageProps['color'])) {
// inherit from hierarchy root
// inherit from hierarchy pages
pageProps = await getHierarchyPageProps(pageTitle);
resultedPageProps = { ...pageProps, ...resultedPageProps };
}
Expand All @@ -149,13 +149,25 @@ export const getPropsByPageName = async (pageTitle: string): Promise<propsObject
}

export const getHierarchyPageProps = async (pageTitle: string): Promise<propsObject> => {
let pageProps: propsObject = Object.create(null);
pageTitle = pageTitle.split('/')[0];
pageProps = await getPageProps(pageTitle);
let resultedPageProps = { ...pageProps };
if (!pageProps['icon'] || !pageProps['color']) {
pageProps = await getInheritedPropsProps(pageTitle);
const titles = pageTitle.split('/');
const pageTitles = titles.slice(0, -1).reduce(
(r) => r.concat(titles.slice(0, r.length + 1).join('/')),
[] as Array<string>
).reverse()

let resultedPageProps: propsObject = Object.create(null);
for (const pageTitle of pageTitles) {
let pageProps = await getPageProps(pageTitle);
resultedPageProps = { ...pageProps, ...resultedPageProps };
if (resultedPageProps['icon'] && resultedPageProps['color'])
break

if (globals.pluginConfig.inheritFromProp) {
pageProps = await getInheritedPropsProps(pageTitle);
resultedPageProps = { ...pageProps, ...resultedPageProps };
if (resultedPageProps['icon'] && resultedPageProps['color'])
break
}
}
return resultedPageProps;
}
Expand Down

0 comments on commit aff207e

Please sign in to comment.