mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
fix(core): load fonts from selfhost url (#5789)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import type { BlockSpec } from '@blocksuite/block-std';
|
||||
import type { BlockServiceOptions, BlockSpec } from '@blocksuite/block-std';
|
||||
import type { ParagraphService } from '@blocksuite/blocks';
|
||||
import {
|
||||
AttachmentService,
|
||||
DocEditorBlockSpecs,
|
||||
EdgelessEditorBlockSpecs,
|
||||
PageService,
|
||||
} from '@blocksuite/blocks';
|
||||
import bytes from 'bytes';
|
||||
import { html, unsafeStatic } from 'lit/static-html.js';
|
||||
@@ -17,6 +18,26 @@ class CustomAttachmentService extends AttachmentService {
|
||||
}
|
||||
}
|
||||
|
||||
class CustomPageService extends PageService {
|
||||
constructor(opt: BlockServiceOptions) {
|
||||
super(opt);
|
||||
const officialDomains = new Set(['affine.pro', 'affine.fail']);
|
||||
const load = this.fontLoader.load.bind(this.fontLoader);
|
||||
this.fontLoader.load = function (fonts) {
|
||||
if (!officialDomains.has(window.location.host)) {
|
||||
return load(
|
||||
fonts.map(f => ({
|
||||
...f,
|
||||
// self-hosted fonts are served from /assets
|
||||
url: '/assets' + new URL(f.url).pathname.split('/').pop(),
|
||||
}))
|
||||
);
|
||||
}
|
||||
return load(fonts);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type AffineReference = HTMLElementTagNameMap['affine-reference'];
|
||||
type PageReferenceRenderer = (reference: AffineReference) => React.ReactElement;
|
||||
|
||||
@@ -76,6 +97,12 @@ export const docModeSpecs = DocEditorBlockSpecs.map(spec => {
|
||||
service: CustomAttachmentService,
|
||||
};
|
||||
}
|
||||
if (spec.schema.model.flavour === 'affine:page') {
|
||||
return {
|
||||
...spec,
|
||||
service: CustomPageService,
|
||||
};
|
||||
}
|
||||
return spec;
|
||||
});
|
||||
export const edgelessModeSpecs = EdgelessEditorBlockSpecs.map(spec => {
|
||||
|
||||
Reference in New Issue
Block a user