fix: Fixed issue with Simplenote importer not titling multi-line documents (#2798)
This commit is contained in:
@@ -40,7 +40,7 @@ describe('SimplenoteConverter', () => {
|
||||
expect(result?.[1].uuid).not.toBeNull()
|
||||
expect(result?.[1].content_type).toBe('Note')
|
||||
expect(result?.[1].content.title).toBe('Testing 2')
|
||||
expect(result?.[1].content.text).toBe("This is the 2nd note's content.")
|
||||
expect(result?.[1].content.text).toBe("This is...\r\nthe 2nd note's content.")
|
||||
expect(result?.[1].content.trashed).toBe(false)
|
||||
|
||||
expect(result?.[2].created_at).toBeInstanceOf(Date)
|
||||
|
||||
@@ -15,6 +15,17 @@ type SimplenoteData = {
|
||||
const isSimplenoteEntry = (entry: any): boolean =>
|
||||
entry.id && entry.content != undefined && entry.creationDate && entry.lastModified
|
||||
|
||||
const splitAtFirst = (str: string, delim: string): [string, string] | [] => {
|
||||
const indexOfDelimiter = str.indexOf(delim)
|
||||
const hasDelimiter = indexOfDelimiter > -1
|
||||
if (!hasDelimiter) {
|
||||
return []
|
||||
}
|
||||
const before = str.slice(0, indexOfDelimiter)
|
||||
const after = str.slice(indexOfDelimiter + delim.length)
|
||||
return [before, after]
|
||||
}
|
||||
|
||||
export class SimplenoteConverter implements Converter {
|
||||
constructor() {}
|
||||
|
||||
@@ -58,17 +69,15 @@ export class SimplenoteConverter implements Converter {
|
||||
const createdAtDate = new Date(item.creationDate)
|
||||
const updatedAtDate = new Date(item.lastModified)
|
||||
|
||||
const splitItemContent = item.content.split('\r\n')
|
||||
const hasTitleAndContent = splitItemContent.length === 2
|
||||
const title =
|
||||
hasTitleAndContent && splitItemContent[0].length ? splitItemContent[0] : createdAtDate.toLocaleString()
|
||||
const content = hasTitleAndContent && splitItemContent[1].length ? splitItemContent[1] : item.content
|
||||
const splitContent = splitAtFirst(item.content, '\r\n')
|
||||
const title = splitContent[0] ?? createdAtDate.toLocaleString()
|
||||
const text = splitContent[1] ?? item.content
|
||||
|
||||
return createNote({
|
||||
createdAt: createdAtDate,
|
||||
updatedAt: updatedAtDate,
|
||||
title,
|
||||
text: content,
|
||||
text,
|
||||
trashed,
|
||||
useSuperIfPossible: true,
|
||||
})
|
||||
|
||||
@@ -2,7 +2,7 @@ const data = {
|
||||
activeNotes: [
|
||||
{
|
||||
id: '43349052-4efa-48c2-bdd6-8323124451b1',
|
||||
content: "Testing 2\r\nThis is the 2nd note's content.",
|
||||
content: "Testing 2\r\nThis is...\r\nthe 2nd note's content.",
|
||||
creationDate: '2020-06-08T21:28:43.856Z',
|
||||
lastModified: '2021-04-16T06:21:53.124Z',
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user