Skip to content

Commit 8bf2b4e

Browse files
committed
main
1 parent 1af3832 commit 8bf2b4e

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

docs/services/DocumentService.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,21 @@ class DocumentService implements IDocumentService {
4747
readonly readingDocInfo: DocumentInfo = readingDocMap;
4848

4949
get skillDocParent(): FileSystem.DirectoryInfo {
50-
const doc = FileSystem.projectRoot()
51-
.getDirectories()
52-
.find(x => x.name === 'document');
50+
const doc = FileSystem.documentRoot();
5351
const ret = doc.getDirectories().find(x => x.name === 'Skill');
5452
if (!ret) throw new Error('Skill Document source not found.');
5553
return ret;
5654
}
5755

5856
get readingDocParent(): FileSystem.DirectoryInfo {
59-
const doc = FileSystem.projectRoot()
60-
.getDirectories()
61-
.find(x => x.name === 'document');
57+
const doc = FileSystem.documentRoot();
6258
const ret = doc.getDirectories().find(x => x.name === 'Reading');
6359
if (!ret) throw new Error('Reading Document source not found.');
6460
return ret;
6561
}
6662

6763
get articleDocParent(): FileSystem.DirectoryInfo {
68-
const doc = FileSystem.projectRoot()
69-
.getDirectories()
70-
.find(x => x.name === 'document');
64+
const doc = FileSystem.documentRoot();
7165
const ret = doc.getDirectories().find(x => x.name === 'Articles');
7266
if (!ret) throw new Error('Articles Document source not found.');
7367
return ret;
@@ -93,9 +87,9 @@ class DocumentService implements IDocumentService {
9387

9488
let src: FileSystem.DirectoryInfo;
9589

96-
if (Object.keys(skillDocMap).includes(name)) {
90+
if (Object.prototype.hasOwnProperty.call(skillDocMap, name)) {
9791
src = this.skillDocParent;
98-
} else if (Object.keys(readingDocMap).includes(name)) {
92+
} else if (Object.prototype.hasOwnProperty.call(readingDocMap, name)) {
9993
src = this.readingDocParent;
10094
}
10195

@@ -132,14 +126,18 @@ class DocumentService implements IDocumentService {
132126
const shouldSolveSharpSign = (name: DocumentName) => name.includes('#');
133127

134128
let src: FileSystem.DirectoryInfo;
135-
if (Object.keys(skillDocMap).includes(name)) {
129+
if (name === 'Articles') src = this.articleDocParent;
130+
else if (Object.prototype.hasOwnProperty.call(skillDocMap, name)) {
136131
src = this.skillDocParent;
137-
} else if (Object.keys(readingDocMap).includes(name)) {
132+
} else if (Object.prototype.hasOwnProperty.call(readingDocMap, name)) {
138133
src = this.readingDocParent;
139134
}
135+
140136
const markdownEntry = this.getMarkdownEntryFolder(name);
141-
let linkContext = `document/${src.name}/${name}/`;
137+
let linkContext =
138+
name === 'Articles' ? `document/${src.name}` : `document/${src.name}/${name}/`;
142139

140+
// any md presented at first level
143141
if (markdownEntry.getFiles().length) {
144142
const file = Enumerable.from(markdownEntry.getFiles())
145143
.orderBy(x => x.name)

docs/services/SidebarService.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,25 @@ const solveSharpSign = (text: string) => {
1212
};
1313

1414
class SidebarService implements ISidebarService {
15-
private readonly base: string = `/${documentRoot().name}`;
15+
private getBase(name: DocumentName): string {
16+
if (documentService.skillDocInfo.hasOwnProperty(name) && name !== 'Articles') {
17+
return `/${documentRoot().name}/Skill`;
18+
}
19+
if (documentService.readingDocInfo.hasOwnProperty(name)) {
20+
return `/${documentRoot().name}/Reading`;
21+
}
22+
return `/${documentRoot().name}`;
23+
}
1624
readonly documentService: IDocumentService = documentService;
1725
getMultipleSidebar(): DefaultTheme.SidebarMulti {
1826
const sidebar: DefaultTheme.SidebarMulti = {};
1927
for (const name of Object.keys(documentService.skillDocInfo)) {
20-
sidebar[`${this.base}/Skill/${name}/docs/`] = this.getSidebarOfDocument(name as DocumentName);
28+
sidebar[`${this.getBase(name as DocumentName)}/${name}/docs/`] = this.getSidebarOfDocument(
29+
name as DocumentName,
30+
);
2131
}
2232
for (const name of Object.keys(documentService.readingDocInfo)) {
23-
sidebar[`${this.base}/Reading/${name}/docs/`] = this.getSidebarOfDocument(
33+
sidebar[`${this.getBase(name as DocumentName)}/${name}/docs/`] = this.getSidebarOfDocument(
2434
name as DocumentName,
2535
);
2636
}
@@ -33,10 +43,11 @@ class SidebarService implements ISidebarService {
3343
text: solveSharpSign(name),
3444
items:
3545
name === 'Articles'
36-
? this.transformFolderToSidebarItem(markdownEntry, `${this.base}/${name}`).sort(
37-
(a, b) => gitTrackedDate(a.link!) - gitTrackedDate(b.link!),
38-
)
39-
: this.transformFolderToSidebarItem(markdownEntry, `${this.base}/${name}`),
46+
? this.transformFolderToSidebarItem(
47+
markdownEntry,
48+
`${this.getBase(name)}/${name}`,
49+
).sort((a, b) => gitTrackedDate(a.link!) - gitTrackedDate(b.link!))
50+
: this.transformFolderToSidebarItem(markdownEntry, `${this.getBase(name)}/${name}`),
4051
},
4152
];
4253
function gitTrackedDate(file: string): number {

docs/shared/FileSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,5 @@ export function projectRoot(): DirectoryInfo {
124124
export function documentRoot(): DirectoryInfo {
125125
return projectRoot()
126126
.getDirectories()
127-
.filter(x => x.name === 'document')[0];
127+
.find(x => x.name === 'document');
128128
}

0 commit comments

Comments
 (0)