refactor(core): use new backlink indexer (#7296)

This commit is contained in:
EYHN
2024-07-02 09:18:01 +00:00
parent 40e381e272
commit 27d0fc5108
33 changed files with 826 additions and 357 deletions

View File

@@ -0,0 +1,24 @@
import type { DocService } from '@toeverything/infra';
import { Entity, LiveData } from '@toeverything/infra';
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$ = LiveData.from<Backlink[]>(
this.docsSearchService.watchRefsTo(this.docService.doc.id),
[]
);
}

View File

@@ -0,0 +1,23 @@
import type { DocService } from '@toeverything/infra';
import { Entity, LiveData } from '@toeverything/infra';
import type { DocsSearchService } from '../../docs-search';
interface Link {
docId: string;
title: string;
}
export class DocLinks extends Entity {
constructor(
private readonly docsSearchService: DocsSearchService,
private readonly docService: DocService
) {
super();
}
links$ = LiveData.from<Link[]>(
this.docsSearchService.watchRefsFrom(this.docService.doc.id),
[]
);
}

View File

@@ -0,0 +1,22 @@
import {
DocScope,
DocService,
type Framework,
WorkspaceScope,
} from '@toeverything/infra';
import { DocsSearchService } from '../docs-search';
import { DocBacklinks } from './entities/doc-backlinks';
import { DocLinks } from './entities/doc-links';
import { DocLinksService } from './services/doc-links';
export { DocLinksService } from './services/doc-links';
export function configureDocLinksModule(framework: Framework) {
framework
.scope(WorkspaceScope)
.scope(DocScope)
.service(DocLinksService)
.entity(DocBacklinks, [DocsSearchService, DocService])
.entity(DocLinks, [DocsSearchService, DocService]);
}

View File

@@ -0,0 +1,9 @@
import { Service } from '@toeverything/infra';
import { DocBacklinks } from '../entities/doc-backlinks';
import { DocLinks } from '../entities/doc-links';
export class DocLinksService extends Service {
backlinks = this.framework.createEntity(DocBacklinks);
links = this.framework.createEntity(DocLinks);
}