|
25 | 25 |
|
26 | 26 |
|
27 | 27 | def parse_sphinx(input_dir, output_dir): |
28 | | - for fname in os.listdir(input_dir): |
29 | | - if fname.endswith(".html"): |
30 | | - with open(input_dir + fname, "r") as f: |
31 | | - soup = BeautifulSoup(f.read(), "html.parser") |
32 | | - doc = soup.find("div", {"class": "document"}) |
33 | | - wrapped_doc = doc.wrap(soup.new_tag("div", **{"class": "sphinx"})) |
34 | | - # add js |
35 | | - if fname == "search.html": |
36 | | - out = js_scripts + search_js_scripts + str(wrapped_doc) |
37 | | - else: |
38 | | - out = js_scripts + str(wrapped_doc) |
39 | | - with open(output_dir + fname, "w") as fout: |
40 | | - fout.write(out) |
| 28 | + for cur, _, files in os.walk(input_dir): |
| 29 | + for fname in files: |
| 30 | + if fname.endswith(".html"): |
| 31 | + with open(os.path.join(cur, fname), "r") as f: |
| 32 | + soup = BeautifulSoup(f.read(), "html.parser") |
| 33 | + doc = soup.find("div", {"class": "document"}) |
| 34 | + wrapped_doc = doc.wrap(soup.new_tag("div", **{"class": "sphinx"})) |
| 35 | + # add js |
| 36 | + if fname == "search.html": |
| 37 | + out = js_scripts + search_js_scripts + str(wrapped_doc) |
| 38 | + else: |
| 39 | + out = js_scripts + str(wrapped_doc) |
| 40 | + output_path = os.path.join(output_dir, os.path.relpath(cur, input_dir)) |
| 41 | + os.makedirs(output_path, exist_ok=True) |
| 42 | + with open(os.path.join(output_path, fname), "w") as fout: |
| 43 | + fout.write(out) |
41 | 44 |
|
42 | | - # update reference in JS file |
43 | | - with open(input_dir + "_static/searchtools.js", "r") as js_file: |
44 | | - js = js_file.read() |
45 | | - js = js.replace( |
46 | | - "DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/'", "'_sphinx-sources/'" |
47 | | - ) |
48 | | - with open(input_dir + "_static/searchtools.js", "w") as js_file: |
49 | | - js_file.write(js) |
| 45 | + # update reference in JS file |
| 46 | + with open(os.path.join(input_dir, "_static/searchtools.js"), "r") as js_file: |
| 47 | + js = js_file.read() |
| 48 | + js = js.replace( |
| 49 | + "DOCUMENTATION_OPTIONS.URL_ROOT + '_sources/'", "'_sphinx-sources/'" |
| 50 | + ) |
| 51 | + with open(os.path.join(input_dir, "_static/searchtools.js"), "w") as js_file: |
| 52 | + js_file.write(js) |
50 | 53 |
|
51 | 54 |
|
52 | 55 | if __name__ == "__main__": |
|
0 commit comments