Skip to content

Commit 1c08b54

Browse files
Add charts to docs
1 parent 056fac4 commit 1c08b54

File tree

7 files changed

+7280
-2
lines changed

7 files changed

+7280
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
all: build
22

33
documentation:
4+
python docs/add_plotly_to_book.py docs/
45
jb clean docs
56
jb build docs
67

docs/_toc.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ parts:
88
- file: reference/calculate_household_comparison
99
- file: reference/calculate_single_economy
1010
- file: reference/calculate_economy_comparison
11+
- file: reference/create_charts
1112

docs/add_plotly_to_book.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import argparse
2+
from pathlib import Path
3+
4+
# This command-line tools enables Plotly charts to show in the HTML files for the Jupyter Book documentation.
5+
6+
parser = argparse.ArgumentParser()
7+
parser.add_argument("book_path", help="Path to the Jupyter Book.")
8+
9+
args = parser.parse_args()
10+
11+
# Find every HTML file in the Jupyter Book. Then, add a script tag to the start of the <head> tag in each file, with the contents:
12+
# <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>
13+
14+
book_folder = Path(args.book_path)
15+
16+
for html_file in book_folder.glob("**/*.html"):
17+
with open(html_file, "r") as f:
18+
html = f.read()
19+
20+
# Add the script tag to the start of the <head> tag.
21+
html = html.replace(
22+
"<head>",
23+
'<head><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js"></script>',
24+
)
25+
26+
with open(html_file, "w") as f:
27+
f.write(html)

0 commit comments

Comments
 (0)