Skip to content

Commit

Permalink
feat(core): add markdown preview for backlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
EYHN authored and pengx17 committed Nov 28, 2024
1 parent c95e6ec commit 3e1e1f4
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/package.json b/package.json
index 5fef2811aa86f3f1f8228daef7d867863e71db72..b795fbd2a0e1cba0b6389ff051220f4e3c52fc13 100644
--- a/package.json
+++ b/package.json
@@ -34,7 +34,7 @@
"deno": "./index.js",
"react-native": "./index.js",
"worker": "./index.js",
- "browser": "./index.dom.js",
+ "browser": "./index.js",
"default": "./index.js"
}
},
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"which-typed-array": "npm:@nolyfill/which-typed-array@latest",
"macos-alias": "npm:@napi-rs/[email protected]",
"fs-xattr": "npm:@napi-rs/xattr@latest",
"vite": "6.0.1"
"vite": "6.0.1",
"decode-named-character-reference@npm:^1.0.0": "patch:decode-named-character-reference@npm%3A1.0.2#~/.yarn/patches/decode-named-character-reference-npm-1.0.2-db17a755fd.patch"
}
}
2 changes: 1 addition & 1 deletion packages/common/infra/src/sync/indexer/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class Document<S extends Schema = any> {
}
} else {
for (const key in map) {
if (map[key] === undefined) {
if (map[key] === undefined || map[key] === null) {
continue;
}
doc.insert(key, map[key]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@affine/core/modules/doc-link';
import { useI18n } from '@affine/i18n';
import { LiveData, useLiveData, useServices } from '@toeverything/infra';
import { useCallback, useState } from 'react';
import { Fragment, useCallback, useState } from 'react';

import { AffinePageReference } from '../../affine/reference-link';
import * as styles from './bi-directional-link-panel.css';
Expand Down Expand Up @@ -52,9 +52,14 @@ export const BiDirectionalLinkPanel = () => {
{t['com.affine.page-properties.backlinks']()} · {backlinks.length}
</div>
{backlinks.map(link => (
<div key={link.docId} className={styles.link}>
<AffinePageReference key={link.docId} pageId={link.docId} />
</div>
<Fragment key={link.docId}>
<div className={styles.link}>
<AffinePageReference key={link.docId} pageId={link.docId} />
</div>
<br />
<pre style={{ opacity: 0.5 }}>{link.markdownPreview}</pre>
<br />
</Fragment>
))}
</div>
<div className={styles.linksContainer}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Backlink {
docId: string;
blockId: string;
title: string;
markdownPreview?: string;
}

export class DocBacklinks extends Entity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class DocsIndexer extends Entity {
/**
* increase this number to re-index all docs
*/
static INDEXER_VERSION = 6;
static INDEXER_VERSION = 10;

private readonly jobQueue: JobQueue<IndexerJobPayload> =
new IndexedDBJobQueue<IndexerJobPayload>(
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/core/src/modules/docs-search/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const blockIndexSchema = defineSchema({
// additional info
// { "databaseName": "xxx" }
additional: { type: 'String', index: false },
markdownPreview: { type: 'String', index: false },
});

export type BlockIndexSchema = typeof blockIndexSchema;
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ export class DocsSearchService extends Service {
'docId',
{
hits: {
fields: ['docId', 'blockId'],
fields: ['docId', 'blockId', 'markdownPreview'],
pagination: {
limit: 1,
},
Expand All @@ -499,10 +499,16 @@ export class DocsSearchService extends Service {
const title =
docData.find(doc => doc.id === bucket.key)?.get('title') ?? '';
const blockId = bucket.hits.nodes[0]?.fields.blockId ?? '';
const markdownPreview =
bucket.hits.nodes[0]?.fields.markdownPreview ?? '';
return {
docId: bucket.key,
blockId: typeof blockId === 'string' ? blockId : blockId[0],
title: typeof title === 'string' ? title : title[0],
markdownPreview:
typeof markdownPreview === 'string'
? markdownPreview
: markdownPreview[0],
};
});
});
Expand Down
Loading

0 comments on commit 3e1e1f4

Please sign in to comment.