-
-
Notifications
You must be signed in to change notification settings - Fork 76
Implement EPUB reader as part of the plugin #141
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
Conversation
It's the black magic that makes the plugin work. Basically, OfflineIframe lets me download a website and display it as if you visited it online, but with the benefit that I can intercept and modify any web request. This is for example used to override API calls and to load the user specified pdfs/epubs. So for example, whenever a hypothesis api call is made, such as when creating a new annotation. I can intercept that call, and make Annotator run its own custom logic that stores the annotation in markdown file instead of calling the hypothes.is servers. |
Yay! :) Looks like this changes somehow fixed a problem when annotation sidebar sometimes shows inside epub view. Also |
@elias-sundqvist I've added hypothesis as an npm package to remove I see that is could be done in two ways:
|
Although importing hypothes.is as an npm package is a neat idea, I'm not sure if it will work very well. You mentioned some of the issues with this approach above, but we may also encounter situations where we need to modify parts of the original hypothes.is code. Therefore I think it might be better to keep using the resources folder. (At least for hypothes.is. Your epub.js solution in this PR will probably be worth merging.) To avoid the manual labor involved in updating hypothes.is version, we could have a hypothes.is fork as a submodule in this repo. That would allow us to make our own custom changes, and whenever a new update is released we can just rebase our changes and run the build script. If you want to try anyways: Option 2 is basically what is being done right now, just that the script comes from the resources folder instead of node_modules. You could maybe make a script in the rollup config to automatically copy the relevant files from node_modules to the resources folder. This would ensure that the hypothesis version is kept in sync with the npm version. |
Is this still WIP, or should I try to merge it? |
It's still in progress :( Each time I turn a page, there is a chance hypothesis will crush with Looks like it happens because hypothesis tries to parse a page before epubjs rendered it, but I didn't figure out why it happens yet. |
Also I researched hypothesis a little. There is a hope we can make all our changes in hypothesis through I didn't dive into it yet, but at first glance it looks like we can expose |
Ok, thanks for the update! I've made some changes locally that I can push tomorrow. One of the changes is the submodule solution I mentioned earlier. |
2566587
to
e82293c
Compare
5a66eae
to
4106622
Compare
@elias-sundqvist Are you sure you pushed all changes to master? I wanted to merge new features to this branch, but I can't even build master locally now :( P.S. Submodule solution looks great 👍🏻 |
Getting the latest release to build yesterday was pretty annoying. I guess I let some minor issues slip by. Regarding the warnings you got:
|
Also, if you are using windows you need to do the thing mentioned in README_DEV.md. |
Yay, it merged and built 🎉 master works great, but on I built by
|
# Conflicts: # src/defineEpubAnnotation.tsx # src/defineGenericAnnotation.tsx # yarn.lock
Huh! I made a build with your merge and it works stranger than I thought 😅 I don't have undefined errors, I guess because I work on macOS. But! With some books I get 403 errors again, and with some everything works fine o_O |
I have exactly the same problem on master. Moby Dick works fine, my books have 403 errors. Also, I see |
One issue in my last commit was that the old call to the epubReader function still remained. If not, maybe you could send me your epub file so that I can test it? |
I don't understand what's going on 😭 Only strange pirated books were working incorrectly yesterday, but all good legally bought books worked fine. A few minutes ago I removed node_modules and package-lock.json, cleaned npm cache, built everything again and... got errors for all books. Even with Moby Dick. |
Strange. Maybe some dependency got updated and caused something to change? Most version numbers in package.json are specified as "a specific version or higher", so the dependencies may have changed when you deleted node modules and reinstalled. I can probably look into this more during the weekend. |
Tried to build it again, master worked fine, ts-reader had problems with all books :( Maybe it would be easier if we have a call and try to debug it together? What do u think? |
I made a new commit that fixes some epub loading issues for me. |
Heeeeey, I'm back! 😄 I figured out why EPUB reader sometimes fails and what is really going on when we see hypothesis inside hypothesis or 403 error. I've found fresh issue about this behavior Epub.js demo does not work Good news is I don't get this problem on latest v1.1035.0 version! That's why send a PR to the fork. With this update we can finally merge this PR ❤️ P.S. I changed how hypothesis-client builds so it would build exactly they do it. |
Looks like this update also fixed Epub annotations dissapear after page turn At lest I don't see this behavior in my vault anymore. |
Sounds great! I'm a bit busy with other things, but I'll check this out and try to merge it sometime this week. |
I've tested it with updated submodule reference. LGTM 👌🏻 |
I'm trying to make resources upgrade easier. This is a proof of concept how we can implement EPUB reader inside the plugin. It uses epubjs as an npm package, part of
reader.js
rewritten with TypeScript.What do you think about this kind of implementation?
Also, I discovered that
defineGenericAnnotation
createsOfflineIframe
and does some kind of proxying, modifying file urls and stuff. What's the point of doing that?