Skip to content

Commit e1c980a

Browse files
authored
Change EditURL output to use relative path (#219)
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.
1 parent 515cd34 commit e1c980a

2 files changed

Lines changed: 10 additions & 22 deletions

File tree

src/Literate.jl

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
343343
cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])"
344344
cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)"
345345
cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)"
346-
if (dir = get(ENV, "TRAVIS_BUILD_DIR", nothing)) !== nothing
347-
cfg["repo_root_path"] = dir
348-
end
349346
elseif haskey(ENV, "GITHUB_ACTIONS")
350347
repo_slug = get(ENV, "GITHUB_REPOSITORY", "unknown-repository")
351348
deploy_folder = if get(ENV, "GITHUB_EVENT_NAME", nothing) == "push"
@@ -362,9 +359,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
362359
cfg["repo_root_url"] = "https://github.com/$(repo_slug)/blob/$(cfg["edit_commit"])"
363360
cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/github/$(repo_slug)/blob/$(deploy_branch)/$(deploy_folder)"
364361
cfg["binder_root_url"] = "https://mybinder.org/v2/gh/$(repo_slug)/$(deploy_branch)?filepath=$(deploy_folder)"
365-
if (dir = get(ENV, "GITHUB_WORKSPACE", nothing)) !== nothing
366-
cfg["repo_root_path"] = dir
367-
end
368362
elseif haskey(ENV, "GITLAB_CI")
369363
if (url = get(ENV, "CI_PROJECT_URL", nothing)) !== nothing
370364
cfg["repo_root_url"] = "$(url)/blob/$(cfg["edit_commit"])"
@@ -373,9 +367,6 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing)
373367
(m = match(r"https://(.+)", url)) !== nothing
374368
cfg["nbviewer_root_url"] = "https://nbviewer.jupyter.org/urls/$(m[1])"
375369
end
376-
if (dir = get(ENV, "CI_PROJECT_DIR", nothing)) !== nothing
377-
cfg["repo_root_path"] = dir
378-
end
379370
end
380371

381372
# Merge default_config with user_config
@@ -423,9 +414,6 @@ Available options:
423414
- `binder_root_url`: URL to the root of the repository as seen on mybinder. Determined
424415
automatically on Travis CI, GitHub Actions and GitLab CI.
425416
Used for `@__BINDER_ROOT_URL__`.
426-
- `repo_root_path`: Filepath to the root of the repository. Determined automatically on
427-
Travis CI, GitHub Actions and GitLab CI. Used for computing
428-
[Documenters `EditURL`](@ref Interaction-with-Documenter).
429417
- `image_formats`: A vector of `(mime, ext)` tuples, with the default
430418
`$(_DEFAULT_IMAGE_FORMATS)`. Results which are `showable` with a MIME type are saved with
431419
the first match, with the corresponding extension.
@@ -470,11 +458,11 @@ function preprocessor(inputfile, outputdir; user_config, user_kwargs, type)
470458
# run some Documenter specific things for markdown output
471459
if type === :md && isdocumenter(config)
472460
# change the Edit on GitHub link
473-
path = relpath(inputfile, get(config, "repo_root_path", pwd())::String)
474-
path = replace(path, "\\" => "/")
461+
edit_url = relpath(inputfile, config["literate_outputdir"])
462+
edit_url = replace(edit_url, "\\" => "/")
475463
content = """
476464
# ```@meta
477-
# EditURL = "@__REPO_ROOT_URL__/$(path)"
465+
# EditURL = "$(edit_url)"
478466
# ```
479467
480468
""" * content

test/runtests.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ end end
515515
end
516516
expected_markdown = """
517517
```@meta
518-
EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl"
518+
EditURL = "../inputfile.jl"
519519
```
520520
521521
# [Example](@id example-id)
@@ -645,7 +645,7 @@ end end
645645
@test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
646646
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl", markdown)
647647
@test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", markdown)
648-
@test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
648+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
649649

650650
# Travis with no tag -> dev directory
651651
withenv(TRAVIS_ENV...,
@@ -656,7 +656,7 @@ end end
656656
@test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
657657
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl", markdown)
658658
@test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown)
659-
@test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
659+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
660660

661661
# GitHub Actions with a tag
662662
withenv(ACTIONS_ENV...) do
@@ -666,7 +666,7 @@ end end
666666
@test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
667667
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v1.2.0/file.jl", markdown)
668668
@test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=v1.2.0/file.jl", markdown)
669-
@test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
669+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
670670

671671
# GitHub Actions with PR preview build
672672
withenv(ACTIONS_ENV...,
@@ -678,7 +678,7 @@ end end
678678
@test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
679679
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/previews/PR42/file.jl", markdown)
680680
@test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=previews/PR42/file.jl", markdown)
681-
@test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
681+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
682682

683683
# GitHub Actions without a tag -> dev directory
684684
withenv(ACTIONS_ENV...,
@@ -689,7 +689,7 @@ end end
689689
@test occursin("Link to repo root: https://github.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
690690
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/file.jl", markdown)
691691
@test occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown)
692-
@test occursin("EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
692+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
693693

694694
# GitLab CI with GitLab Pages
695695
withenv(GITLAB_ENV...) do
@@ -699,7 +699,7 @@ end end
699699
@test occursin("Link to repo root: https://gitlab.com/fredrikekre/Literate.jl/blob/master/file.jl", markdown)
700700
@test occursin("Link to nbviewer: https://nbviewer.jupyter.org/urls/fredrikekre.gitlab.io/Literate.jl/file.jl", markdown)
701701
@test_broken occursin("Link to binder: https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/file.jl", markdown)
702-
@test occursin("EditURL = \"https://gitlab.com/fredrikekre/Literate.jl/blob/master/test/$(basename(sandbox))/inputfile.jl\"", markdown)
702+
@test occursin("EditURL = \"../inputfile.jl\"", markdown)
703703

704704
# building under DocumentationGenerator.jl
705705
withenv("DOCUMENTATIONGENERATOR" => "true",

0 commit comments

Comments
 (0)