feat(editor): add favicon, title, description support for footnote url reference (#11924)

Closes: [BS-3272](https://linear.app/affine-design/issue/BS-3272/footnote-适配-exa-api-返回结果)

## What's Changed

Add link preview data support (favicon, title, description) for URL references in footnotes:
- Store and display URL preview data in footnotes
- Add encoding/decoding support for favicon URLs
- Optimize link preview by using existing preview data when available
This commit is contained in:
donteatfriedrice
2025-04-23 11:57:25 +00:00
parent ff133d1267
commit db5eadb72a
7 changed files with 121 additions and 31 deletions
@@ -31,9 +31,15 @@ export class FootNotePopup extends SignalWatcher(WithDisposable(LitElement)) {
private readonly _isLoading$ = signal(false);
private readonly _linkPreview$ = signal<
{ favicon: string | undefined; title?: string } | undefined
>({ favicon: undefined, title: undefined });
private readonly _linkPreview$ = signal<{
favicon: string | undefined;
title?: string;
description?: string;
}>({
favicon: undefined,
title: undefined,
description: undefined,
});
private readonly _prefixIcon$ = computed(() => {
const referenceType = this.footnote.reference.type;
@@ -105,9 +111,29 @@ export class FootNotePopup extends SignalWatcher(WithDisposable(LitElement)) {
this.abortController.abort();
};
private readonly _initLinkPreviewData = () => {
this._linkPreview$.value = {
favicon: this.footnote.reference.favicon,
title: this.footnote.reference.title,
description: this.footnote.reference.description,
};
};
override connectedCallback() {
super.connectedCallback();
if (this.footnote.reference.type === 'url' && this.footnote.reference.url) {
this._initLinkPreviewData();
// If the reference is a url, and the url exists
// and the link preview data is not already set, fetch the link preview data
const isTitleAndDescriptionEmpty =
!this._linkPreview$.value?.title &&
!this._linkPreview$.value?.description;
if (
this.footnote.reference.type === 'url' &&
this.footnote.reference.url &&
isTitleAndDescriptionEmpty
) {
this._isLoading$.value = true;
this.std.store
.get(LinkPreviewerService)
@@ -116,6 +142,7 @@ export class FootNotePopup extends SignalWatcher(WithDisposable(LitElement)) {
this._linkPreview$.value = {
favicon: data.icon ?? undefined,
title: data.title ?? undefined,
description: data.description ?? undefined,
};
})
.catch(console.error)