diff --git a/Project.toml b/Project.toml index d05a9604..5d58a281 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DemoCards" uuid = "311a05b2-6137-4a5a-b473-18580a3d38b5" authors = ["Johnny Chen "] -version = "0.4.10" +version = "0.4.11" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -19,7 +19,7 @@ YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" [compat] Documenter = "0.22, 0.23, 0.24, 0.25, 0.26, 0.27" -Pluto = "^0.19" +Pluto = "^0.19.13" PlutoStaticHTML = "^6" FileIO = "1" HTTP = "0.6, 0.7, 0.8, 0.9, 1" diff --git a/src/types/pluto.jl b/src/types/pluto.jl index 15762927..dc91da4e 100644 --- a/src/types/pluto.jl +++ b/src/types/pluto.jl @@ -122,19 +122,16 @@ function save_democards(card_dir::AbstractString, # copy to card dir and do things cardname = splitext(basename(card.path))[1] - curr_dir = pwd() - src_dir = dirname(card.path) # pluto outputs are expensive, we save the output to a cache dir # these cache dir contains the render files from previous runs, # saves time, while rendering - render_dir = joinpath(src_dir, "..", "..", "pluto_output") |> abspath + render_dir = joinpath(project_dir, "pluto_output") |> abspath isdir(render_dir) || mkpath(render_dir) nb_path = joinpath(card_dir, "$(cardname).jl") - card_path = joinpath(card_dir, "$(cardname).md") + md_path = joinpath(card_dir, "$(cardname).md") - _, _, body = split_pluto_frontmatter(readlines(card.path)) - write(nb_path, join(body, "\n")) + cp(card.path, nb_path) if VERSION < card.julia # It may work, it may not work; I hope it would work. @@ -146,23 +143,25 @@ function save_democards(card_dir::AbstractString, bopts = BuildOptions(card_dir;previous_dir=render_dir, output_format=output_format) # don't run notebooks in parallel + # TODO: User option to run it parallel or not build_notebooks(bopts, ["$(cardname).jl"], oopts) - cache_path = joinpath(render_dir, basename(card_path)) - cp(card_path, cache_path; force=true) + # move rendered files to cache + cache_path = joinpath(render_dir, basename(md_path)) + cp(md_path, cache_path; force=true) badges = make_badges(card; src=src, card_dir=card_dir, nbviewer_root_url=nbviewer_root_url, project_dir=project_dir, - build_notebook=false) + build_notebook=false) header = "# [$(card.title)](@id $(card.id))\n" footer = pluto_footer - body = join(readlines(card_path), "\n") - write(card_path, header, badges * "\n\n", body, footer) + body = join(readlines(md_path), "\n") + write(md_path, header, badges * "\n\n", body, footer) return nothing end diff --git a/src/utils.jl b/src/utils.jl index fb132771..ab5ac616 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -143,28 +143,6 @@ function get_regex(::Val{:Markdown}, regex_type) end end - -function get_regex(::Val{:Pluto}, regex_type) - if regex_type == :image - # Example: ![title](path) - return r"^\s*!\[(?[^\]]*)\]\((?<path>[^\s]*)\)" - elseif regex_type == :title - # Example: # [title](@id id) - regex_title = r"md[\"]{1,3}.*\n#\s(\S.*)\n" - # Example: # title - regex_simple_title = r"md[\"]{1,3}.*\n#\s(\S.*)\n" - - # Note: return the complete one first - return (regex_title, regex_simple_title) - elseif regex_type == :content - # lines that are not title, image, link, list - # FIXME: list is also captured by this regex - return r"^\s*(?<content>[^#\-*!].*)" - else - error("Unrecognized regex type: $(regex_type)") - end -end - function get_regex(::Val{:Julia}, regex_type) if regex_type == :image # Example: #md ![title](path) @@ -213,8 +191,8 @@ Currently supported items are: `title`, `id`, `cover`, `description`. function parse(T::Val, card::AbstractDemoCard) # TODO: generalize if T === Val(:Pluto) - header, frontmatter, body = split_pluto_frontmatter(readlines(card.path)) - config = parse(T, body) # should ideally not pickup + frontmatter = [] + config = Pluto.frontmatter(card.path) else header, frontmatter, body = split_frontmatter(readlines(card.path)) config = parse(T, body) @@ -370,28 +348,6 @@ function split_frontmatter(contents::AbstractArray{<:AbstractString}) end -# special case, generalize it with rest of functions later -function split_pluto_frontmatter(contents) - first_cell_regex = r"#\s╔═╡\sCell\sorder:\n#\s?[╠╟][─═]\s?([0-9a-f\-]{36})" - content = join(contents, "\n") - first_cell_id = match(first_cell_regex, content)[1] - m1 = r"#\s╔═╡\s" - m2 = Regex("$(first_cell_id)\n") - m3 = r"""md\"\"\"\n([\s\S]*?)\"\"\"""" - first_cell_regex = m1 * m2 * m3 - frontmatter = match(first_cell_regex, content)[1] - frontmatter = split(frontmatter, "\n") |> Vector{String} - content_id_repr = r"#\s?[╠╟][─═]\s?" * Regex("$(first_cell_id)") - - offset = map(contents) do line - m = match(content_id_repr, line) - m isa RegexMatch - end |> findlast - - return String[], frontmatter, vcat(contents[1:offset-1], contents[offset+1:end]) -end - - function get_default_title(x::Union{AbstractDemoCard, DemoSection, DemoPage}) name_without_ext = splitext(basename(x))[1] strip(replace(uppercasefirst(name_without_ext), r"[_-]" => " "))