Skip to content

Commit 04ab9fe

Browse files
committed
use PlutoSlideServer for exports
1 parent 468bcb0 commit 04ab9fe

File tree

3 files changed

+98
-137
lines changed

3 files changed

+98
-137
lines changed

Manifest.toml

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
julia_version = "1.11.4"
44
manifest_format = "2.0"
5-
project_hash = "73f5657fabc4984484b79d2c18d0b4b5268f76e7"
5+
project_hash = "c19737f1d2a83bce64f07b873cb6b2a81c51024c"
66

77
[[deps.AbstractPlutoDingetjes]]
88
deps = ["Pkg"]
@@ -33,6 +33,12 @@ version = "1.11.0"
3333
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
3434
version = "1.11.0"
3535

36+
[[deps.BetterFileWatching]]
37+
deps = ["Deno_jll", "JSON"]
38+
git-tree-sha1 = "1849cdfcae3ef1b9545cb1d0e4f1b012d33570b9"
39+
uuid = "c9fd44ac-77b5-486c-9482-9798bd063cc6"
40+
version = "0.1.6"
41+
3642
[[deps.BitFlags]]
3743
git-tree-sha1 = "0691e34b3bb8be9307330f88d1a3c3f25466c24d"
3844
uuid = "d1d4a3ce-64b1-5f1a-9ba4-7e7e69966f35"
@@ -155,6 +161,12 @@ git-tree-sha1 = "9e2f36d3c96a820c678f2f1f1782582fcf685bae"
155161
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"
156162
version = "1.9.1"
157163

164+
[[deps.Deno_jll]]
165+
deps = ["Artifacts", "JLLWrappers", "Libdl"]
166+
git-tree-sha1 = "a2470d95fb1056e505d892bfe69dbe7c354b9c38"
167+
uuid = "04572ae6-984a-583e-9378-9577a1c2574d"
168+
version = "2.6.3+0"
169+
158170
[[deps.Distributed]]
159171
deps = ["Random", "Serialization", "Sockets"]
160172
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
@@ -243,6 +255,12 @@ git-tree-sha1 = "7a214fdac5ed5f59a22c2d9a885a16da1c74bbc7"
243255
uuid = "559328eb-81f9-559d-9380-de523a88c83c"
244256
version = "1.0.17+0"
245257

258+
[[deps.FromFile]]
259+
deps = ["Downloads", "Requires"]
260+
git-tree-sha1 = "fd1b6f327472d0faf28b4d1fda8d9b582ab136df"
261+
uuid = "ff7dd447-1dcb-4ce3-b8ac-22a812192de7"
262+
version = "0.1.6"
263+
246264
[[deps.GLFW_jll]]
247265
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libglvnd_jll", "Xorg_libXcursor_jll", "Xorg_libXi_jll", "Xorg_libXinerama_jll", "Xorg_libXrandr_jll", "libdecor_jll", "xkbcommon_jll"]
248266
git-tree-sha1 = "b7bfd56fa66616138dfe5237da4dc13bbd83c67f"
@@ -279,12 +297,35 @@ git-tree-sha1 = "38044a04637976140074d0b0621c1edf0eb531fd"
279297
uuid = "61579ee1-b43e-5ca0-a5da-69d92c66a64b"
280298
version = "9.55.1+0"
281299

