♻️ refactor: Reduce code complexity and improve readability
This commit is contained in:
parent
2ca299224d
commit
e11f18c034
@ -50,28 +50,27 @@ type TutorialItem = {
|
|||||||
subItems?: TutorialItem[];
|
subItems?: TutorialItem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const processIcon = (item: TutorialItem) => {
|
||||||
|
if ("icon" in item && typeof item.icon === 'string' && !item.icon.startsWith('http')) {
|
||||||
|
item.icon = `${BASE_URL}/${item.icon}`;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export async function getTutorialList() {
|
export async function getTutorialList() {
|
||||||
return await getTutorial('SUMMARY.md').then(({ config, content }) => {
|
const { config, content } = await getTutorial('SUMMARY.md');
|
||||||
const navigation = config as Record<string, TutorialItem[]> | undefined;
|
const navigation = config as Record<string, TutorialItem[]> | undefined;
|
||||||
let map = new Map<string, TutorialItem[]>();
|
|
||||||
if (navigation) {
|
if (!navigation) {
|
||||||
for (const value of Object.values(navigation)) {
|
return parseTutorialToMap(content);
|
||||||
for (const item of value) {
|
}
|
||||||
if (item.subItems) {
|
|
||||||
for (const subItem of item.subItems) {
|
Object.values(navigation)
|
||||||
if ("icon" in subItem && typeof subItem.icon === 'string' && !subItem.icon.startsWith('http')) {
|
.flat()
|
||||||
subItem.icon = `${BASE_URL}/${subItem.icon}`;
|
.forEach(item => {
|
||||||
}
|
item.subItems?.forEach(processIcon);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
}
|
return new Map(Object.entries(navigation));
|
||||||
}
|
|
||||||
map = new Map(Object.entries(navigation));
|
|
||||||
} else {
|
|
||||||
map = parseTutorialToMap(content);
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTutorialToMap(markdown: string): Map<string, TutorialItem[]> {
|
function parseTutorialToMap(markdown: string): Map<string, TutorialItem[]> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user