Skip to content

Add keep_path global variable (#759) #760

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

Merged
merged 1 commit into from
Jan 10, 2021
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
18 changes: 15 additions & 3 deletions src/manager/dir_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ function form_output_path(base::AS, file::AS, case::Symbol)
case == :md && (file = change_ext(file))
outbase = _out_path(base)
if case in (:md, :html)
# file is index.html or 404.html --> keep the path
# file is index.html or 404.html or in keep_path --> keep the path
# file is page.html --> .../page/index.html
fname = splitext(file)[1]
if fname ∉ ("index", "404") && !endswith(fname, "/index")
if fname ∉ ("index", "404") && !endswith(fname, "/index") && !_keep_path(base, fname)
file = joinpath(fname, "index.html")
end
end
Expand Down Expand Up @@ -62,6 +62,18 @@ function _out_path(base::String)::String
return outpath
end

function _keep_path(base, fname)::Bool
rpath = get_rpath(joinpath(base, fname))
keep = globvar(:keep_path)::Vector{String}
isempty(keep) && return false
files = [f for f in keep if endswith(f, ".html")]
dirs = [d for d in keep if endswith(d, "/")]
spath = rpath * ".html"
any(f -> f == spath, files) && return true
any(d -> startswith(spath, d), dirs) && return true
return false
end

"""
$(SIGNATURES)

Expand Down Expand Up @@ -151,7 +163,7 @@ function _scan_input_dir!(other_files::TrackedFiles,
if file == "config.md"
add_if_new_file!(infra_files, opts...)
elseif file == "utils.jl"
add_if_new_file!(infra_files, opts...)
add_if_new_file!(infra_files, opts...)
elseif fext == ".md"
add_if_new_file!(md_pages, opts...)
elseif fext ∈ (".html", ".htm")
Expand Down
2 changes: 2 additions & 0 deletions src/utils/vars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const GLOBAL_VARS_DEFAULT = [
"tag_page_path" => dpair("tag"),
# will be added to IGNORE_FILES
"ignore" => Pair(String[], (Vector{Any},)),
# don't insert `index.html` at the end of the path for these files
"keep_path" => Pair(String[], (Vector{String},)),
# for robots.txt
"robots_disallow" => Pair(String[], (Vector{String},)),
"generate_robots" => dpair(true),
Expand Down