|
11 | 11 | import mkdocs_gen_files |
12 | 12 |
|
13 | 13 | REPO_ROOT = Path(__file__).parents[1] |
14 | | -PACKAGE_NAME_ROOT = "example_fgen_basic" |
15 | | -ROOT_DIR = Path("fortran-api") |
16 | | -nav = mkdocs_gen_files.Nav() |
| 14 | + |
| 15 | +FORD_OUTPUT_DIR = Path("docs") / "fortran-api" |
17 | 16 |
|
18 | 17 | ford = shutil.which("ford") |
19 | 18 | if ford is None: |
20 | 19 | msg = "Could not find FORD executable" |
21 | 20 | raise AssertionError(msg) |
22 | 21 |
|
23 | 22 | subprocess.run( # noqa: S603 |
24 | | - [ford, "ford_config.md"], |
| 23 | + [ford, "ford_config.md", "--output_dir", str(FORD_OUTPUT_DIR)], |
25 | 24 | check=True, |
26 | 25 | ) |
27 | 26 |
|
| 27 | +# Copy files across using mkdocs_gen_files |
| 28 | +# so it knows to include the files in the final docs. |
| 29 | +for entry in (REPO_ROOT / FORD_OUTPUT_DIR).rglob("*"): |
| 30 | + if not entry.is_file(): |
| 31 | + continue |
| 32 | + |
| 33 | + with open(entry, "rb") as fh: |
| 34 | + contents = fh.read() |
| 35 | + |
| 36 | + target_file = entry.relative_to(REPO_ROOT / "docs") |
| 37 | + with mkdocs_gen_files.open(target_file, "wb") as fh: |
| 38 | + fh.write(contents) |
| 39 | + if target_file.name == "index.html": |
| 40 | + target_file = target_file.parent / "home.html" |
| 41 | + |
| 42 | + with mkdocs_gen_files.open(target_file, "wb") as fh: |
| 43 | + fh.write(contents) |
| 44 | + |
| 45 | +# with mkdocs_gen_files.open( |
| 46 | +# (FORD_OUTPUT_DIR).relative_to("docs") / "NAVIGATION.md", "w" |
| 47 | +# ) as fh: |
| 48 | +# fh.writelines("* [example_fgen_basic](home.html)") |
| 49 | + |
| 50 | +# Remove the ford files (which were just copied) |
| 51 | +shutil.rmtree(REPO_ROOT / FORD_OUTPUT_DIR) |
| 52 | + |
28 | 53 | # Put back the gitkeep file which ford deletes |
29 | | -(REPO_ROOT / "docs" / ROOT_DIR / ".gitkeep").touch() |
| 54 | +gitkeep = REPO_ROOT / FORD_OUTPUT_DIR / ".gitkeep" |
| 55 | +gitkeep.parent.mkdir() |
| 56 | +gitkeep.touch() |
0 commit comments