From ee7a9c75d9dfc2724e721f5fbada46061bb9dc88 Mon Sep 17 00:00:00 2001 From: Gelieza K Date: Mon, 31 Jul 2023 17:19:18 +0200 Subject: [PATCH] Build md files automatically in make.jl --- docs/make.jl | 61 +- docs/src/matrix_matrix.md | 29 +- docs/src/notebook-hello.md | 28 +- docs/src/notebook-output/index.html | 15362 ------------------ docs/src/notebook-output/matrix_matrix.html | 2 +- docs/src/notebooks/matrix_matrix.ipynb | 2 +- 6 files changed, 85 insertions(+), 15399 deletions(-) delete mode 100644 docs/src/notebook-output/index.html diff --git a/docs/make.jl b/docs/make.jl index 98a529e..d5a8c7a 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,5 +1,52 @@ using XM_40017 using Documenter +using Glob + +const md_nb_template = """ +```@meta +EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/SCRIPT_NAME.ipynb" +``` + +```@raw html +
+
Tip
+
+
    +
  • + Download this notebook and run it locally on your machine [recommended]. Click here. +
  • +
  • + You can also run this notebook in the cloud using Binder. Click here + . +
  • +
+
+
+``` + +```@raw html + + +``` +""" + +# Write markdown file that includes notebook html +function create_md_nb_file( notebook_path ) + global md_nb_template; + script_file = splitpath(notebook_path)[end] + script_name = splitext(script_file)[1] + content = replace( md_nb_template, "SCRIPT_NAME" => script_name) + md_path = joinpath(@__DIR__, "src", script_name * ".md" ) + open(md_path, "w") do md_file + write(md_file, content) + end + return md_path +end # Convert to html using nbconvert function convert_notebook_to_html(notebook_path; output_name = "index", output_dir = "./docs/src/notebook-output", theme = "dark") @@ -37,11 +84,15 @@ function replace_colors(content) return content end -convert_notebook_to_html("docs/src/notebooks/matrix_matrix.ipynb", output_name = "matrix_matrix") -modify_notebook_html("docs/src/notebook-output/matrix_matrix.html") - -convert_notebook_to_html("docs/src/notebooks/notebook-hello.ipynb", output_name = "notebook-hello") -modify_notebook_html("docs/src/notebook-output/notebook-hello.html") +# Loop over notebooks and generate html and markdown +notebook_files = glob("*.ipynb", "docs/src/notebooks/") +for filepath in notebook_files + create_md_nb_file(filepath) + filename_with_ext = splitpath(filepath)[end] + filename = splitext(filename_with_ext)[1] + convert_notebook_to_html(filepath, output_name = filename) + modify_notebook_html("docs/src/notebook-output/$(filename).html") +end makedocs(; modules=[XM_40017], diff --git a/docs/src/matrix_matrix.md b/docs/src/matrix_matrix.md index 1d9edcc..6fc6208 100644 --- a/docs/src/matrix_matrix.md +++ b/docs/src/matrix_matrix.md @@ -1,22 +1,22 @@ ```@meta -EditURL = "https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook.ipynb" +EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/matrix_matrix.ipynb" ``` ```@raw html
-
Tip
-
-
    -
  • - Download this notebook and run it locally on your machine [recommended]. Click here. -
  • -
  • - You can also run this notebook in the cloud using Binder. Click here - . -
  • -
-
-
+
Tip
+
+ +
+ ``` ```@raw html @@ -28,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook.ipy }); ``` - diff --git a/docs/src/notebook-hello.md b/docs/src/notebook-hello.md index cf3bb30..cdcaea3 100644 --- a/docs/src/notebook-hello.md +++ b/docs/src/notebook-hello.md @@ -1,23 +1,22 @@ - ```@meta EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/notebook-hello.ipynb" ``` ```@raw html
-
Tip
-
-
    -
  • - Download this notebook and run it locally on your machine [recommended]. Click here. -
  • -
  • - You can also run this notebook in the cloud using Binder. Click here - . -
  • -
-
-
+
Tip
+
+ +
+ ``` ```@raw html @@ -29,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/not }); ``` - diff --git a/docs/src/notebook-output/index.html b/docs/src/notebook-output/index.html deleted file mode 100644 index af2a4fb..0000000 --- a/docs/src/notebook-output/index.html +++ /dev/null @@ -1,15362 +0,0 @@ - - - - - -notebook - - - - - - - - - - - - - - - - - - - - - - - -
- -
- - -
- - -
- - -
- - -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
-
- -
- - -
-
- -
-
- -
- - -
- - - - - - - - - diff --git a/docs/src/notebook-output/matrix_matrix.html b/docs/src/notebook-output/matrix_matrix.html index c4fedfe..3138a69 100644 --- a/docs/src/notebook-output/matrix_matrix.html +++ b/docs/src/notebook-output/matrix_matrix.html @@ -15130,7 +15130,7 @@ body[data-format='mobile'] .jp-OutputArea-child .jp-OutputArea-output {
diff --git a/docs/src/notebooks/matrix_matrix.ipynb b/docs/src/notebooks/matrix_matrix.ipynb index 7604ee9..02422c9 100644 --- a/docs/src/notebooks/matrix_matrix.ipynb +++ b/docs/src/notebooks/matrix_matrix.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "source": [ "
\n", - "Note: Do not forget to execute the cells below before starting this notebook!\n", + "Note: Do not forget to execute the cells below before starting this notebook! \n", "
" ] },