Skip to content

Commit 0a4f3b5

Browse files
authored
Merge pull request #7 from daexs/clean-up-mkdocs-build
refactor: move documentation generation into the root directory
2 parents 50e0d17 + 5c5ed54 commit 0a4f3b5

File tree

7 files changed

+63
-9
lines changed

7 files changed

+63
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ tags
1919
!.circleci
2020
!.gitignore
2121
!.npmignore
22+
23+
tmp

Makefile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Manage plotly.js documentation.
2+
3+
RUN = uv run
4+
DOC_SRC=docs/_posts
5+
SCHEMA_SRC=test/plot-schema.json
6+
7+
## commands: show available commands
8+
commands:
9+
@grep -h -E '^##' ${MAKEFILE_LIST} | sed -e 's/## //g' | column -t -s ':'
10+
11+
## doc: rebuild documentation
12+
.PHONY: doc
13+
doc:
14+
make examples
15+
make reference
16+
make build
17+
18+
## examples: build example documentation in ./tmp
19+
examples:
20+
@mkdir -p tmp
21+
${RUN} bin/example_pages.py --indir ${DOC_SRC}/plotly_js --outdir tmp/javascript --jsversion 3.2.1
22+
23+
## format: reformat Python code
24+
format:
25+
@ruff format bin
26+
27+
## lint: check code and project
28+
lint:
29+
@ruff check bin
30+
31+
## reference: build reference documentation in ./tmp
32+
reference:
33+
@mkdir -p tmp
34+
${RUN} bin/reference_pages.py --schema ${SCHEMA_SRC} --outdir tmp/reference ${DOC_SRC}/reference_pages/javascript/*.html
35+
36+
## serve: display documentation
37+
serve:
38+
${RUN} mkdocs serve
39+
40+
## website: build documentation with mkdocs using already-built examples and reference
41+
website:
42+
${RUN} mkdocs build
43+
44+
## --: --
45+
46+
## clean: clean up repository
47+
clean:
48+
@find . -name '*~' -delete
49+
@find . -name '.DS_Store' -delete
50+
@rm -rf _site
51+
@rm -f ${SCHEMA_DST}

docs/bin/example_pages.py renamed to bin/example_pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _make_mydiv(args, accum, path, header, content, counter):
153153
content_json = escape(json.dumps(content))
154154

155155
# Get JS Version
156-
mkdocs_path = Path(__file__).resolve().parents[2] / "mkdocs.yml"
156+
mkdocs_path = Path(__file__).resolve().parent.parent / "mkdocs.yml"
157157
config = load_config(config_file=str(mkdocs_path))
158158
extra = config.get('extra', {})
159159
version = extra.get('js-version')

bin/generate_reference_pages.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
"""Generate reference pages to satisfy MkDocs."""
2+
13
import os
24
from pathlib import Path
35
import mkdocs_gen_files
46

57
def generate_pages(path, output_dir, parent, nav=None):
68
"""
7-
Walks through the path and generates markdown files that
8-
include the corresponding html snippets in it.
9+
Walk through the a directory and generate Markdown files that
10+
include the corresponding HTML snippets.
911
"""
1012
with os.scandir(path) as it:
1113
entries = sorted(it, key= lambda e: e.name)
@@ -25,19 +27,18 @@ def generate_pages(path, output_dir, parent, nav=None):
2527

2628
nav = mkdocs_gen_files.Nav()
2729

28-
parent = Path(__file__).resolve().parents[1]
29-
ref_path = f"{parent}/docs/tmp/reference"
30+
parent = Path(__file__).resolve().parent.parent
31+
ref_path = f"{parent}/tmp/reference"
3032
ref_output_dir = f"{parent}/pages/reference/"
3133

32-
examples_path = f"{parent}/docs/tmp/javascript"
34+
examples_path = f"{parent}/tmp/javascript"
3335
examples_output_dir = f"{parent}/pages/examples/"
3436

35-
# Make directories if it doesn't exist
3637
os.makedirs(ref_output_dir, exist_ok=True)
3738
os.makedirs(examples_output_dir, exist_ok=True)
3839

3940
generate_pages(ref_path, ref_output_dir, "reference", nav)
4041
generate_pages(examples_path, examples_output_dir, "javascript")
4142

4243
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
43-
nav_file.writelines(nav.build_literate_nav())
44+
nav_file.writelines(nav.build_literate_nav())
File renamed without changes.
File renamed without changes.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ theme:
2424
markdown_extensions:
2525
- footnotes
2626
- pymdownx.snippets:
27-
base_path: ["docs/tmp"]
27+
base_path: ["tmp"]
2828

2929
extra_css:
3030
- css/extra_css.css

0 commit comments

Comments
 (0)