mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 09:32:06 +10:00
fix page name in notion import
This commit is contained in:
@ -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 });
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user