Build md files automatically in make.jl

This commit is contained in:
Gelieza K 2023-07-31 17:19:18 +02:00
parent 65e88dff8e
commit ee7a9c75d9
6 changed files with 85 additions and 15399 deletions

View File

@ -1,5 +1,52 @@
using XM_40017 using XM_40017
using Documenter 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
<div class="admonition is-success">
<header class="admonition-header">Tip</header>
<div class="admonition-body">
<ul>
<li>
Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/SCRIPT_NAME.ipynb" download>here</a>.
</li>
<li>
You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebooks/SCRIPT_NAME.ipynb">here</a>
.
</li>
</ul>
</div>
</div>
```
```@raw html
<iframe id="notebook" src="../notebook-output/SCRIPT_NAME.html" style="width:100%"></iframe>
<script>
document.addEventListener('DOMContentLoaded', function(){
var myIframe = document.getElementById("notebook");
iFrameResize({log:true}, myIframe);
});
</script>
```
"""
# 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 # Convert to html using nbconvert
function convert_notebook_to_html(notebook_path; output_name = "index", output_dir = "./docs/src/notebook-output", theme = "dark") 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 return content
end end
convert_notebook_to_html("docs/src/notebooks/matrix_matrix.ipynb", output_name = "matrix_matrix") # Loop over notebooks and generate html and markdown
modify_notebook_html("docs/src/notebook-output/matrix_matrix.html") notebook_files = glob("*.ipynb", "docs/src/notebooks/")
for filepath in notebook_files
convert_notebook_to_html("docs/src/notebooks/notebook-hello.ipynb", output_name = "notebook-hello") create_md_nb_file(filepath)
modify_notebook_html("docs/src/notebook-output/notebook-hello.html") 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(; makedocs(;
modules=[XM_40017], modules=[XM_40017],

View File

@ -1,5 +1,5 @@
```@meta ```@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 ```@raw html
@ -11,12 +11,12 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook.ipy
Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/matrix_matrix.ipynb" download>here</a>. Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/matrix_matrix.ipynb" download>here</a>.
</li> </li>
<li> <li>
You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebook.ipynb">here</a> You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebooks/matrix_matrix.ipynb">here</a>
. .
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
``` ```
```@raw html ```@raw html
@ -28,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook.ipy
}); });
</script> </script>
``` ```

View File

@ -1,4 +1,3 @@
```@meta ```@meta
EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/notebook-hello.ipynb" EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/notebook-hello.ipynb"
``` ```
@ -12,12 +11,12 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/not
Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/notebook-hello.ipynb" download>here</a>. Download this notebook and run it locally on your machine [recommended]. Click <a href="notebooks/notebook-hello.ipynb" download>here</a>.
</li> </li>
<li> <li>
You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebook-hello.ipynb">here</a> You can also run this notebook in the cloud using Binder. Click <a href="https://mybinder.org/v2/gh/fverdugo/XM_40017/gh-pages?filepath=dev/notebooks/notebook-hello.ipynb">here</a>
. .
</li> </li>
</ul> </ul>
</div> </div>
</div> </div>
``` ```
```@raw html ```@raw html
@ -29,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/not
}); });
</script> </script>
``` ```

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@
"metadata": {}, "metadata": {},
"source": [ "source": [
"<div class=\"alert alert-block alert-info\">\n", "<div class=\"alert alert-block alert-info\">\n",
"<b>Note:</b> Do not forget to execute the cells below before starting this notebook!\n", "<b>Note:</b> Do not forget to execute the cells below before starting this notebook! \n",
"</div>" "</div>"
] ]
}, },