mirror of
https://github.com/docmost/docmost.git
synced 2026-07-11 19:04:46 +10:00
fix: cleanup title
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)}`;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user