-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): use new backlink indexer
- Loading branch information
Showing
8 changed files
with
127 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/frontend/core/src/modules/doc-link/entities/doc-backlinks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import type { DocService } from '@toeverything/infra'; | ||
import { | ||
effect, | ||
Entity, | ||
fromPromise, | ||
LiveData, | ||
mapInto, | ||
} from '@toeverything/infra'; | ||
import { exhaustMap } from 'rxjs'; | ||
|
||
import type { DocsSearchService } from '../../docs-search'; | ||
|
||
interface Backlink { | ||
docId: string; | ||
blockId: string; | ||
title: string; | ||
} | ||
|
||
export class DocBacklinks extends Entity { | ||
constructor( | ||
private readonly docsSearchService: DocsSearchService, | ||
private readonly docService: DocService | ||
) { | ||
super(); | ||
} | ||
|
||
backlinks$ = new LiveData<Backlink[]>([]); | ||
|
||
revalidate = effect( | ||
exhaustMap(() => { | ||
return fromPromise( | ||
this.docsSearchService.searchRefsTo(this.docService.doc.id) | ||
).pipe(mapInto(this.backlinks$)); | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { DocScope, DocService, type Framework } from '@toeverything/infra'; | ||
|
||
import { DocsSearchService } from '../docs-search'; | ||
import { DocBacklinks } from './entities/doc-backlinks'; | ||
import { DocLinksServices } from './services/doc-links'; | ||
|
||
export { DocLinksServices } from './services/doc-links'; | ||
|
||
export function configureDocLinksModules(framework: Framework) { | ||
framework | ||
.scope(DocScope) | ||
.service(DocLinksServices) | ||
.entity(DocBacklinks, [DocsSearchService, DocService]); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/frontend/core/src/modules/doc-link/services/doc-links.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Service } from '@toeverything/infra'; | ||
|
||
import { DocBacklinks } from '../entities/doc-backlinks'; | ||
|
||
export class DocLinksServices extends Service { | ||
backlinks = this.framework.createEntity(DocBacklinks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import type { Schema } from '@toeverything/infra'; | ||
import { defineSchema } from '@toeverything/infra'; | ||
|
||
export const docIndexSchema = { | ||
export const docIndexSchema = defineSchema({ | ||
title: 'FullText', | ||
} satisfies Schema; | ||
}); | ||
|
||
export const blockIndexSchema = { | ||
export type DocIndexSchema = typeof docIndexSchema; | ||
|
||
export const blockIndexSchema = defineSchema({ | ||
docId: 'String', | ||
blockId: 'String', | ||
content: 'FullText', | ||
flavour: 'String', | ||
} satisfies Schema; | ||
ref: 'String', | ||
blob: 'String', | ||
}); | ||
|
||
export type BlockIndexSchema = typeof blockIndexSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters