Skip to content

Commit 5162ca5

Browse files
committed
Rollback on getTitle
1 parent d133227 commit 5162ca5

5 files changed

Lines changed: 18 additions & 11 deletions

File tree

electron/db.sqlite-journal

-8.52 KB
Binary file not shown.

src/app/book/gbr-preset/plugins/frontmatter.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@ export function getTitle(): Transformer {
2525
return (tree: Root, file: VFile) => {
2626
file.data = file.data || {};
2727
return visit(tree, 'heading', (node: Heading) => {
28-
let title: string;
29-
30-
for (let i=1; !title && node.depth === i; i++){
31-
title = toString(node);
28+
if (node.depth === 1 && !file.data.title) {
29+
file.data.title = toString(node);
3230
}
33-
34-
file.data.title = title;
35-
3631
return true;
3732
});
3833
};

src/app/book/markdown-elements/toc-pagination.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ export class TOCPaginationComponent implements OnInit, OnChanges {
9999

100100
const p = paths.map(async path => {
101101
const _vfile = await this.fetch(path);
102-
await this.markdownService.process(_vfile);
102+
await this.markdownService.processTOCPagination(_vfile);
103103
return _vfile;
104104
});
105105

106106
return Promise.all(p).then(files => {
107107
this.files = files.reduce((acc: Array<FileIndexItem>, _: VFile): Array<FileIndexItem> => {
108+
console.log(_);
108109
const path = getBasePath(_);
109110
let link: string | string[] = this.locationService.prepareLink(path, this.routerService.root);
110111

src/app/book/markdown/markdown.service.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ export class MarkdownService {
9191
.use(rehypeStringify);
9292
}
9393

94+
@lazyInitialize
95+
private get tocPaginationProcessor() {
96+
return remark()
97+
.use(getTitle)
98+
}
99+
94100
@lazyInitialize
95101
private get linksProcessor() {
96102
return remark()
@@ -219,6 +225,12 @@ export class MarkdownService {
219225
return err || file;
220226
}
221227

228+
async processTOCPagination(doc: VFileCompatible) {
229+
const file = VFile(doc) as VFile;
230+
const err = await this.tocPaginationProcessor.process(file) as VFile;
231+
return err || file;
232+
}
233+
222234
/**
223235
* Get Sections
224236
*/
@@ -258,7 +270,7 @@ export class MarkdownService {
258270
/^\//.test(__.url.split('#')[0])
259271
? __.url.split('#')[0]
260272
: `/${__.url.split('#')[0]}`
261-
)) < 0)
273+
)) < 0)
262274
? [...acc, decodeURI(/^\//.test(__.url.split('#')[0]) ? __.url.split('#')[0] : `/${__.url.split('#')[0]}`)]
263275
: acc;
264276
}, []) as Array<string>;
@@ -269,7 +281,6 @@ export class MarkdownService {
269281

270282
loadSummary = async (summary: string) => {
271283
const _vfile = this.locationService.pageToFile(summary);
272-
273284
const fullPath = await this.fetchService.find(_vfile.cwd, _vfile.path);
274285

275286
const pathsFromBackend: Array<string> = await this.loadSummaryFromBackend();

src/app/book/services/search.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class SearchService {
7272
).toPromise();
7373
});
7474

75-
return Promise.all(promises).then(files => {
75+
Promise.all(promises).then(files => {
7676
this.searchIndex = files.reduce((acc: Array<any>, f: VFile): Array<any> => {
7777
// 这里这句代码要命,很容易写错..., 少写三个点就完全不一样了的 :)
7878
//return f ? [...acc, f.data.tocSearch] : acc;

0 commit comments

Comments
 (0)