300+
[[deps.Git]]
301+
deps = ["Git_LFS_jll", "Git_jll", "JLLWrappers", "OpenSSH_jll"]
302+
git-tree-sha1 = "824a1890086880696fc908fe12a17bcf61738bd8"
303+
uuid = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
304+
version = "1.5.0"
305+
306+
[[deps.Git_LFS_jll]]
307+
deps = ["Artifacts", "JLLWrappers", "Libdl"]
308+
git-tree-sha1 = "bb8471f313ed941f299aa53d32a94ab3bee08844"
309+
uuid = "020c3dae-16b3-5ae5-87b3-4cb189e250b2"
310+
version = "3.7.0+0"
311+
312+
[[deps.Git_jll]]
313+
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "Libiconv_jll", "OpenSSL_jll", "PCRE2_jll", "Zlib_jll"]
314+
git-tree-sha1 = "dc34a3e3d96b4ed305b641e626dc14c12b7824b8"
315+
uuid = "f8c6e375-362e-5223-8a59-34ff63f689eb"
316+
version = "2.53.0+0"
317+
282318
[[deps.Glib_jll]]
283319
deps = ["Artifacts", "Gettext_jll", "JLLWrappers", "Libdl", "Libffi_jll", "Libiconv_jll", "Libmount_jll", "PCRE2_jll", "Zlib_jll"]
284320
git-tree-sha1 = "b0036b392358c80d2d2124746c2bf3d48d457938"
285321
uuid = "7746bdde-850d-59dc-9ae8-88ece973131d"
286322
version = "2.82.4+0"
287323

324+
[[deps.Glob]]
325+
git-tree-sha1 = "83cb0092e2792b9e3a865b6655e88f5b862607e2"
326+
uuid = "c27321d9-0574-5035-807b-f59d2c89b15c"
327+
version = "1.4.0"
328+
288329
[[deps.GracefulPkg]]
289330
deps = ["Compat", "Pkg", "TOML"]
290331
git-tree-sha1 = "a854d6c0e9fb561b88cd20b4ad64f518cb1bfb8d"
@@ -467,6 +508,12 @@ deps = ["Artifacts", "Pkg"]
467508
uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
468509
version = "1.11.0"
469510

511+
[[deps.LeftChildRightSiblingTrees]]
512+
deps = ["AbstractTrees"]
513+
git-tree-sha1 = "95ba48564903b43b2462318aa243ee79d81135ff"
514+
uuid = "1d6d02ad-be62-4b6b-8a6d-2f90e265016e"
515+
version = "0.2.1"
516+
470517
[[deps.LibCURL]]
471518
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
472519
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
@@ -646,6 +693,12 @@ deps = ["Artifacts", "Libdl"]
646693
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
647694
version = "0.8.1+4"
648695

696+
[[deps.OpenSSH_jll]]
697+
deps = ["Artifacts", "JLLWrappers", "Libdl", "OpenSSL_jll", "Zlib_jll"]
698+
git-tree-sha1 = "301412a644646fdc0ad67d0a87487466b491e53d"
699+
uuid = "9bd350c2-7e96-507f-8002-3f2e150b4e1b"
700+
version = "10.2.1+0"
701+
649702
[[deps.OpenSSL]]
650703
deps = ["BitFlags", "Dates", "MozillaCACerts_jll", "NetworkOptions", "OpenSSL_jll", "Sockets"]
651704
git-tree-sha1 = "1d1aaa7d449b58415f97d2839c318b70ffb525a0"
@@ -745,6 +798,12 @@ git-tree-sha1 = "c3e5073a977b1c58b2d55c1ec187c3737e64e6af"
745798
uuid = "72656b73-756c-7461-726b-72656b6b696b"
746799
version = "1.2.2"
747800

801+
[[deps.PlutoSliderServer]]
802+
deps = ["AbstractPlutoDingetjes", "Base64", "BetterFileWatching", "Configurations", "Distributed", "FromFile", "Git", "Glob", "GracefulPkg", "HTTP", "JSON", "LibGit2", "Logging", "Pkg", "Pluto", "PlutoDependencyExplorer", "SHA", "Serialization", "Sockets", "TOML", "TerminalLoggers", "UUIDs"]
803+
git-tree-sha1 = "d00613560b367be5b9620defa748489c67023347"
804+
uuid = "2fc8631c-6f24-4c5b-bca7-cbb509c42db4"
805+
version = "1.8.0"
806+
748807
[[deps.PlutoStaticHTML]]
749808
deps = ["AbstractTrees", "Base64", "Dates", "Gumbo", "LazyArtifacts", "Pkg", "Pluto", "PrecompileTools", "RelocatableFolders", "SHA", "TOML", "tectonic_jll"]
750809
git-tree-sha1 = "4ce3422fcced70805225a88c3d4f013cf6e043cf"
@@ -779,6 +838,12 @@ deps = ["Unicode"]
779838
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
780839
version = "1.11.0"
781840

