fix(core): fix doc url parsing with custom domain names (#10444)

Closes: [AF-2279](https://affine-pro.slack.com/archives/C06CTBH5L4R/p1740552397245649?thread_ts=1740547457.278239&cid=C06CTBH5L4R)
This commit is contained in:
fundon
2025-02-26 07:35:25 +00:00
parent e38e59d4e5
commit 866b096304
2 changed files with 7 additions and 4 deletions

View File

@@ -11,9 +11,11 @@ import type { FrameworkProvider } from '@toeverything/infra';
function patchParseDocUrlExtension(framework: FrameworkProvider) {
const workspaceService = framework.get(WorkspaceService);
const workspaceServerService = framework.get(WorkspaceServerService);
const baseUrl = workspaceServerService.server?.baseUrl ?? location.origin;
const ParseDocUrl = ParseDocUrlExtension({
parseDocUrl(url) {
const info = resolveLinkToDoc(url);
const info = resolveLinkToDoc(url, baseUrl);
if (!info || info.workspaceId !== workspaceService.workspace.id) return;
delete info.refreshKey;
@@ -28,13 +30,14 @@ function patchParseDocUrlExtension(framework: FrameworkProvider) {
function patchGenerateDocUrlExtension(framework: FrameworkProvider) {
const workspaceService = framework.get(WorkspaceService);
const workspaceServerService = framework.get(WorkspaceServerService);
const baseUrl = workspaceServerService.server?.baseUrl ?? location.origin;
const GenerateDocUrl = GenerateDocUrlExtension({
generateDocUrl(pageId: string, params?: ReferenceParams) {
return generateUrl({
...params,
pageId,
workspaceId: workspaceService.workspace.id,
baseUrl: workspaceServerService.server?.baseUrl ?? location.origin,
baseUrl,
});
},
});

View File

@@ -102,8 +102,8 @@ const isRouteModulePath = (
): path is (typeof routeModulePaths)[number] =>
routeModulePaths.includes(path as any);
export const resolveLinkToDoc = (href: string) => {
const meta = resolveRouteLinkMeta(href);
export const resolveLinkToDoc = (href: string, baseUrl?: string) => {
const meta = resolveRouteLinkMeta(href, baseUrl);
if (!meta || meta.moduleName !== 'doc') return null;
const params = preprocessParams(