From 7783cf513c0ffada70a82dbff46a36dadb4f2b65 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 4 Aug 2023 18:44:42 +0200 Subject: [PATCH] Change EditURL output to use relative path This patch changes the generated EditURl to use a relative path (source file relative output directory) and let Documenter figure out the remote URL instead. This is required for Documenter version 1, but works also on older Documenter versions. --- src/Literate.jl | 18 +++--------------- test/runtests.jl | 14 +++++++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/src/Literate.jl b/src/Literate.jl index f511898..d650bc3 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -343,9 +343,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])" cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)" cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)" - if (dir = get(ENV, "TRAVIS_BUILD_DIR", nothing)) !== nothing - cfg["repo_root_path"] = dir - end elseif haskey(ENV, "GITHUB_ACTIONS") repo_slug = get(ENV, "GITHUB_REPOSITORY", "unknown-repository") deploy_folder = if get(ENV, "GITHUB_EVENT_NAME", nothing) == "push" @@ -362,9 +359,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])" cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)" cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)" - if (dir = get(ENV, "GITHUB_WORKSPACE", nothing)) !== nothing - cfg["repo_root_path"] = dir - end elseif haskey(ENV, "GITLAB_CI") if (url = get(ENV, "CI_PROJECT_URL", nothing)) !== nothing cfg["repo_root_url"] = "$(url)/blob/$(cfg["edit_commit"])" @@ -373,9 +367,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) (m = match(r"https://(.+)", url)) !== nothing cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/urls/$(m[1])" end - if (dir = get(ENV, "CI_PROJECT_DIR", nothing)) !== nothing - cfg["repo_root_path"] = dir - end end # Merge default_config with user_config @@ -423,9 +414,6 @@ Available options: - `binder_root_url`: URL to the root of the repository as seen on mybinder. Determined automatically on Travis CI, GitHub Actions and GitLab CI. Used for `@__BINDER_ROOT_URL__`. -- `repo_root_path`: Filepath to the root of the repository. Determined automatically on - Travis CI, GitHub Actions and GitLab CI. Used for computing - [Documenters `EditURL`](@ref Interaction-with-Documenter). - `image_formats`: A vector of `(mime, ext)` tuples, with the default `$(_DEFAULT_IMAGE_FORMATS)`. Results which are `showable` with a MIME type are saved with the first match, with the corresponding extension. @@ -470,11 +458,11 @@ function preprocessor(inputfile, outputdir; user_config, user_kwargs, type) # run some Documenter specific things for markdown output if type === :md && isdocumenter(config) # change the Edit on GitHub link - path = relpath(inputfile, get(config, "repo_root_path", pwd())::String) - path = replace(path, "\\" => "/") + edit_url = relpath(inputfile, config["literate_outputdir"]) + edit_url = replace(edit_url, "\\" => "/") content = """ # ```@meta - # EditURL = "@__REPO_ROOT_URL__/$(path)" + # EditURL = "$(edit_url)" # ``` """ * content diff --git a/test/runtests.jl b/test/runtests.jl index 88954b9..c31c32b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -515,7 +515,7 @@ end end end expected_markdown = """ ```@meta - EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl" + EditURL = "../inputfile.jl" ``` # [Example](@id example-id) @@ -645,7 +645,7 @@ end end @test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl", markdown) @test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", markdown) - @test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # Travis with no tag -> dev directory withenv(TRAVIS_ENV..., @@ -656,7 +656,7 @@ end end @test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl", markdown) @test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown) - @test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # GitHub Actions with a tag withenv(ACTIONS_ENV...) do @@ -666,7 +666,7 @@ end end @test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl", markdown) @test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl", markdown) - @test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # GitHub Actions with PR preview build withenv(ACTIONS_ENV..., @@ -678,7 +678,7 @@ end end @test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl", markdown) @test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", markdown) - @test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # GitHub Actions without a tag -> dev directory withenv(ACTIONS_ENV..., @@ -689,7 +689,7 @@ end end @test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl", markdown) @test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown) - @test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # GitLab CI with GitLab Pages withenv(GITLAB_ENV...) do @@ -699,7 +699,7 @@ end end @test occursin("Link to repo root: https://gitlab.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown) @test occursin("Link to nbviewer: https://nbviewer.jupyter.org/urls/fredrikekre.gitlab.io/Literate.jl/file.jl", markdown) @test_broken occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown) - @test occursin("EditURL = \"https://gitlab.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown) + @test occursin("EditURL = \"../inputfile.jl\"", markdown) # building under DocumentationGenerator.jl withenv("DOCUMENTATIONGENERATOR" => "true",