841+
[[deps.ProgressLogging]]
842+
deps = ["Logging", "SHA", "UUIDs"]
843+
git-tree-sha1 = "f0803bc1171e455a04124affa9c21bba5ac4db32"
844+
uuid = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
845+
version = "0.1.6"
846+
782847
[[deps.PtrArrays]]
783848
git-tree-sha1 = "1d36ef11a9aaf1e8b74dacc6a731dd1de8fd493d"
784849
uuid = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
@@ -972,6 +1037,12 @@ git-tree-sha1 = "1feb45f88d133a655e001435632f019a9a1bcdb6"
9721037
uuid = "62fd8b95-f654-4bbd-a8a5-9c27f68ccd50"
9731038
version = "0.1.1"
9741039

1040+
[[deps.TerminalLoggers]]
1041+
deps = ["LeftChildRightSiblingTrees", "Logging", "Markdown", "Printf", "ProgressLogging", "UUIDs"]
1042+
git-tree-sha1 = "f133fab380933d042f6796eda4e130272ba520ca"
1043+
uuid = "5d786b92-1e48-4d6f-9151-6b4477ca9bed"
1044+
version = "0.1.7"
1045+
9751046
[[deps.Test]]
9761047
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
9771048
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
33
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
44
Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
5+
PlutoSliderServer = "2fc8631c-6f24-4c5b-bca7-cbb509c42db4"
56
PlutoStaticHTML = "359b1769-a58e-495b-9770-312e911026ad"
67
PlutoUI = "7f904dfe-b85e-4ff6-b463-dae2292396a8"

scripts/export_pluto.jl

