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].uuid).not.toBeNull()
|
||||||
expect(result?.[1].content_type).toBe('Note')
|
expect(result?.[1].content_type).toBe('Note')
|
||||||
expect(result?.[1].content.title).toBe('Testing 2')
|
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?.[1].content.trashed).toBe(false)
|
||||||
|
|
||||||
expect(result?.[2].created_at).toBeInstanceOf(Date)
|
expect(result?.[2].created_at).toBeInstanceOf(Date)
|
||||||
|
|||||||
@@ -15,6 +15,17 @@ type SimplenoteData = {
|
|||||||
const isSimplenoteEntry = (entry: any): boolean =>
|
const isSimplenoteEntry = (entry: any): boolean =>
|
||||||
entry.id && entry.content != undefined && entry.creationDate && entry.lastModified
|
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 {
|
export class SimplenoteConverter implements Converter {
|
||||||
constructor() {}
|
constructor() {}
|
||||||
|
|
||||||
@@ -58,17 +69,15 @@ export class SimplenoteConverter implements Converter {
|
|||||||
const createdAtDate = new Date(item.creationDate)
|
const createdAtDate = new Date(item.creationDate)
|
||||||
const updatedAtDate = new Date(item.lastModified)
|
const updatedAtDate = new Date(item.lastModified)
|
||||||
|
|
||||||
const splitItemContent = item.content.split('\r\n')
|
const splitContent = splitAtFirst(item.content, '\r\n')
|
||||||
const hasTitleAndContent = splitItemContent.length === 2
|
const title = splitContent[0] ?? createdAtDate.toLocaleString()
|
||||||
const title =
|
const text = splitContent[1] ?? item.content
|
||||||
hasTitleAndContent && splitItemContent[0].length ? splitItemContent[0] : createdAtDate.toLocaleString()
|
|
||||||
const content = hasTitleAndContent && splitItemContent[1].length ? splitItemContent[1] : item.content
|
|
||||||
|
|
||||||
return createNote({
|
return createNote({
|
||||||
createdAt: createdAtDate,
|
createdAt: createdAtDate,
|
||||||
updatedAt: updatedAtDate,
|
updatedAt: updatedAtDate,
|
||||||
title,
|
title,
|
||||||
text: content,
|
text,
|
||||||
trashed,
|
trashed,
|
||||||
useSuperIfPossible: true,
|
useSuperIfPossible: true,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const data = {
|
|||||||
activeNotes: [
|
activeNotes: [
|
||||||
{
|
{
|
||||||
id: '43349052-4efa-48c2-bdd6-8323124451b1',
|
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',
|
creationDate: '2020-06-08T21:28:43.856Z',
|
||||||
lastModified: '2021-04-16T06:21:53.124Z',
|
lastModified: '2021-04-16T06:21:53.124Z',
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user