Skip to content
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

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 this issue Jul 27, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@cirosantilli
Copy link

cirosantilli commented Jul 27, 2021

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
Copy link
Owner

owenh000 commented Aug 5, 2021

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
Copy link
Author

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 owenh000 added the enhancement New feature or request label Aug 8, 2021
@owenh000
Copy link
Owner

owenh000 commented Sep 7, 2021

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 Use --out-file break the links to home #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
Copy link
Contributor

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.

@cirosantilli
Copy link
Author

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants