Restructure folders

This commit is contained in:
Gelieza K
2023-08-11 15:41:40 +02:00
parent 732eb4ee00
commit 7f0f40fa47
43 changed files with 63394 additions and 19294 deletions

View File

@@ -13,7 +13,7 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/SCR
<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>.
Download this notebook and run it locally on your machine [recommended]. Click <a href="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>
@@ -25,7 +25,7 @@ EditURL = "https://github.com/fverdugo/XM_40017/blob/main/docs/src/notebooks/SCR
```
```@raw html
<iframe id="notebook" src="../notebook-output/SCRIPT_NAME.html" style="width:100%"></iframe>
<iframe id="notebook" src="../notebook-html/SCRIPT_NAME.html" style="width:100%"></iframe>
<script>
document.addEventListener('DOMContentLoaded', function(){
var myIframe = document.getElementById("notebook");
@@ -47,17 +47,15 @@ function convert_embedded_img_to_base64(notebook_path)
base64 = m[:base64code]
doc = replace(doc, "attachment:$filename.png" => "data:image/png;base64,$base64")
end
write(notebook_path, doc);
filename = splitpath(notebook_path)[end]
write("docs/src/notebooks/$filename", doc);
end
# Write markdown file that includes notebook html
function create_md_nb_file( notebook_path )
function create_md_nb_file( filename )
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" )
content = replace(md_nb_template, "SCRIPT_NAME" => filename)
md_path = joinpath(@__DIR__, "src/notebooks", filename * ".md" )
open(md_path, "w") do md_file
write(md_file, content)
end
@@ -65,7 +63,7 @@ function create_md_nb_file( notebook_path )
end
# Convert to html using nbconvert
function convert_notebook_to_html(notebook_path; output_name = "index", output_dir = "./docs/src/notebook-output", theme = "light")
function convert_notebook_to_html(notebook_path; output_name = "index", output_dir = "./docs/src/notebook-html", theme = "light")
command_jup = "jupyter"
command_nbc = "nbconvert"
output_format = "--to=html"
@@ -76,39 +74,33 @@ function convert_notebook_to_html(notebook_path; output_name = "index", output_d
run(`$command_jup $command_nbc $output_format $output $output_dir $theme $infile`)
end
# Resize iframes using IframeResizer
function modify_notebook_html( html_name )
content = open( html_name, "r" ) do html_file
# Modify html contents
function modify_notebook_html( html_filepath )
content = open( html_filepath, "r" ) do html_file
read( html_file, String )
end
# Resize iframes using IframeResizer
content = replace(content,
r"(<script\b[^>]*>[\s\S]*?<\/script>\K)" =>
s"\1\n\t<script src='../assets/iframeResizer.contentWindow.min.js'></script>\n";
count = 1
)
content = replace_colors(content)
open( html_name, "w" ) do html_file
open( html_filepath, "w" ) do html_file
write( html_file, content )
end
return nothing
end
# Replace colors to match Documenter.jl
function replace_colors(content)
#content = replace( content, "--jp-layout-color0: #111111;" => "--jp-layout-color0: #1f2424;")
#content = replace(content, "--md-grey-900: #212121;" => "--md-grey-900: #282f2f;")
return content
end
# Loop over notebooks and generate html and markdown
notebook_files = glob("*.ipynb", "docs/src/notebooks/")
notebook_files = glob("*.ipynb", "notebooks/")
for filepath in notebook_files
convert_embedded_img_to_base64(filepath)
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")
create_md_nb_file(filename)
convert_notebook_to_html("docs/src/notebooks/$filename_with_ext", output_name = filename)
modify_notebook_html("docs/src/notebook-html/$(filename).html")
end
makedocs(;
@@ -122,12 +114,12 @@ makedocs(;
canonical="https://fverdugo.github.io/XM_40017",
edit_link="main",),
pages=["Home" => "index.md","Getting started"=>"getting_started_with_julia.md", "Notebooks"=>[
"Julia Basics" => "julia_basics.md",
"Tasks and channels" => "julia_async.md",
"Remote calls and remote channels" => "julia_distributed.md",
"Matrix Multiplication"=>"matrix_matrix.md",
"Jacobi" => "jacobi_method.md",
"Solutions" => "sol_matrix_matrix.md"
"Julia Basics" => "notebooks/julia_basics.md",
"Tasks and channels" => "notebooks/julia_async.md",
"Remote calls and remote channels" => "notebooks/julia_distributed.md",
"Matrix Multiplication"=>"notebooks/matrix_matrix.md",
"Jacobi" => "notebooks/jacobi_method.md",
"Solutions" => "notebooks/sol_matrix_matrix.md"
]],
)