From 6ff7f6913718b090d31b6b5a03c94750a2de032a Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 30 Jun 2026 02:45:07 +0100 Subject: [PATCH] fix: file import page title --- .../import/services/import.service.ts | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/apps/server/src/integrations/import/services/import.service.ts b/apps/server/src/integrations/import/services/import.service.ts index 1eb10ca80..9d0044040 100644 --- a/apps/server/src/integrations/import/services/import.service.ts +++ b/apps/server/src/integrations/import/services/import.service.ts @@ -102,8 +102,10 @@ export class ImportService { throw new BadRequestException(message); } - const { title, prosemirrorJson } = - this.extractTitleAndRemoveHeading(prosemirrorState); + const { title, prosemirrorJson } = this.extractTitleAndRemoveHeading( + prosemirrorState, + { anyHeadingLevel: true }, + ); const pageTitle = title || fileName; @@ -246,18 +248,29 @@ export class ImportService { return null; } - extractTitleAndRemoveHeading(prosemirrorState: any) { + extractTitleAndRemoveHeading( + prosemirrorState: any, + opts?: { anyHeadingLevel?: boolean }, + ) { let title: string | null = null; const content = prosemirrorState.content ?? []; + const firstNode = content[0]; - if ( - content.length > 0 && - content[0].type === 'heading' && - content[0].attrs?.level === 1 - ) { - title = content[0].content?.[0]?.text ?? null; - content.shift(); + const isTitleHeading = + firstNode?.type === 'heading' && + (opts?.anyHeadingLevel || firstNode.attrs?.level === 1); + + if (isTitleHeading) { + const headingText = (firstNode.content ?? []) + .map((node: any) => node.text ?? '') + .join('') + .trim(); + + if (headingText) { + title = headingText; + content.shift(); + } } // ensure at least one paragraph