owenh000 / asciidoctor-multipage

A configurable multipage HTML converter for Asciidoctor
https://owenh.net/asciidoctor-multipage
MIT License
58 stars 23 forks source link

Add option to generate ToC child links without the .html extension for servers like GitHub pages that automatically remove those extension #21

Open cirosantilli opened 3 years ago

cirosantilli commented 3 years ago

Sed hack: https://github.com/cirosantilli/china-dictatorship/blob/0cfdaf75c5a6032c9ad4525e827e84b9d680b081/push#L25

Gemfile

source 'https://rubygems.org'

gem 'asciidoctor', '2.0.11'
gem 'asciidoctor-multipage', '0.0.12 '

tmp.adoc

= h1

== h2

Build:

bundle exec asciidoctor -b multipage_html5 -D out/tmp -r asciidoctor-multipage tmp.adoc

Default outcome: out/tmp/tmp.html contains a link to _h2.html, which works fine in the local filesystem.

However, when pushing that output e.g. to GitHub pages, I would like the link instead to be just to _h2 instead of _h2.html.

Both _h2 and _h2.html work on that server, but the .html one is just uglier.

Maybe we can have a:

-a html_ext=0

to remove it.

owenh000 commented 3 years ago

Hi @cirosantilli, thanks for the suggestion. However, it seems like this is more a problem of URL rewriting than HTML generation (specific to GitHub Pages).

Will GitHub Pages will automatically redirect from /_h2.html to /_h2?

# Generate output
asciidoctor -r asciidoctor-multipage -b multipage_html5 -D out/tmp tmp.adoc

# Only needed if GitHub Pages does *not* redirect from `/_h2.html` to `/_h2`
sed -E -i 's/(<a href="[^"]+).html">/\1">/g' out/tmp/*.html

# Remove .html extensions
rename 's/\.html$//' out/tmp/*.html

Does that help?

cirosantilli commented 3 years ago

Hi @cirosantilli, thanks for the suggestion. However, it seems like this is more a problem of URL rewriting than HTML generation (specific to GitHub Pages).

Will GitHub Pages will automatically redirect from /_h2.html to /_h2?

It does no redirectt, e.g.: https://cirosantilli.com/china-dictatorship/about.html

# Generate output
asciidoctor -r asciidoctor-multipage -b multipage_html5 -D out/tmp tmp.adoc

# Only needed if GitHub Pages does *not* redirect from `/_h2.html` to `/_h2`
sed -E -i 's/(<a href="[^"]+).html">/\1">/g' out/tmp/*.html

# Remove .html extensions
rename 's/\.html$//' out/tmp/*.html

Does that help?

Sure, but haxx :-)

owenh000 commented 3 years ago

There is some related discussion about this in issue #26.

The asciidoctor-multipage extension handles writing of all files excluding the main root page, so it seems like it would be trivial to remove the .html extension from those output files. However, because Asciidoctor handles writing of the main output file it may not be possible to change the filename used for that file.

However, it may be possible to implement this as follows:

  1. Support use of the Asciidoctor --out-file option as discussed in issue #26.
  2. Add a multipage-omit-extensions document attribute for omitting the .html extension from non-root output files.
  3. Execute Asciidoctor with the --out-file option set to an output path with no .html extension.
jesustorresdev commented 3 years ago

May be it's related to jekyll and how jekyll treats files with underscore?

There is here a similar issue in other project:

https://github.com/mpetrovich/stylemark/issues/65

The suggested solution is to add .nojekyll to the root directory. It's what I did in my Github pages.

cirosantilli commented 3 years ago

May be it's related to jekyll and how jekyll treats files with underscore?

There is here a similar issue in other project:

mpetrovich/stylemark#65

The suggested solution is to add .nojekyll to the root directory. It's what I did in my Github pages.

I don't think it has anything to do with Jekyll. Basically, asciidoctor-multipage produces <a href="child-id.html"> and I want it to produce <a href="child-id"> instead. Both child-id.html and child-id work, but I want the one without .html which looks nicer.

jesustorresdev commented 3 years ago

Sorry. I think you have a problem with underscore html files (I did), but I already saw what you think is uglier.