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 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
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],

View File

@ -1,5 +1,5 @@
```@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
@ -11,7 +11,7 @@ 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>.
</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>
</ul>
@ -28,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/notebooks/notebook.ipy
});
</script>
```

View File

@ -1,4 +1,3 @@
```@meta
EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/notebook-hello.ipynb"
```
@ -12,7 +11,7 @@ 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>.
</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>
</ul>
@ -29,4 +28,3 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/not
});
</script>
```

File diff suppressed because one or more lines are too long