How to embed absolute links when serving from a subdirectory in a domain?
Say, I have a link going to another page and I need it starting from the root:
[some url link](/path/to/page.md)
This gets compiled to a link to the correct page:
<a href="/path/to/page.html">some url link</a>
However, this doesn't work if I'm serving from a subdirectory:
http://example.com/my_book/path/to/page.html
The absolute url will skip over the subdirectory my_book and point to http://example.com/path/to/page.html which doesn't exist.
How can we specify that links should go to an absolute path based upon the root location of the book?
Right now, I solved it by using https://github.com/avitex/mdbook-tera which is a pre-processor.
I added a variable in front of every URL link. The variable maps to the subdirectory name.
I am hoping for a simpler, not so hacky solution though.
see https://github.com/rust-lang/mdBook/issues/1764
Right now, I solved it by using https://github.com/avitex/mdbook-tera which is a pre-processor.
I added a variable in front of every URL link. The variable maps to the subdirectory name.
I am hoping for a simpler, not so hacky solution though.
@schungx Would you mind sharing exactly how you solved it in this way?
@schungx Would you mind sharing exactly how you solved it in this way?
Oops, sorry, just realize that I have not responded to this. So, this is how I did it (one year too late):
-
Install
mdbook-tera -
Define a Tera variable in a context file, e.g.
root_url = /my/book -
In book pages, for links, use
{{ root_url }}/path/to/doc.md -
Bob's your uncle
You need this unless your root is really the book's root. In many sites it isn't.
Seeing that version 0.5 is coming out... I wonder if there is now a solution to this issue?