tnahs / readstor

A CLI for Apple Books annotations
https://tnahs.github.io/readstor/
Apache License 2.0
16 stars 1 forks source link

Linear sort of location field #6

Open bf4648 opened 1 year ago

bf4648 commented 1 year ago

First of all, I want to say, I love this open-source project! Thank you so much for making it. I do have some recommendations for some enhancements though.

This is currently the way I export my iBook highlights:

  1. I use readstor to export all iBook highlights to a directory (it would be nice to just add an "-id" parameter so that I do not have to export all my iBook highlights):
rm -rf /tmp/workspace
mkdir -p /tmp/workspace
readstor -f -o /tmp/workspace/ export --extract-tags
  1. I then sort by the 'location' field (since I want my highlights sorted linearly):
cat annotations.json | jq 'map(.metadata.location |= {sortkey: [splits("[.:]") | tonumber], value: .}) |
  sort_by(.metadata.location.sortkey) |map(.metadata.location |= .value)' > annotations-sorted.json

I then have to figure out a way to transform this "annotations-sorted.json" file into a markdown format. It would be nice to just add a '--sort' parameter to readstor export or readstor render. It would especially be helpful to add a --sort parameter to the readstor render command since this already exports to markdown format.

tnahs commented 1 year ago

Hey, thanks for feedback! I'm glad you like it! 😄

Exporting a single book is a great idea, I wanted to implement that a while back but I have over a hundred read books in my library so I couldn't think of a clean way of exporting them without cluttering the terminal will tons of text that would have to be scrolled. It could possibly be done with a search term and a confirmation?

$ readstor export --title "art spirit"
-> Found 1 book(s) containing "art spirit":
       The Art Spirit by Robert Henri

-> Export 1 book(s)? [y/N]: _

I'm open to ideas/feedback!

RE: sorting. That's odd because the annotations should be sorted by the location field. It happens in the pre-processor here. And this runs for both export and render. There was an issue submitted a while back where the annotations weren't showing up in proper order but that was most likely the result of the parser.

Could you provide some data showing the incorrect sorting and the correct one. I have unit tests with three books where the sort order is checked and they're passing currently.

tnahs commented 1 year ago

@bf4648 I took a stab at implementing something to export only a sub-set of the annotations. It's on the feat-fitler branch if you'd like to try it out. The documentation for it can be found here. I'll probably be merging it into main sometime soon but won't be releasing it until I implement a few other features.

tnahs commented 1 year ago

The feat-filter branch has been merged. The documentation for filtering can now be found in the dev version.