Skip to content

Commit

Permalink
testing out relative link changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed May 16, 2024
1 parent 085d4a0 commit 239fbf8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 5 additions & 5 deletions docs/buildutils/relative_links.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ function make_relative(s, here)
end

"""
Replaces all absolute links in all html files in the __site folder with
Replaces all absolute links in all html files in the build folder with
relative links.
"""
function make_links_relative()
function make_links_relative(buildfolder)
invalid_relative_links = Dict{String,Pair{String,String}}()

function check_local_link!(invalid_relative_links, file_location, link)
link_without_id = replace(link, r"#[a-zA-Z0-9!_\-\(\)]*$" => "")
link_without_id = replace(link, r"#.*$" => "")
absolute_link = if startswith(link, "/")
replace(link_without_id, r"^/+" => "")
else
Expand All @@ -69,7 +69,7 @@ function make_links_relative()
!startswith(link, "data:") && !startswith(link, r"https?") && !startswith(link, "#")
end

cd("__site") do
cd(buildfolder) do
for (root, _, files) in walkdir(".")
path = join(splitpath(root)[2:end], "/")

Expand Down Expand Up @@ -128,7 +128,7 @@ function make_links_relative()
end

if !isempty(invalid_relative_links)
error("Found invalid relative links: \n$(join(invalid_relative_links, "\n"))")
@warn("Found invalid relative links: \n$(join(invalid_relative_links, "\n"))")
end

return
Expand Down
4 changes: 3 additions & 1 deletion docs/makedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ using Documenter.MarkdownAST
using Documenter.MarkdownAST: @ast
using DocumenterVitepress
using Markdown
# using Gumbo
# using AbstractTrees

# include("buildutils/deploydocs.jl")
# include("buildutils/relative_links.jl")
Expand Down Expand Up @@ -183,7 +185,7 @@ makedocs(;
# # at the time, link relatively within `stable` so that users don't accidentally
# # copy & paste versioned links if they started out on `stable`
# @info "Rewriting all absolute links as relative"
# make_links_relative()
# make_links_relative(joinpath("build", "final_site"))

# generate_redirects([
# "/reference/index.html" => "/examples/index.html",
Expand Down

0 comments on commit 239fbf8

Please sign in to comment.