Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add markdown preview for backlinks #8883

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion packages/frontend/component/src/ui/property/property.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const PropertyCollapsibleSection = forwardRef<
collapsed?: boolean;
onCollapseChange?: (collapsed: boolean) => void;
}> &
HTMLProps<HTMLDivElement>
Omit<HTMLProps<HTMLDivElement>, 'title'>
>(
(
{
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 @@ -122,7 +122,6 @@ const DatabaseBacklinkRow = ({

return (
<PropertyCollapsibleSection
// @ts-expect-error fix type
title={
<span className={styles.databaseNameWrapper}>
<span className={styles.databaseName}>
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> =
pengx17 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading