If i have a link i am using in multiple .md files in an mdbook, is there a way to store that link in a global variable and use it in several places in the book, so that if i need to change that link, i only change it in one place.
mdBook supports preprocessors and has a built-in one for including files. You could keep your links in a separate links.md
file, i.e.:
[rust-lang]: https://www.rust-lang.org
[mdbook]: https://rust-lang.github.io/mdBook/index.html
and include it in the markdown files you need them:
[Rust][rust-lang] is a cool programming language and [mdBook][mdbook]
is a great tool for writing documentation!
{{#include links.md}}
1 Like
It's not working for me, also the .md files are all in the same directory. i think something maybe missing.
Sorry, I messed up the syntax in my example. Reference-links are in the form [Rust][rust-lang]
, not [Rust](rust-lang)
. Fixed the example. As to links.md
being in the src
directory, that shouldn't matter if you don't add it to SUMMARY.md
as a chapter.
1 Like