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

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

Closed
Tracked by #5
jun6lee opened this issue Feb 28, 2024 · 7 comments · Fixed by #8
Closed
Tracked by #5

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

jun6lee opened this issue Feb 28, 2024 · 7 comments · Fixed by #8
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@jun6lee
Copy link

jun6lee commented Feb 28, 2024

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
Copy link
Owner

@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
Copy link
Author

jun6lee commented Feb 28, 2024

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
Copy link
Author

jun6lee commented Feb 28, 2024

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
Copy link
Author

jun6lee commented Feb 28, 2024

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

@jun6lee
Copy link
Author

jun6lee commented Feb 28, 2024

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
Copy link
Owner

bandantonio commented Feb 28, 2024

@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.

@bandantonio bandantonio changed the title FR: Some more fields FR: Colored annotations and additional fields to pass to the template Feb 28, 2024
@bandantonio bandantonio mentioned this issue Feb 28, 2024
6 tasks
@bandantonio bandantonio added enhancement New feature or request good first issue Good for newcomers labels Feb 28, 2024
@jun6lee
Copy link
Author

jun6lee commented Feb 29, 2024

Works for me, no rush. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
Development

Successfully merging a pull request may close this issue.

2 participants