fix: cleanup title

This commit is contained in:
Philipinho
2026-06-27 00:40:19 +01:00
parent 4aa4feb41f
commit 303b6a048f
2 changed files with 11 additions and 2 deletions
@@ -16,6 +16,7 @@ import {
computeLocalPath,
getExportExtension,
getPageTitle,
getSafePageTitle,
PageExportTree,
replaceInternalLinks,
updateAttachmentUrlsToLocalPaths,
@@ -314,7 +315,7 @@ export class ExportService {
updateAttachmentUrlsToLocalPaths(updatedJsonContent);
}
const pageTitle = getPageTitle(page.title);
const pageTitle = getSafePageTitle(page.title);
const pageExportContent = await this.exportPage(format, {
...page,
content: updatedJsonContent,
+9 -1
View File
@@ -6,6 +6,7 @@ import { validate as isValidUUID } from 'uuid';
import * as path from 'path';
import { Page } from '@docmost/db/types/entity.types';
import { isAttachmentNode } from '../../common/helpers/prosemirror/utils';
import { sanitizeFileName } from '../../common/helpers';
export type PageExportTree = Record<string, Page[]>;
@@ -27,6 +28,13 @@ export function getPageTitle(title: string) {
return title ? title : 'untitled';
}
export function getSafePageTitle(title: string): string {
const sanitized = sanitizeFileName(getPageTitle(title), {
preserveSpaces: true,
});
return sanitized || 'untitled';
}
export function updateAttachmentUrlsToLocalPaths(prosemirrorJson: any) {
const doc = jsonToNode(prosemirrorJson);
if (!doc) return null;
@@ -167,7 +175,7 @@ export function computeLocalPath(
const children = tree[parentPageId] || [];
for (const page of children) {
const title = encodeURIComponent(getPageTitle(page.title));
const title = encodeURIComponent(getSafePageTitle(page.title));
const localPath = `${currentPath}${title}`;
slugIdToPath[page.slugId] = `${localPath}${getExportExtension(format)}`;