Last active
May 14, 2024 12:31
-
-
Save kyurikotpq/56c394193618070ac3ba9db489e054ec to your computer and use it in GitHub Desktop.
Render ebook highlights (exported from Libby app as JSON) using Obsidian's DataviewJS plugin.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```dataviewjs | |
// Change this to where your JSON file resides | |
const FILENAME = "book-highlights/libbyjourney-9818863-million-dollar-weekend.json"; | |
// Load and parse the JSON | |
const JSON_STR = await dv.io.load(FILENAME); | |
const JSON_OBJ = JSON.parse(JSON_STR); | |
const { readingJourney, circulation, highlights } = JSON_OBJ; | |
// Cover Image, Title, Author | |
dv.paragraph(`![${readingJourney.cover.title}|200](${readingJourney.cover.url})`) | |
dv.header(1, `${readingJourney.cover.title} by ${readingJourney.author}`) | |
// Summary of Reading Journey | |
const timeline = circulation.map(a => `- ${new Date(a.timestamp).toDateString()} / ${a.activity} ${a.details || ''}`).join('\n'); | |
dv.paragraph(`${timeline}\n\n`); | |
// Highlights | |
dv.header(2, "Highlights"); | |
// Organize highlights by their position in the book | |
highlights.sort((prev, next) => (prev.percent < next.percent) ? -1 : 1); | |
// Split highlights by chapters | |
let prevChapterTitle = highlights[0].chapter; | |
dv.header(3, prevChapterTitle) | |
highlights.forEach(h => { | |
if (h.chapter != prevChapterTitle) { | |
dv.header(3, h.chapter); | |
prevChapterTitle = h.chapter; | |
} | |
// Format highlights as code blocks (easier to copy) | |
dv.paragraph("```\n" + h.quote.replace("\n\n", "") + "\n```"); | |
// ALTERNATIVELY: Format highlights as bullet points | |
// dv.paragraph(`- ${h.quote.replace("\n\n", "")}`); | |
}) | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment