Skip to content

Commit

Permalink
Merge pull request #2 from tensor4all/terasaki/add-scripts
Browse files Browse the repository at this point in the history
Terasaki/add scripts
  • Loading branch information
terasakisatoshi authored Sep 13, 2024
2 parents ea0ea81 + c9b1271 commit 7c94712
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ExportPluto.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ jobs:
restore-keys: |
${{ runner.os }}-pluto_state_cache-v2-${{ hashFiles('**/Project.toml', '**/Manifest.toml', '.github/workflows/*' ) }}
- name: Instantiate
run: |
julia --project -e 'using Pkg; Pkg.instantiate()'
- name:
run: |
julia --project scripts/generate_index.jl
- name: Run & export Pluto notebooks
run: |
julia -e 'using Pkg
Pkg.activate(mktempdir())
Pkg.add([
Pkg.PackageSpec(name="PlutoSliderServer", version="0.3.2-0.3"),
])
julia --project -e '
import PlutoSliderServer
PlutoSliderServer.github_action("./pluto_notebooks";
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.html
pluto_notebooks/pluto_export.json
5 changes: 5 additions & 0 deletions scripts/export_directory.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using PlutoSliderServer

pluto_notebooks = joinpath(dirname(@__DIR__), "pluto_notebooks")

PlutoSliderServer.export_directory(pluto_notebooks)
58 changes: 58 additions & 0 deletions scripts/generate_index.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function extract_title(filepath::AbstractString)
lines = read(filepath, String)

title = ""
searchingmd = false
foundtitle = false

for l in split(lines, "\n")
foundtitle && break
if !isnothing(match(r"md\"\"\"", l))
searchingmd = true
continue
end

if searchingmd
m = match(r"#\s*", l)
if !isnothing(m)
title_ = lstrip(l[nextind(l, m.offset + 1):end])
title = replace(title_, r"\"\"\"" => "")
foundtitle = true
end
end

if searchingmd
isnothing(match(r"\"\"\"", l))
searchingmd = false
end
end
if isempty(title)
@warn "Couldn't find title. Using file name as title"
title = basename(file)
end
return title
end

const PLUTO_NOTEBOOKS_DIR = joinpath(dirname(@__DIR__), "pluto_notebooks")

const PLUTO_FILE_NAMES = [
"welcome.jl",
"quantics1d.jl",
"quantics1d_advanced.jl",
"compress.jl",
"interfacingwithitensors.jl",
"quantics2d.jl",
"plots.jl",
"qft.jl",
]

open(joinpath(PLUTO_NOTEBOOKS_DIR, "index.md"), "w") do io
write(io, "# Notebooks\n")

for f in PLUTO_FILE_NAMES
title = extract_title(joinpath(PLUTO_NOTEBOOKS_DIR, f))
link = splitext(basename(f))[begin] * ".html"
@show title
write(io, "- [$(title)]($link)\n")
end
end

0 comments on commit 7c94712

Please sign in to comment.