Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Fix Simplenote importer not titling multi-line documents #2798

Merged
merged 2 commits into from Jan 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
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