Lines changed: 25 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,30 @@
1-
# Export Pluto notebooks in notebooks/ to static HTML in public/
2-
# - Uses PlutoStaticHTML if available (tries multiple common API names).
3-
# - If PlutoStaticHTML is missing, this script attempts to add it for the run.
4-
# - Run with: julia --project=. scripts/export_pluto.jl
5-
6-
using Pkg
7-
using Logging
8-
9-
const EXPORTER_PKG = "PlutoStaticHTML"
10-
11-
function ensure_exporter(pkg::String)
12-
try
13-
@eval using PlutoStaticHTML
14-
return true
15-
catch err
16-
@info("$pkg not present in environment, trying to add it for this run...")
17-
try
18-
Pkg.add(pkg)
19-
@eval using PlutoStaticHTML
20-
return true
21-
catch err2
22-
@error("Failed to install or load $pkg: $err2")
23-
return false
24-
end
25-
end
26-
end
27-
28-
function try_export_with_known_apis(mod, nbpath::String, outpath::String)
29-
# 1) export(nb, outpath)
30-
if isdefined(mod, :export)
31-
try
32-
@info("Calling PlutoStaticHTML.export($nbpath, $outpath)")
33-
getfield(mod, :export)(nbpath, outpath)
34-
return true
35-
catch err
36-
@warn("PlutoStaticHTML.export failed: $err")
37-
end
38-
end
39-
40-
# 2) save_html(nb, outpath)
41-
if isdefined(mod, :save_html)
42-
try
43-
@info("Calling PlutoStaticHTML.save_html($nbpath, $outpath)")
44-
getfield(mod, :save_html)(nbpath, outpath)
45-
return true
46-
catch err
47-
@warn("PlutoStaticHTML.save_html failed: $err")
48-
end
49-
end
50-
51-
# 3) notebook_to_html(nb) -> returns HTML string
52-
if isdefined(mod, :notebook_to_html)
53-
try
54-
@info("Calling PlutoStaticHTML.notebook_to_html($nbpath) -> writing to $outpath")
55-
html = getfield(mod, :notebook_to_html)(nbpath)
56-
open(outpath, "w") do io
57-
write(io, html)
58-
end
59-
return true
60-
catch err
61-
@warn("PlutoStaticHTML.notebook_to_html failed: $err")
62-
end
63-
end
64-
65-
# 4) autodiscover candidate functions with "html", "export" or "render" in the name
66-
fnames = filter(n -> occursin("html", String(n)) || occursin("export", String(n)) || occursin("render", String(n)), names(mod, all=true))
67-
for fname in fnames
68-
try
69-
f = getfield(mod, fname)
70-
@info("Attempting autodiscovered function: $(fname)")
71-
# Try calling with (nb, outpath) then with (nb) and write result if string-like
72-
try
73-
f(nbpath, outpath)
74-
return true
75-
catch
76-
res = f(nbpath)
77-
if isa(res, AbstractString)
78-
open(outpath, "w") do io write(io, res) end
79-
return true
80-
end
1+
using PlutoSliderServer
2+
3+
# Pfade definieren
4+
notebook_dir = joinpath(pwd(), "notebooks")
5+
static_dir = joinpath(pwd(), "public")
6+
mkpath(static_dir)
7+
8+
@info "Starte Export mit export_notebook..."
9+
10+
# In das Notebook-Verzeichnis wechseln, damit die Pfade stimmen
11+
cd(notebook_dir) do
12+
for file in readdir()
13+
if endswith(file, ".jl")
14+
println("Exporting: ", file)
15+
16+
# Die einfachste Export-Methode
17+
# Erzeugt eine .html Datei im gleichen Ordner
18+
PlutoSliderServer.export_notebook(file)
19+
20+
# Die generierte HTML-Datei finden und verschieben
21+
html_file = replace(file, ".jl" => ".html")
22+
if isfile(html_file)
23+
mv(html_file, joinpath(static_dir, html_file); force=true)
24+
println("Moved to public: ", html_file)
8125
end
82-
catch err
83-
@warn("Autodiscovered attempt $(fname) failed: $err")
8426
end
8527
end
86-
87-
return false
88-
end
89-
90-
function main()
91-
notebook_dir = joinpath(pwd(), "notebooks")
92-
output_dir = joinpath(pwd(), "public")
93-
mkpath(output_dir)
94-
95-
if !isdir(notebook_dir)
96-
@info "No notebooks/ directory found; nothing to export."
97-
return
98-
end
99-
100-
notebooks = filter(f -> endswith(f, ".jl"), readdir(notebook_dir; join=true))
101-
if isempty(notebooks)
102-
@info "No .jl notebooks found in notebooks/. Nothing to do."
103-
return
104-
end
105-
106-
ok = ensure_exporter(EXPORTER_PKG)
107-
if !ok
108-
@error "Exporter $EXPORTER_PKG not available. Add it to Project.toml or install it manually."
109-
exit(1)
110-
end
111-
112-
# Export loop with local counter
113-
success_count = 0
114-
for nb in notebooks
115-
name = splitext(basename(nb))[1]
116-
outpath = joinpath(output_dir, "$(name).html")
117-
@info "Exporting $nb -> $outpath"
118-
119-
try
120-
exported = try_export_with_known_apis(PlutoStaticHTML, nb, outpath)
121-
if exported
122-
@info "Export succeeded for $nb"
123-
success_count += 1
124-
else
125-
@warn "No known export API succeeded for $nb. See logs above."
126-
end
127-
catch err
128-
@error "Unexpected error exporting $nb: $err"
129-
end
130-
end
131-
132-
if success_count == 0
133-
@error "No notebooks were exported. See messages above to diagnose."
134-
exit(1)
135-
else
136-
@info "Export complete: $success_count notebook(s) exported to public/."
137-
exit(0)
138-
end
13928
end
14029

141-
main()
30+
@info "Export abgeschlossen!"

0 commit comments

Comments
 (0)