Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to use Pluto's Featured GUI as index html #100

Merged
merged 6 commits into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion src/Actions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,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,
Expand Down
2 changes: 2 additions & 0 deletions src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/HTTPRouter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 22 additions & 2 deletions src/IndexHTML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ 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_index_html(paths)
function generate_basic_index_html(paths)
"""
<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -43,10 +44,29 @@ 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_direct_html_links=true,
featured_sources_js="[{url:`./pluto_export.json`}]",
)
else
generate_basic_index_html((
without_pluto_file_extension(s.path) =>
without_pluto_file_extension(s.path) * ".html" for s in 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
Expand Down
8 changes: 6 additions & 2 deletions src/IndexJSON.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 1 addition & 4 deletions src/PlutoSliderServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,7 @@ function run_directory(
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
)),
generate_index_html(sessions; settings),
)
end

Expand Down
17 changes: 14 additions & 3 deletions test/static export.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,19 @@ 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
cd(test_dir)
@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",
Expand All @@ -185,10 +189,17 @@ end
jsonstr = read("pluto_export.json", String)
json = JSON.parse(jsonstr)

if fancy
@test occursin("</html>", 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
Expand Down