Skip to content

Commit

Permalink
fix: SimplenoteConverter titling multi-line notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorella-dev committed Jan 24, 2024
1 parent 2898497 commit bf61558
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ type SimplenoteData = {
const isSimplenoteEntry = (entry: any): boolean =>
entry.id && entry.content != undefined && entry.creationDate && entry.lastModified

const splitOnce = (str: string, delim: string): string[] => {
const i = str.indexOf(delim)
if (i < 0) {
// no delimeter found, return whole string
return [str]
}
return [str.slice(0, i), str.slice(i + delim.length)]
}

export class SimplenoteConverter implements Converter {
constructor() {}

Expand Down Expand Up @@ -58,7 +67,7 @@ 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 splitItemContent = splitOnce(item.content, '\r\n')
const hasTitleAndContent = splitItemContent.length === 2
const title =
hasTitleAndContent && splitItemContent[0].length ? splitItemContent[0] : createdAtDate.toLocaleString()
Expand Down

0 comments on commit bf61558

Please sign in to comment.