-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Javascript API for toc #1237
Javascript API for toc #1237
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1237 +/- ##
==========================================
+ Coverage 68.80% 68.84% +0.03%
==========================================
Files 25 25
Lines 2199 2208 +9
Branches 420 421 +1
==========================================
+ Hits 1513 1520 +7
- Misses 514 517 +3
+ Partials 172 171 -1
Continue to review full report at Codecov.
|
@Jaifroid @automactic @macgills This is the really early iteration to create a JS API. I have chosen the TOC API because it is I believe the most simple thing. I would like to have you to join this journey so we secure what is done here is helpful/usable to Kiwix reader' devevelopers. The first thing I would like you to secure with @bakshiutkarsha is that the implementation is correct and work at least as your one in your respective readers. |
@kelson42 @bakshiutkarsha Happy to troubleshoot/test from the Kiwix JS perspective. Just looking at the code, as this is intended to run in any supported browser/environment, the code should be re-cast as ES5. We need to support IE11 as a minimum, and 'async' won't work in older browsers. I don't know the API spec, but as far as I can see, none of the code inside the async blocks actually runs asynchronously, so there is nothing to wait for. I think the same code can simply be written as a set of functions. [Adding @mossroy to this thread.] |
@Jaifroid we can define what ever we need as API, this is the coal of the PR discussion around TOC. Maybe you have your own piece of code in Kiwix-js you would like to advert here? |
OK, thanks! In that case, we'll also need to polyfill Element.closest(). |
Polyfill here: https://github.com/jonathantneal/closest Also, IE11 can't use forEach on a querySelector node list. Instead you have to use the |
Finally, I notice this uses |
I will say nothing on the js code, I'm not a expert here. (Except that I'm stuck in a js world where To be complete here, do we agree that :
I have few questions : Should we use a js method to change the location ? If a client can get the whole toc of the archive, it could change the location of the page directly (a probably better than relying on a embedded js). The following script has the advantage to be article independent, the TOC itself is inferred from the html content. But we could also standardize the html content to allow the client to found the TOC itself (not sure it is a good idea, but for brainstorming purpose, it is good to have it in mind). It worth it to compare this with |
Yes, this is the idea as the reader has control over the HTML widget/DOM. The operation should be as easy as possible and we will need a solution at libzim/libkiwix to make the retrieval of this JS API code as easy/clean as possible.
Yes, anything after retrieval of JS API code is full in hand of ZIM reader.
I have not clear opinion on that.
This is what happens for the moment. The JS API allows to:
This is how EPUB works. The JS API is a more flexible/leaner approach to achieve the same result. |
Yes, I agree. I would put the js code in the zim file itself. And make article add it in the "normal" way.
How it is better ? |
|
The JS API is in each/the ZIM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see comments (mostly from @Jaifroid)
If it is js that generate the dict :
Which one ? We are currently defining it. We could define that a dict have to be present.
The js could generate the dict at runtime (read time).
If this is to the js to generate it, no more work for the scraper, at least not more than add a js with a specific api in the zim file wi
Same if it is the js creating the dict. |
I agree generating the TOC dynamically from the article headings, rather than having it as an extra json item is the simplest generic approach that doesn't require any extra storage. Apart from that, I think it's important to decide now how the script gets attached to the page. Since MWoffliner is written in Typescript, I believe, you probably have a toolchain that compiles TS down to JS for Node. A similar toolchain can be used to compile ES6 down to ES5 and below, and automatically bundle the needed polyfills for all API scripts as a single optimized JS file - e.g. Is this what's intended? It would seem the most sensible approach, as it will support even IE11. (It would be great not to have to bundle jQuery in the ZIM as at present! It's redundant with babel.) |
7f36ac3
to
4b9cfa8
Compare
@bakshiutkarsha There is many things which I would like to change with your PR:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need changes
This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions. |
4e59f45
to
72b6273
Compare
This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions. |
@kelson42 @bakshiutkarsha Is there any way we can get this finished? We were very very close! |
This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions. |
@Jaifroid I hope so soon. This is part of 1.12 milestone (so in November) with a few other ticket. Hopefully @MananJethwani will be able to help here to complete. |
I have rebased the project on git |
This pull request has been automatically marked as stale because it has not had recent activity. It will be now be reviewed manually. Thank you for your contributions. |
should resolve #596