1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00
joplin/packages/lib/services/interop/InteropService_Importer_Md_frontmatter.ts
Henry Heino f938d5f489
Chore: Markdown + fontmatter import and export: Extract frontMatter logic into a separate file (#10508)
Co-authored-by: Laurent Cozic <laurent22@users.noreply.github.com>
2024-05-30 08:40:52 +01:00

30 lines
964 B
TypeScript

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) {
try {
const note = await super.importFile(filePath, parentFolderId);
const { metadata, tags } = parse(note.body);
const updatedNote = { ...note, ...metadata };
const noteItem = await Note.save(updatedNote, { isNew: false, autoTimestamp: false });
const resolvedPath = shim.fsDriver().resolve(filePath);
this.importedNotes[resolvedPath] = noteItem;
for (const tag of tags) { await Tag.addNoteTagByTitle(noteItem.id, tag); }
return noteItem;
} catch (error) {
error.message = `On ${filePath}: ${error.message}`;
throw error;
}
}
}