asciidoctor / asciidoctor-extensions-lab

A lab for testing and demonstrating Asciidoctor extensions. Please do not use this code in production. If you want to use one of these extensions in your application, create a new project, import the code, and distribute it as a RubyGem. You can then request to make it a top-level project under the Asciidoctor organization.
Other
104 stars 101 forks source link

feat: navigation icons for toc sidebar #67

Closed nicorikken closed 2 years ago

nicorikken commented 8 years ago

Icons can be invoked using nav-home, nav-up, nav-down, nav-prev and nav-next. It does require support for Awesomefont which can be triggered using the icons:font attribute.

I'm eager to receive feedback on this, as I guess it can benefit from better checking and Ruby coding style in general. It basically does what it's supposed to do, but can probably be improved.

My main inspiration for the navigation icons was the Debian Maintainers guide

nicorikken commented 8 years ago

Some ideas for improvement:

nicorikken commented 8 years ago

Apparently it is ok to add css, as I see in the view-result processor. Also I'll try using the flexbox CSS for distributing the available icons evenly across the width of the sidebar.

nicorikken commented 8 years ago

I just created an improvement on the previous code using some CSS. Now the icons are spread evenly across the width of the TOC, also rendering neatly for smaller screen-sizes. Normal page:

screen shot 2016-07-10 at 10 13 28

Smartphone size:

screen shot 2016-07-10 at 10 13 13
nicorikken commented 8 years ago

@mojavelinux Am I able to trigger the intelligent link handling in Asciidoctor from the postprocessor? Such that <<index.adoc#,index>> and link:http://asciidoctor.org/[asciidoctor homepage] in the attributes are resolved to URL's? Otherwise I'll have to do duplicate work.

nicorikken commented 8 years ago

I did some refactoring on the extension, and I drew a lot of inspiration from the talk around PR #7

Normal page:

screen shot 2016-07-10 at 19 53 07

Smartphone:

screen shot 2016-07-10 at 19 52 50

Discussion Ideally I'd like to have the links defined globally on the page by default, and have them locally defined if needed. So if attributes are set globally, there is no real need to set any info on rendering, I can just trigger navicons, so something like [navicons] would do, but this doesn't seem to be valid Asciidoctor syntax. It needs some source like below, even though no clear data-uri exsists in this case. (see #7)

chart::<data-uri>[<type>,<x-label>,<y-label>,<width>,<height>]

chart[<type>,<x-label>,<y-label>,<width>,<height>]
....
January,February,March,April,May,June,July
28,48,40,19,86,27,90
65,59,80,81,56,55,40
....

TODO

nicorikken commented 8 years ago

Just found an additional explicit usecase when reading about GNU Make which lists navigational icons for each section, even though it is a single page. The links to contents and index are particularly interesting. I could add explicit support for it.

nicorikken commented 8 years ago

Regarding manual placement, the manual placement of the table of contents using toc::[] is a good exemplary equivalent syntax. Then something like nav::[] could be sufficient.

ggrossetie commented 8 years ago

Nice work @nicorikken !

Regarding manual placement, the manual placement of the table of contents using toc::[] is a good exemplary equivalent syntax. Then something like nav::[] could be sufficient.

Indeed I think you should mimic TOC placement instead of using a block macro. I think it doesn't make any sense to have multiple navigation bars on one document ?

nicorikken commented 8 years ago

Thanks! Still need to finish and polish it though. One could make the case for navigations inside a single file, like in the GNU Make manual I linked earlier. However, having such icons in place enables a document to be split up in multiple pages. So sticking with file-global settings and the option of manual placement should suffice.

ggrossetie commented 8 years ago

One could make the case for navigations inside a single file, like in the GNU Make manual I linked earlier.

Yep but I think this should be another extension section-nav ? Otherwise you may end up handling too much edge cases inside a single extension.

ggrossetie commented 8 years ago

I did a quick review to better understand where you are heading. I'm just throwing ideas, feel free to do differently :wink:

nicorikken commented 8 years ago

Thanks for all the comments, I'll take them into account when I do my next session of hacking on this code.

nicorikken commented 8 years ago

@Mogztter Your comments triggered me to get coding this morning. The implementation is now much cleaner, incorporates manual placement, and the cross-references are now properly supported (using &lt; and &gt; instead of < and > in regexes).

Improvements I would still like to make:

mojavelinux commented 10 months ago

I think this is extension is too complex for the lab, which is meant to serve as a reference for getting started with extensions. If someone is interested in the functionality this extension provides, I would encourage them to set this up as a separate extension project and publish it.