asciidoctor-multipage icon indicating copy to clipboard operation
asciidoctor-multipage copied to clipboard

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

Open cirosantilli opened this issue 3 years ago • 6 comments

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.

cirosantilli avatar Jul 27 '21 16:07 cirosantilli

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?

owenh000 avatar Aug 05 '21 05:08 owenh000

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 :-)

cirosantilli avatar Aug 05 '21 07:08 cirosantilli

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.

owenh000 avatar Sep 07 '21 03:09 owenh000

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.

jesustorresdev avatar Sep 07 '21 09:09 jesustorresdev

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.

cirosantilli avatar Sep 07 '21 09:09 cirosantilli

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

jesustorresdev avatar Sep 07 '21 10:09 jesustorresdev