1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-18 09:35:20 +02:00
joplin/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts

30 lines
964 B
TypeScript
Raw Normal View History

import InteropService_Importer_Md from './InteropService_Importer_Md';
import Note from '../../models/Note';
import Tag from '../../models/Tag';
import shim from '../../shim';
import { parse } from '../../utils/frontMatter';
export default class InteropService_Importer_Md_frontmatter extends InteropService_Importer_Md {
public async importFile(filePath: string, parentFolderId: string) {
2023-12-13 21:24:58 +02:00
try {
const note = await super.importFile(filePath, parentFolderId);
const { metadata, tags } = parse(note.body);
2023-12-13 21:24:58 +02:00
const updatedNote = { ...note, ...metadata };
2023-12-13 21:24:58 +02:00
const noteItem = await Note.save(updatedNote, { isNew: false, autoTimestamp: false });
2023-12-13 21:24:58 +02:00
const resolvedPath = shim.fsDriver().resolve(filePath);
this.importedNotes[resolvedPath] = noteItem;
2023-12-13 21:24:58 +02:00
for (const tag of tags) { await Tag.addNoteTagByTitle(noteItem.id, tag); }
2023-12-13 21:24:58 +02:00
return noteItem;
} catch (error) {
error.message = `On ${filePath}: ${error.message}`;
throw error;
}
}
}