Skip to content

Commit

Permalink
consistent tutorial.ipynb, .jl, .md
Browse files Browse the repository at this point in the history
  • Loading branch information
orso82 committed Sep 16, 2024
1 parent d219afa commit babfcf3
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 36 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ FUSE = "e64856f0-3bb8-4376-b4b7-c03396503992"
IMAS = "13ead8c1-b7d1-41bb-a6d0-5b8b65ed587a"
IMASdd = "c5a45a97-b3f9-491c-b9a7-aa88c3bc0067"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand Down
24 changes: 15 additions & 9 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import ProgressMeter
import Dates
using Literate

# Convert the Literate.jl script to markdown
Literate.markdown(joinpath(@__DIR__, "src", "tutorial.jl"), joinpath(@__DIR__, "src"), documenter=true)
include("notebook_to_jl.jl")

# Convert the Jupyter Notebook to Literate script
if isfile(joinpath(@__DIR__, "..", "examples", "tutorial.ipynb"))
convert_notebook_to_litterate(joinpath(@__DIR__, "..", "examples", "tutorial.ipynb"), joinpath(@__DIR__, "src", "tutorial.jl"))
end
# Convert the Literate script to markdown
Literate.markdown(joinpath(@__DIR__, "src", "tutorial.jl"), joinpath(@__DIR__, "src"); documenter=true)
lines = join(readlines(joinpath(@__DIR__, "src", "tutorial.md")), "\n")
open(joinpath(@__DIR__, "src", "tutorial.md"), "w") do f
write(f, replace(lines,
"""
---
return write(f, replace(lines,
"""
---
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
""" => ""))
*This page was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*
""" => ""))
end

function pretty_units(unit)
Expand Down Expand Up @@ -176,7 +182,7 @@ makedocs(;
sidebar_sitename=false,
assets=["assets/favicon.ico"],
size_threshold=nothing,
size_threshold_warn=nothing,
size_threshold_warn=nothing
),
repo=Remotes.GitHub("ProjectTorreyPines", "FUSE.jl"),
warnonly=true,
Expand All @@ -185,7 +191,7 @@ makedocs(;
"Lean" => ["Tutorial" => "tutorial.md", "Examples" => "examples.md"],
"Use Cases" => "cases.md",
"Actors" => ["List of actors" => "actors.md", "act parameters" => "act.md"],
"Initialization" => ["Init routines" => "inits.md", "ini parameters" => "ini.md"],
"Initialization" => ["Init routines" => "inits.md", "ini parameters" => "ini.md"],
"Data Structure" => "dd.md",
"Development" => "develop.md",
"Install" => ["Install FUSE" => "install.md", "on SAGA" => "install_saga.md", "on OMEGA" => "install_omega.md"],
Expand Down
31 changes: 31 additions & 0 deletions docs/notebook_to_jl.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using JSON

"""
convert_notebook_to_litterate(ipynb_file::String, litterate_file::String)
Function to convert a Jupyter notebook (.ipynb) into a Litterate-compatible Julia script
"""
function convert_notebook_to_litterate(ipynb_file::String, litterate_file::String)
# Read the Jupyter notebook file
notebook_content = JSON.parsefile(ipynb_file)

# Open the output Julia file for writing
open(litterate_file, "w") do f
# Loop through each cell in the notebook
for cell in notebook_content["cells"]
if cell["cell_type"] == "markdown"
# Convert markdown cells to comments
for line in cell["source"]
println(f, "# ", strip(line))
end
elseif cell["cell_type"] == "code"
# Write code cells as-is
for line in cell["source"]
println(f, strip(line))
end
end
# Add a blank line between cells for readability
println(f)
end
end
end
Loading

0 comments on commit babfcf3

Please sign in to comment.