From 6dbb64f05865ee6c14c0a3d4c917c4e921eb087d Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Tue, 13 Dec 2022 16:39:02 +0100 Subject: [PATCH 1/5] Option to use Pluto's Featured GUI as index html --- src/Actions.jl | 2 +- src/Configuration.jl | 2 ++ src/HTTPRouter.jl | 4 ++-- src/IndexHTML.jl | 21 +++++++++++++++++++-- src/IndexJSON.jl | 8 ++++++-- src/PlutoSliderServer.jl | 10 ++-------- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Actions.jl b/src/Actions.jl index 7b2aca2..a90174d 100644 --- a/src/Actions.jl +++ b/src/Actions.jl @@ -249,7 +249,7 @@ function generate_static_export( ) header_html = Pluto.frontmatter_html(frontmatter) - html_contents = generate_html(; + html_contents = Pluto.generate_html(; pluto_cdn_root=settings.Export.pluto_cdn_root, version=pluto_version, notebookfile_js, diff --git a/src/Configuration.jl b/src/Configuration.jl index 66233a5..00a80ea 100644 --- a/src/Configuration.jl +++ b/src/Configuration.jl @@ -46,6 +46,8 @@ end cache_dir::Union{Nothing,String} = nothing "Automatically generate an `index.html` file, listing all the exported notebooks (only if no `index.jl` or `index.html` file exists already)." create_index::Bool = true + "Use the Pluto Featured GUI to display the notebooks on the auto-generated index page, using frontmatter for title, description, image, and more. The default is currently `false`, but it might change in the future. Set to `true` or `false` explicitly to fix a value." + create_pluto_featured_index::Union{Nothing,Bool} = nothing """ADVANCED: URL of the binder repository to load when you click the "Run on binder" button in the top right, this will be set automatically if you leave it at the default value. This setting is quite advanced, and only makes sense if you have a fork of `https://github.com/fonsp/pluto-on-binder/` (because you want to control the binder launch, or because you are using your own fork of Pluto). If so, the setting should be of the form `"https://mybinder.org/v2/gh/fonsp/pluto-on-binder/v0.17.2"`, where `fonsp/pluto-on-binder` is the name of your repository, and `v0.17.2` is a tag or commit hash.""" binder_url::Union{Nothing,String} = nothing pluto_cdn_root::Union{Nothing,String} = nothing diff --git a/src/HTTPRouter.jl b/src/HTTPRouter.jl index 5669395..9555d99 100644 --- a/src/HTTPRouter.jl +++ b/src/HTTPRouter.jl @@ -13,7 +13,7 @@ using Sockets import JSON @from "./IndexJSON.jl" import generate_index_json -@from "./IndexHTML.jl" import temp_index, generate_index_html +@from "./IndexHTML.jl" import temp_index, generate_basic_index_html @from "./Types.jl" import NotebookSession, RunningNotebook @from "./Configuration.jl" import PlutoDeploySettings, get_configuration @from "./PlutoHash.jl" import base64urldecode @@ -152,7 +152,7 @@ function make_router( only_relevant(sesh.run.original_state), only_relevant(new_state), ) - patches_as_dicts::Array{Dict} = Firebasey._convert(Array{Dict},patches) + patches_as_dicts::Array{Dict} = Firebasey._convert(Array{Dict}, patches) HTTP.Response( 200, diff --git a/src/IndexHTML.jl b/src/IndexHTML.jl index ceabb29..d567ea8 100644 --- a/src/IndexHTML.jl +++ b/src/IndexHTML.jl @@ -8,7 +8,7 @@ import Pluto: Pluto, without_pluto_file_extension @from "./Types.jl" import NotebookSession, RunningNotebook -function generate_index_html(paths) +function generate_basic_index_html(paths) """ @@ -43,10 +43,27 @@ function generate_index_html(paths) """ end +function generate_index_html( + sessions::Vector{NotebookSession}; + settings::PlutoDeploySettings, +) + if something(settings.Export.create_pluto_featured_index, false) + Pluto.generate_index_html(; + pluto_cdn_root=settings.Export.pluto_cdn_root, + version=try_get_exact_pluto_version(), + featured_static=true, + featured_direct_html_links=true, + featured_sources_js="[{url:`./pluto_export.json`}]", + ) + else + temp_index(sessions) + end +end + function temp_index(notebook_sessions::Vector{NotebookSession}) - generate_index_html(temp_index_item.(notebook_sessions)) + generate_basic_index_html(Iterators.map(temp_index_item, notebook_sessions)) end function temp_index_item(s::NotebookSession) without_pluto_file_extension(s.path) => nothing diff --git a/src/IndexJSON.jl b/src/IndexJSON.jl index a135fbb..1694f5a 100644 --- a/src/IndexJSON.jl +++ b/src/IndexJSON.jl @@ -63,13 +63,17 @@ function json_data( ) end -function generate_index_json(s; settings::PlutoDeploySettings, start_dir::AbstractString) +function generate_index_json( + sessions::Vector{NotebookSession}; + settings::PlutoDeploySettings, + start_dir::AbstractString, +) p = joinpath(start_dir, "pluto_export_configuration.json") config_data = if isfile(p) JSON.parse(read(p, String))::Dict{String,Any} else Dict{String,Any}() end - result = json_data(s; settings, start_dir, config_data) + result = json_data(sessions; settings, start_dir, config_data) JSON.json(result) end \ No newline at end of file diff --git a/src/PlutoSliderServer.jl b/src/PlutoSliderServer.jl index e6c2f09..ecde909 100644 --- a/src/PlutoSliderServer.jl +++ b/src/PlutoSliderServer.jl @@ -4,7 +4,7 @@ using FromFile @from "./MoreAnalysis.jl" import bound_variable_connections_graph @from "./FileHelpers.jl" import find_notebook_files_recursive, list_files_recursive -@from "./IndexHTML.jl" import generate_index_html +@from "./IndexHTML.jl" import temp_index @from "./IndexJSON.jl" import generate_index_json @from "./Actions.jl" import process, should_shutdown, should_update, should_launch, will_process @@ -313,13 +313,7 @@ function run_directory( joinpath(output_dir, f) |> isfile end if !exists - write( - joinpath(output_dir, "index.html"), - generate_index_html(( - without_pluto_file_extension(s.path) => - without_pluto_file_extension(s.path) * ".html" for s in sessions - )), - ) + write(joinpath(output_dir, "index.html"), temp_index(sessions)) end # JSON From 2c95a23d8dba8c26303ac0e694fe2f6d38e702ae Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Tue, 13 Dec 2022 17:11:36 +0100 Subject: [PATCH 2/5] asdf --- src/IndexHTML.jl | 6 +++++- src/PlutoSliderServer.jl | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/IndexHTML.jl b/src/IndexHTML.jl index d567ea8..c28274b 100644 --- a/src/IndexHTML.jl +++ b/src/IndexHTML.jl @@ -6,6 +6,7 @@ import Pluto: Pluto, without_pluto_file_extension @from "./Configuration.jl" import PlutoDeploySettings @from "./Types.jl" import NotebookSession, RunningNotebook +@from "./Export.jl" import try_get_exact_pluto_version function generate_basic_index_html(paths) @@ -56,7 +57,10 @@ function generate_index_html( featured_sources_js="[{url:`./pluto_export.json`}]", ) else - temp_index(sessions) + generate_basic_index_html(( + without_pluto_file_extension(s.path) => + without_pluto_file_extension(s.path) * ".html" for s in sessions + )) end end diff --git a/src/PlutoSliderServer.jl b/src/PlutoSliderServer.jl index ecde909..cfeb2e3 100644 --- a/src/PlutoSliderServer.jl +++ b/src/PlutoSliderServer.jl @@ -4,7 +4,7 @@ using FromFile @from "./MoreAnalysis.jl" import bound_variable_connections_graph @from "./FileHelpers.jl" import find_notebook_files_recursive, list_files_recursive -@from "./IndexHTML.jl" import temp_index +@from "./IndexHTML.jl" import generate_index_html @from "./IndexJSON.jl" import generate_index_json @from "./Actions.jl" import process, should_shutdown, should_update, should_launch, will_process @@ -313,7 +313,10 @@ function run_directory( joinpath(output_dir, f) |> isfile end if !exists - write(joinpath(output_dir, "index.html"), temp_index(sessions)) + write( + joinpath(output_dir, "index.html"), + generate_index_html(sessions; settings), + ) end # JSON From 283c779fc48be1b6b82401daeda8fdacdad70d61 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Wed, 14 Dec 2022 00:11:30 +0100 Subject: [PATCH 3/5] Update IndexHTML.jl --- src/IndexHTML.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/IndexHTML.jl b/src/IndexHTML.jl index c28274b..e05f0b6 100644 --- a/src/IndexHTML.jl +++ b/src/IndexHTML.jl @@ -52,7 +52,6 @@ function generate_index_html( Pluto.generate_index_html(; pluto_cdn_root=settings.Export.pluto_cdn_root, version=try_get_exact_pluto_version(), - featured_static=true, featured_direct_html_links=true, featured_sources_js="[{url:`./pluto_export.json`}]", ) From 3108850ed59066f09bed9394436c91c0b5e9a0eb Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Wed, 14 Dec 2022 00:26:52 +0100 Subject: [PATCH 4/5] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index e8b3fe2..656ec84 100644 --- a/Project.toml +++ b/Project.toml @@ -34,7 +34,7 @@ GitHubActions = "0.1" Glob = "1" HTTP = "^1.0.2" JSON = "0.21" -Pluto = "0.19.17" +Pluto = "0.19.18" TerminalLoggers = "0.1" julia = "1.6" From aed813a3398e17347ebdb12c1347085ebe2c9433 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Wed, 14 Dec 2022 17:07:26 +0100 Subject: [PATCH 5/5] add test --- test/static export.jl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test/static export.jl b/test/static export.jl index 04a22ba..8dc5c4d 100644 --- a/test/static export.jl +++ b/test/static export.jl @@ -155,7 +155,7 @@ end end -@testset "static - Index HTML and JSON" begin +@testset "static - Index HTML and JSON – fancy=$(fancy)" for fancy ∈ (false, true) test_dir = make_test_dir() @show test_dir cache_dir @@ -163,7 +163,11 @@ end @test sort(list_files_recursive()) == sort(["a.jl", "b.pluto.jl", "notanotebook.jl", "subdir/c.plutojl"]) - export_directory(Export_cache_dir=cache_dir, Export_baked_state=false) + export_directory( + Export_cache_dir=cache_dir, + Export_baked_state=false, + Export_create_pluto_featured_index=fancy, + ) @test sort(list_files_recursive()) == sort([ "index.html", @@ -185,10 +189,17 @@ end jsonstr = read("pluto_export.json", String) json = JSON.parse(jsonstr) + if fancy + @test occursin("", htmlstr) + @test occursin("pluto_export.json", htmlstr) + end + nbs = ["subdir/c.plutojl", "b.pluto.jl", "a.jl"] for (i, p) in enumerate(nbs) - @test occursin(p |> without_pluto_file_extension, htmlstr) @test occursin(p, jsonstr) + if !fancy + @test occursin(p |> without_pluto_file_extension, htmlstr) + end @test !isempty(json["notebooks"][p]["frontmatter"]["title"]) without_pluto_file_extension