File tree Expand file tree Collapse file tree 6 files changed +54
-76
lines changed Expand file tree Collapse file tree 6 files changed +54
-76
lines changed Original file line number Diff line number Diff line change 3333 run : cargo build --verbose --examples
3434 - name : Build the book
3535 run : mdbook build docs
36- - name : Build the book using the script
37- run : python3 docs/build_book.py
3836 - name : Run book tests
3937 run : mdbook test -L target/debug/deps docs
Original file line number Diff line number Diff line change @@ -72,17 +72,20 @@ But they are removed when building the book
7272cargo install mdbook
7373` ` `
7474
75- Build the book (simple method, contains ` Sphinx` artifacts):
75+ Book build process uses preprocessor to remove Sphinx artifacts.
76+ Due to limitation of mdbook, it can only be built either from main directory,
77+ using ` mdbook X docs` or from ` docs` directory, using ` mdbook X` , where
78+ ` X` is mdbook command such as ` build` / ` serve` / ` test` etc.
79+
80+ If the book is built from another directory (e.g. scylla, using ` mdbook build ../docs` ),
81+ preprocessor won' t be found, so the result will contain Sphinx artifacts.
82+
83+ Build the book.
7684```bash
7785mdbook build docs
7886# HTML will be in docs/book
7987```
8088
81- To build the release version use a script which automatically removes ` Sphinx` chunks:
82- ` ` ` bash
83- python3 docs/build_book.py
84- # HTML will be in docs/book/scriptbuild/book
85- ` ` `
8689
8790Or serve it on a local http server (automatically refreshes on changes)
8891```bash
Original file line number Diff line number Diff line change 4646
4747.PHONY : docs
4848docs :
49- ./ docs/build_book.py
49+ mdbook build docs
5050
5151.PHONY : up
5252up :
Original file line number Diff line number Diff line change @@ -11,4 +11,13 @@ edition = "2021"
1111
1212[output .html ]
1313default-theme = " ayu"
14- git-repository-url = " https://github.com/scylladb/scylla-rust-driver"
14+ git-repository-url = " https://github.com/scylladb/scylla-rust-driver"
15+
16+ [preprocessor .sphinx ]
17+ command = ''' bash -c '
18+ if test -f "./docs/sphinx_preprocessor.py"; then
19+ python ./docs/sphinx_preprocessor.py "$@"
20+ else
21+ python ./sphinx_preprocessor.py "$@"
22+ fi' run_preprocessor
23+ '''
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import json
2+ import sys
3+
4+ def remove_sphinx_markdown (md_file_text ):
5+ text_split = md_file_text .split ("```eval_rst" )
6+
7+ result = text_split [0 ]
8+
9+ for i in range (1 , len (text_split )):
10+ cur_chunk = text_split [i ]
11+ result += cur_chunk [cur_chunk .find ("```" ) + 3 :]
12+
13+ return result
14+
15+ def process_section (section ):
16+ if 'Chapter' in section :
17+ section ['Chapter' ]['content' ] = remove_sphinx_markdown (section ['Chapter' ]['content' ])
18+ for s in section ['Chapter' ]['sub_items' ]:
19+ process_section (s )
20+
21+ if __name__ == '__main__' :
22+ if len (sys .argv ) > 1 : # we check if we received any argument
23+ if sys .argv [1 ] == "supports" :
24+ # then we are good to return an exit status code of 0, since the other argument will just be the renderer's name
25+ sys .exit (0 )
26+
27+ # load both the context and the book representations from stdin
28+ context , book = json .load (sys .stdin )
29+
30+ for section in book ['sections' ]:
31+ process_section (section )
32+
33+ # we are done with the book's modification, we can just print it to stdout
34+ print (json .dumps (book ))
You can’t perform that action at this time.
0 commit comments