mirror of
https://github.com/docmost/docmost.git
synced 2026-08-30 02:25:01 +08:00
fix: cleanup title
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
|||||||
computeLocalPath,
|
computeLocalPath,
|
||||||
getExportExtension,
|
getExportExtension,
|
||||||
getPageTitle,
|
getPageTitle,
|
||||||
|
getSafePageTitle,
|
||||||
PageExportTree,
|
PageExportTree,
|
||||||
replaceInternalLinks,
|
replaceInternalLinks,
|
||||||
updateAttachmentUrlsToLocalPaths,
|
updateAttachmentUrlsToLocalPaths,
|
||||||
@@ -314,7 +315,7 @@ export class ExportService {
|
|||||||
updateAttachmentUrlsToLocalPaths(updatedJsonContent);
|
updateAttachmentUrlsToLocalPaths(updatedJsonContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const pageTitle = getPageTitle(page.title);
|
const pageTitle = getSafePageTitle(page.title);
|
||||||
const pageExportContent = await this.exportPage(format, {
|
const pageExportContent = await this.exportPage(format, {
|
||||||
...page,
|
...page,
|
||||||
content: updatedJsonContent,
|
content: updatedJsonContent,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { validate as isValidUUID } from 'uuid';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { Page } from '@docmost/db/types/entity.types';
|
import { Page } from '@docmost/db/types/entity.types';
|
||||||
import { isAttachmentNode } from '../../common/helpers/prosemirror/utils';
|
import { isAttachmentNode } from '../../common/helpers/prosemirror/utils';
|
||||||
|
import { sanitizeFileName } from '../../common/helpers';
|
||||||
|
|
||||||
export type PageExportTree = Record<string, Page[]>;
|
export type PageExportTree = Record<string, Page[]>;
|
||||||
|
|
||||||
@@ -27,6 +28,13 @@ export function getPageTitle(title: string) {
|
|||||||
return title ? title : 'untitled';
|
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) {
|
export function updateAttachmentUrlsToLocalPaths(prosemirrorJson: any) {
|
||||||
const doc = jsonToNode(prosemirrorJson);
|
const doc = jsonToNode(prosemirrorJson);
|
||||||
if (!doc) return null;
|
if (!doc) return null;
|
||||||
@@ -167,7 +175,7 @@ export function computeLocalPath(
|
|||||||
const children = tree[parentPageId] || [];
|
const children = tree[parentPageId] || [];
|
||||||
|
|
||||||
for (const page of children) {
|
for (const page of children) {
|
||||||
const title = encodeURIComponent(getPageTitle(page.title));
|
const title = encodeURIComponent(getSafePageTitle(page.title));
|
||||||
const localPath = `${currentPath}${title}`;
|
const localPath = `${currentPath}${title}`;
|
||||||
slugIdToPath[page.slugId] = `${localPath}${getExportExtension(format)}`;
|
slugIdToPath[page.slugId] = `${localPath}${getExportExtension(format)}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user