Skip to content

Commit a196908

Browse files
authored
Support skip_files to ignore specific files. (#142)
1 parent c52b1ae commit a196908

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LiveServer"
22
uuid = "16fef848-5104-11e9-1b77-fb7a48bbb589"
33
authors = ["Jonas Asprion <jonas.asprion@gmx.ch", "Thibaut Lienart <tlienart@me.com>"]
4-
version = "0.9.0"
4+
version = "0.9.1"
55

66
[deps]
77
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"

src/server.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Append `/` to the path part of `url`; i.e., transform `a/b` to `a/b/` and `/a/b?
112112
"""
113113
function append_slash(url_str::AbstractString)
114114
uri = HTTP.URI(url_str)
115-
return string(endswith(uri.path, "/") ? uri : merge(uri; path = uri.path * "/"))
115+
return string(endswith(uri.path, "/") ? uri : HTTP.URI(uri; path = uri.path * "/"))
116116
end
117117

118118
"""

src/utils.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ function servedocs_callback!(
2222
path2makejl::AbstractString,
2323
literate::Union{Nothing,String},
2424
skip_dirs::Vector{String},
25+
skip_files::Vector{String},
2526
foldername::String,
2627
buildfoldername::String)
2728
# ignore things happening in the build folder (generated files etc)
2829
startswith(fp, joinpath(foldername, buildfoldername)) && return nothing
29-
# ignore things happening in any skip_dirs
30+
# ignore files skip_dirs and skip_files
3031
for dir in skip_dirs
3132
startswith(fp, dir) && return nothing
3233
end
34+
for file in skip_files
35+
fp == file && return nothing
36+
end
3337

3438
# if the file that was changed is the `make.jl` file, assume that maybe
3539
# new files have been generated and so refresh the vector of watched files
@@ -167,6 +171,7 @@ subfolder `docs`.
167171
`skip_dir=joinpath("docs","src","examples")`.
168172
* `skip_dirs=[]`: same as `skip_dir` but for a list of such dirs. Takes
169173
precedence over `skip_dir`.
174+
* `skip_files=[]`: a vector of files that should not trigger regeneration.
170175
* `foldername="docs"`: specify a different path for the content.
171176
* `buildfoldername="build"`: specify a different path for the build.
172177
* `makejl="make.jl"`: path of the script generating the documentation relative
@@ -182,6 +187,7 @@ function servedocs(;
182187
doc_env::Bool=false,
183188
skip_dir::String="",
184189
skip_dirs::Vector{String}=String[],
190+
skip_files::Vector{String}=String[],
185191
foldername::String="docs",
186192
buildfoldername::String="build",
187193
makejl::String="make.jl",
@@ -193,6 +199,8 @@ function servedocs(;
193199
if isempty(skip_dirs) && !isempty(skip_dir)
194200
skip_dirs = [skip_dir]
195201
end
202+
skip_dirs = abspath.(skip_dirs)
203+
skip_files = abspath.(skip_files)
196204

197205
path2makejl = joinpath(foldername, makejl)
198206

@@ -203,7 +211,7 @@ function servedocs(;
203211
docwatcher,
204212
fp -> servedocs_callback!(
205213
docwatcher, fp, path2makejl,
206-
literate, skip_dirs, foldername, buildfoldername
214+
literate, skip_dirs, skip_files, foldername, buildfoldername
207215
)
208216
)
209217

test/utils.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
include(abspath(makejl))
2424
@test readmake() == 1
2525

26-
def = (nothing, String[], "docs", "build")
26+
def = (nothing, String[], String[], "docs", "build")
2727

2828
# callback function
2929
dw = LS.SimpleWatcher()
@@ -107,7 +107,7 @@ end
107107
# callback function
108108
dw = LS.SimpleWatcher()
109109

110-
LS.servedocs_callback!(dw, makejl, makejl, "", String[], "site", "build")
110+
LS.servedocs_callback!(dw, makejl, makejl, "", String[], String[], "site", "build")
111111

112112
@test length(dw.watchedfiles) == 3
113113
@test dw.watchedfiles[1].path == joinpath("site", "make.jl")
@@ -118,14 +118,14 @@ end
118118

119119
# let's now remove `index2.md`
120120
rm(joinpath("site", "src", "index2.md"))
121-
LS.servedocs_callback!(dw, makejl, makejl, "", String[], "site", "build")
121+
LS.servedocs_callback!(dw, makejl, makejl, "", String[], String[], "site", "build")
122122

123123
# the file has been removed
124124
@test length(dw.watchedfiles) == 2
125125
@test readmake() == 3
126126

127127
# let's check there's an appropriate trigger for index
128-
LS.servedocs_callback!(dw, joinpath("site", "src", "index.md"), makejl, "", String[], "site", "build")
128+
LS.servedocs_callback!(dw, joinpath("site", "src", "index.md"), makejl, "", String[], String[], "site", "build")
129129
@test length(dw.watchedfiles) == 2
130130
@test readmake() == 4
131131

0 commit comments

Comments
 (0)