fix page name in notion import

This commit is contained in:
Philipinho
2025-09-17 00:05:24 +01:00
parent cc5b927de2
commit 5b1a815415
2 changed files with 12 additions and 2 deletions

View File

@ -24,6 +24,7 @@ import { formatImportHtml } from '../utils/import-formatter';
import {
buildAttachmentCandidates,
collectMarkdownAndHtmlFiles,
stripNotionID,
} from '../utils/import.utils';
import { executeTx } from '@docmost/db/utils';
import { BacklinkRepo } from '@docmost/db/repos/backlink/backlink.repo';
@ -163,7 +164,7 @@ export class FileImportTaskService {
pagesMap.set(relPath, {
id: v7(),
slugId: generateSlugId(),
name: path.basename(relPath, ext),
name: stripNotionID(path.basename(relPath, ext)),
content: '',
parentPageId: null,
fileExtension: ext,
@ -272,7 +273,10 @@ export class FileImportTaskService {
// Find children of current page
for (const [childFilePath, childPage] of pagesMap.entries()) {
if (childPage.parentPageId === currentPage.id && !pageLevel.has(childFilePath)) {
if (
childPage.parentPageId === currentPage.id &&
!pageLevel.has(childFilePath)
) {
pageLevel.set(childFilePath, level + 1);
queue.push({ filePath: childFilePath, level: level + 1 });
}

View File

@ -64,3 +64,9 @@ export async function collectMarkdownAndHtmlFiles(
await walk(dir);
return results;
}
export function stripNotionID(fileName: string): string {
// Handle optional separator (space or dash) + 32 alphanumeric chars at end
const notionIdPattern = /[ -]?[a-z0-9]{32}$/i;
return fileName.replace(notionIdPattern, '').trim();
}