Skip to content

Commit

Permalink
feat: inlude notes in the export
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
OGKevin committed Sep 15, 2022
1 parent ec1f627 commit ce72c43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/database/Highlight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ describe('HighlightService', async function () {
## Chapter Eight: Holden
“I guess I can’t be. How do you prove a negative?” - [[2022-08-05T20:46:41+00:00]]
`
> “I guess I can’t be. How do you prove a negative?” — [[2022-08-05T20:46:41+00:00]]`
)
});

Expand Down Expand Up @@ -85,9 +83,7 @@ describe('HighlightService', async function () {
## Chapter Eight: Holden
“I guess I can’t be. How do you prove a negative?”
`
> “I guess I can’t be. How do you prove a negative?”`
)
});

Expand Down
16 changes: 12 additions & 4 deletions src/database/Highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,29 @@ export class HighlightService {
markdown += `\n\n`
}

return markdown
return markdown.trim()
}

convertToMap(arr: Highlight[], includeDate: boolean, dateFormat: string): Map<bookTitle, Map<chapter, highlight[]>> {
convertToMap(
arr: Highlight[],
includeDate: boolean,
dateFormat: string,
): Map<bookTitle, Map<chapter, highlight[]>> {
const m = new Map<string, Map<string, string[]>>()

arr.forEach(x => {
if (!x.content.bookTitle) {
throw new Error("bookTitle must be set")
}

let text = x.bookmark.text
let text = `> ${x.bookmark.text}`

if (x.bookmark.note) {
text += `\n\n ${x.bookmark.note}`
}

if (includeDate) {
text = text + ` - [[${moment(x.bookmark.dateCreated).format(dateFormat)}]]`
text += ` — [[${moment(x.bookmark.dateCreated).format(dateFormat)}]]`
}

const existingBook = m.get(x.content.bookTitle)
Expand Down

0 comments on commit ce72c43

Please sign in to comment.