-
Notifications
You must be signed in to change notification settings - Fork 110
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
Docs: Add a book preprocessor #910
Conversation
Submitted an issue to mdbook: rust-lang/mdBook#2289 |
mdbook issue was closed in favor of rust-lang/mdBook#1424 which is open and not touches for 3 years now, so we shouldn't hope for mdbook fix. Imo the script I wrote should be enough, if it isn't I can write more complicated one that would always work. |
@@ -0,0 +1,34 @@ | |||
import json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: how about adding a shebang? We had it in the previous script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is not supposed to be run manually, so I don't see how shebang helps?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense not to do it.
This is to avoid having to use build_book.py script. 1. Preprocessor is faster and doesn't use disk, as all communication is trough stdio. 2. It doesn't need to be executed explicitly. You can just use `mdbook build docs` and it will create correct documentation. 3. New script is shorter and simpler than old. Script is based on example from https://rust-lang.github.io/mdBook/for_developers/preprocessors.html and uses a function from build_book.py In book.toml the command used is a simple bash script instead of just `python ./sphinx_preprocessor.py` because the command is run in the directory the user executed it in, not the directory that book.toml is in (which is imho a poor design in this case), so in order to be able to run the command both from main dir and from docs dir, such a script locating the preprocessor is necessary.
This script is no longer necessary and just double the work
0b14a4f
to
9b8ef00
Compare
v2
|
This PR adds a preprocessor for the book that removes Sphinx-related sections.
This was previously done by
docs/build_book.py
script, which this PR removes.There are some advantages of new approach:
There is one disadvantage: book must be built either from main directory, or docs directory. If it's built from different location, build will succeed buy Sphinx sections won't be stripped.
This is because of mdbook limitation - PWD of build process is the folder the command is executed in, not the folder in which book.toml is located.
This shouldn't be a problem - I suspect book build is never / very rarely executed from other dir.
If it becomes a problem, it's possible to fix it. The script in bash.sh will need to be modified:
supports
argument - just exit.root
element,cd
to it's value.python ./sphinx_preprocessor.py
with previosuly-read stdin.Pre-review checklist
./docs/source/
.Fixes:
annotations to PR description.