bandantonio / obsidian-apple-books-highlights-plugin

Import highlights and notes from your Apple Books to Obsidian
https://obsidian.md/plugins?id=apple-books-import-highlights
MIT License
44 stars 2 forks source link

FR: Colored annotations and additional fields to pass to the template #2

Closed jun6lee closed 7 months ago

jun6lee commented 7 months ago

Have raised a PR for the same.

Aiming for something like this:

image

Will share a suggested template for anyone looking to do the same, once we have the fields.

bandantonio commented 7 months ago

@jun6lee Thank you for your interest in the plugin. I briefly reviewed your PR, lgtm but as I can see, the annotationStyle is unused within the template. Furthermore, you said that

Will share a suggested template for anyone looking to do the same, once we have the fields.

Would it make more sense for you to update the PR to introduce colors for the highlights? Without it, the PR looks a bit unfinished. Ultimately, these changes can then be reflected in documentation as "advanced" template customization for those who want (or need) color differentiation in their book highlights. What do you think?

Thanks

jun6lee commented 7 months ago

Sure thing.

I was looking to do something like this which I was using on another plugin:

---
book: {{library.ZSORTTITLE}}
author: {{library.ZAUTHOR}}
language: {{library.ZLANGUAGE}}
last_opened: {{dateFormat library.ZLASTOPENDATE "YYYY/MM/DD HH:mm:ss" }}
tags:
- highlights/iBooks
---
# ๐Ÿ“” {{library.ZSORTTITLE}}
---
{{#if library.ZBOOKDESCRIPTION}}

## ๐Ÿงพ Description
---
    {{{library.ZBOOKDESCRIPTION}}}
{{/if}}

### ๐Ÿ” Highlights
---

{{#group annotation by="ZFUTUREPROOFING5"}}
#### ๐Ÿ“š{{value}}
---

{{#each items}}
{{#if ZANNOTATIONSELECTEDTEXT}}
{{#is ZANNOTATIONSTYLE 5}}
- ๐ŸŽฏ <mark style="background: #C4B3D9;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 4}}
- ๐ŸŽฏ <mark style="background: #E6A5AB;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 3}}
- ๐ŸŽฏ <mark style="background: #EDD570;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 2}}
- ๐ŸŽฏ <mark style="background: #A8BADE;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 1}}
- ๐ŸŽฏ <mark style="background: #B0D17F;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{#is ZANNOTATIONSTYLE 0}}
- ๐ŸŽฏ <mark style="background: #FFD9B3;">{{ZANNOTATIONSELECTEDTEXT}}</mark>
{{/is}}
{{/if}}
{{#if ZANNOTATIONNOTE}}
        - โœ๏ธ {{ZANNOTATIONNOTE}}
{{/if}}
<sub>Highlighted: {{dateFormat ZANNOTATIONCREATIONDATE "YYYY/MM/DD HH:mm:ss" }}</sub>
---
{{/each}}
{{/group}}
Source::  [Apple Books Link](ibooks://assetid/{{library.ZASSETID}})
jun6lee commented 7 months ago

If you could push what I've added so far, I can test this and share an advanced_template file in a day or two.

Would that work for you?

jun6lee commented 7 months ago

I also think I may need to add an apple date converter proc, which I have on standby.

jun6lee commented 7 months ago

const APPLE_EPOCH_START = new Date("2001-01-01").getTime(); --- been able to dig out that Apple does a weird thing with EPOCH timestamps, so start with this.

and feed the ZANNOTATIONMODIFICATIONDATE or ZANNOTATIONCREATIONDATE something like this:

      modifiedAt: convertAppleTime(r.modifiedAt),
      createdAt: convertAppleTime(r.createdAt),

using

function convertAppleTime(appleTime) {
  return new Date(APPLE_EPOCH_START + appleTime * 1000).getTime();
}
bandantonio commented 7 months ago

@jun6lee Thanks for sharing.

I was looking to do something like this which I was using on another plugin:

I see no problems integrating colors into the template and provide it as an example of advanced customization. You also saved me time for testing the mapping of ZANNOTATIONSTYLE numbers to their respective colors ๐Ÿ˜„

If you could push what I've added so far, I can test this and share an advanced_template file in a day or two.

I'm now in the middle of releasing a new version and will get back to the colored template in a day or two as well, so basically I can pick up your PR #1 where you left off and add all the necessary changes, if you don't mind.

As for the time, it looks doable, but it's definitely a separate improvement. I would like to check it on my side.

jun6lee commented 7 months ago

Works for me, no rush. :)