Skip to content

Commit

Permalink
fix: Fixed issue with Simplenote importer not titling multi-line docu…
Browse files Browse the repository at this point in the history
…ments (#2798)
  • Loading branch information
mmorella-dev committed Jan 27, 2024
1 parent 853fab5 commit c858e51
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down

0 comments on commit c858e51

Please sign in to comment.