Skip to content

Commit 01cf7c1

Browse files
authored
Make DocumenterVitepress.deploydocs more robust + various other fixes (#257)
- Fix error when trying to read nonexistent `.vitepress/config.mts`. - Pass `deploydocs` keyword arguments through correctly - Respect the `dirname` keyword to deploydocs - Compute the root directory in `DV.deploydocs` and pass it down to Documenter, so that relative `target` paths work. - Add the correct path to the Github Actions post status JSON that Documenter pushes, by invoking it ourselves after all deployments. - Log info statements, not warnings, when filling in missing Vitepress config files. - Fix a bug where the `@ansi` block errored when in draft mode.
1 parent 503d826 commit 01cf7c1

File tree

6 files changed

+71
-28
lines changed

6 files changed

+71
-28
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## v0.2.1 - 2025-05-15
4+
Bug fix release after v0.2.0 - now, namespacing deploydocs as `DocumenterVitepress.deploydocs` should "just work".
5+
6+
- Fix error when trying to read nonexistent `.vitepress/config.mts`.
7+
- Pass `deploydocs` keyword arguments through correctly
8+
- Respect the `dirname` keyword to deploydocs
9+
- Compute the root directory in `DV.deploydocs` and pass it down to Documenter, so that relative `target` paths work.
10+
- Add the correct path to the Github Actions post status JSON that Documenter pushes, by invoking it ourselves after all deployments.
11+
- Log info statements, not warnings, when filling in missing Vitepress config files.
12+
- Fix a bug where the `@ansi` block errored when in draft mode.
13+
314
## v0.2.0 - 2025-05-14
415

516
- **Breaking**: `makedocs` now renders a separate build for each `base` needed by vitepress, for example `v1.2.3`, `v1.2`, `v1` and `stable`. This fixes problems stemming from the non-relocatability of vitepress sites (the base they have been rendered for must be the same as where it is deployed). Because the structure of the `build` folder changes and now contains subfolders which must be deployed separately, `Documenter.deploydocs` cannot be used anymore. Instead, use the function of similar name `DocumenterVitepress.deploydocs` which wraps Documenter's function in a way that handles the multi-folder setup correctly [#246](https://github.com/LuxDL/DocumenterVitepress.jl/pull/246). You will also have to delete every symlink on the `gh-pages` branch which Documenter has written and which you want to deploy to using DocumenterVitepress, for example `stable` will be a symlink but needs to be removed before DocumenterVitepress can render to an actual directory there. For more information check the README.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DocumenterVitepress"
22
uuid = "4710194d-e776-4893-9690-8d956a29c365"
33
authors = ["Lazaro Alonso <[email protected]>", "Anshul Singhvi <[email protected]>"]
4-
version = "0.2.0"
4+
version = "0.2.1"
55

66
[deps]
77
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ pkg> add DocumenterVitepress
2525
To enable the backend:
2626
1. Add `DocumenterVitepress` to your `docs` environment using Pkg
2727
2. Add `using DocumenterVitepress` in `docs/make.jl`,
28-
3. Pass `format = DocumenterVitepress.MarkdownVitepress(...)` to `makedocs` like so, replacing e.g. `format = HTML(...)`:
28+
3. Pass `format = DocumenterVitepress.MarkdownVitepress(...)` to `makedocs` like so, replacing e.g. `format = HTML(...)`.
29+
30+
(Make sure you also see the "Deploying" section below.)
2931

3032
```julia
3133
using Documenter

src/ANSIBlocks.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Selectors.runner(::Type{ANSIBlocks}, node, page, doc)
2020
# Bail early if in draft mode
2121
if Documenter.is_draft(doc, page)
2222
@debug "Skipping evaluation of @ansi block in draft mode:\n$(x.code)"
23-
page.mapping[x] = create_draft_result(x; blocktype="@ansi")
23+
page.mapping[x] = Documenter.create_draft_result(x; blocktype="@ansi")
2424
return
2525
end
2626

src/DocumenterVitepress.jl

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ function Documenter.postprocess_before_push(versions::BaseVersion; subfolder, de
111111
end
112112

113113
"""
114-
deploydocs(; repo, target, branch, devbranch, push_preview)
114+
deploydocs(; repo, target, branch, devbranch, push_preview, kwargs...)
115115
116116
Deploy the documentation built with DocumenterVitepress.
117117
118+
The `repo` keyword argument is required, all others are optional and default to
119+
the defaults of `Documenter.deploydocs` (see its documentation for more details).
120+
118121
This function only shares a name with `Documenter.deploydocs`, it should
119122
therefore be invoked with `DocumenterVitepress.deploydocs`. Because of
120123
DocumenterVitepress's need to build a separate website for each base alias
@@ -123,13 +126,21 @@ does not work with the default settings. This function offers a wrapper over
123126
`Documenter.deploydocs` which deploys each separate build in sequence.
124127
"""
125128
function deploydocs(;
129+
root = Documenter.currentdir(),
126130
repo,
127-
target,
128-
branch,
129-
devbranch,
130-
push_preview,
131+
target = "build",
132+
dirname = "",
133+
kwargs...
131134
)
132-
bases_file = joinpath(target, "bases.txt")
135+
136+
if haskey(kwargs, :versions)
137+
error("""
138+
`DocumenterVitepress.deploydocs` does not support the `versions` keyword argument;
139+
Instead, amend the `deploy_decision` you pass into `MarkdownVitepress`.
140+
""")
141+
end
142+
143+
bases_file = joinpath(root, target, "bases.txt")
133144
if !isfile(bases_file)
134145
error("Expected a file at $bases_file listing the separate bases that DocumenterVitepress has built the docs for.")
135146
end
@@ -140,16 +151,29 @@ function deploydocs(;
140151
dir = joinpath(target, "$i")
141152
@info "Deploying docs for base $(repr(base)) from $dir"
142153
Documenter.deploydocs(;
154+
root,
143155
repo,
144156
target = dir, # each version built has its own dir
145-
versions = DocumenterVitepress.BaseVersion(base),
146-
dirname = base,
147-
branch,
148-
devbranch,
149-
push_preview,
157+
versions = DocumenterVitepress.BaseVersion(base), # the base version
158+
dirname = isempty(dirname) ? base : joinpath(dirname, base), # the dirname to use
159+
kwargs...
150160
)
151161
end
152162

163+
first_version = last(bases)
164+
isempty(first_version) && return
165+
166+
# Push the correct version to the GH Actions documenter/deploy action.
167+
# If we have reached this point, then the build was a success, so we can push
168+
# the "success" type of result.
169+
try
170+
deploy_config = Documenter.auto_detect_deploy_system()
171+
Documenter.post_status(deploy_config; type = "success", repo = repo, subfolder = first_version)
172+
catch e
173+
@warn "DocumenterVitepress: Error while pushing status to CI"
174+
rethrow(e)
175+
end
176+
153177
end
154178

155179
end

src/vitepress_config.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,47 @@ function modify_config_file(doc, settings, deploy_decision, i_folder, base)
2727

2828
# Main.@infiltrate
2929
# Read in the config file,
30-
30+
# First, we establish paths to some useful directories, so that we can use them later.
3131
builddir = isabspath(doc.user.build) ? doc.user.build : joinpath(doc.user.root, doc.user.build)
3232
sourcedir = isabspath(doc.user.source) ? doc.user.source : joinpath(doc.user.root, doc.user.source)
3333
source_vitepress_dir = joinpath(sourcedir, ".vitepress")
3434
build_vitepress_dir = normpath(joinpath(builddir, settings.md_output_path, ".vitepress"))
3535
template_vitepress_dir = joinpath(dirname(@__DIR__), "template", "src", ".vitepress")
36-
mkpath(joinpath(builddir, settings.md_output_path, ".vitepress", "theme"))
37-
vitepress_config_file = joinpath(sourcedir, ".vitepress", "config.mts") # We check the source dir here because `clean=false` will persist the old, non-generated file in the build dir, and we need to overwrite it.
36+
37+
# Make the theme directory
38+
mkpath(joinpath(build_vitepress_dir, "theme"))
39+
40+
# Check for the config file
41+
vitepress_config_file = joinpath(source_vitepress_dir, "config.mts") # We check the source dir here because `clean=false` will persist the old, non-generated file in the build dir, and we need to overwrite it.
3842
if !isfile(vitepress_config_file)
3943
mkpath(splitdir(vitepress_config_file)[1])
40-
@warn "DocumenterVitepress: Did not detect `docs/src/.vitepress/config.mts` file. Substituting in the default file."
44+
@info "DocumenterVitepress: Did not detect `docs/src/.vitepress/config.mts` file. Substituting in the default file."
4145
# We use `write` instead of `cp` here, because `cp`'ed files inherit the permissions of the source file,
4246
# which may not be writable. However, `write` creates a new file for which Julia must have write permissions.
4347
write(joinpath(build_vitepress_dir, "config.mts"), read(joinpath(template_vitepress_dir, "config.mts"), String))
48+
else # the user has provided a config file
49+
# Sometimes this file can get corrupted by makedocs(clean=false),
50+
# so we need to copy it over again.
51+
write(joinpath(build_vitepress_dir, "config.mts"), read(vitepress_config_file, String))
4452
end
4553

4654
# ? theme / check for index.ts, style.css and docstrings.css files
4755
if !isfile(joinpath(source_vitepress_dir, "theme", "index.ts"))
48-
@warn "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/index.ts` file. Substituting in the default file."
56+
@info "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/index.ts` file. Substituting in the default file."
4957
write(joinpath(build_vitepress_dir, "theme", "index.ts"), read(joinpath(template_vitepress_dir, "theme", "index.ts"), String))
5058
end
5159
if !isfile(joinpath(source_vitepress_dir, "theme", "style.css"))
52-
@warn "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/style.css` file. Substituting in the default file."
60+
@info "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/style.css` file. Substituting in the default file."
5361
write(joinpath(build_vitepress_dir, "theme", "style.css"), read(joinpath(template_vitepress_dir, "theme", "style.css"), String))
5462
end
5563
if !isfile(joinpath(source_vitepress_dir, "theme", "docstrings.css"))
56-
@warn "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/docstrings.css` file. Substituting in the default file."
64+
@info "DocumenterVitepress: Did not detect `docs/src/.vitepress/theme/docstrings.css` file. Substituting in the default file."
5765
write(joinpath(build_vitepress_dir, "theme", "docstrings.css"), read(joinpath(template_vitepress_dir, "theme", "docstrings.css"), String))
5866
end
59-
# reset the path to the variable that exists
60-
vitepress_config_file_template = joinpath(source_vitepress_dir, "config.mts") # We check the source dir here because `clean=false` will persist the old, non-generated file in the build dir, and we need to overwrite it.
61-
vitepress_config_file = joinpath(build_vitepress_dir, "config.mts") # We check the source dir here because `clean=false` will persist the old, non-generated file in the build dir, and we need to overwrite it.
62-
63-
config = read(vitepress_config_file_template, String)
67+
# We have already rewritten the config file, so we can't get burned by clean=false
68+
# again.
69+
vitepress_config_file = joinpath(build_vitepress_dir, "config.mts")
70+
config = read(vitepress_config_file, String)
6471
replacers = Vector{Pair{<: Union{AbstractString, Regex}, <: AbstractString}}()
6572

6673

@@ -148,8 +155,7 @@ function modify_config_file(doc, settings, deploy_decision, i_folder, base)
148155
yield()
149156
touch(vitepress_config_file)
150157

151-
#
152-
158+
return
153159
end
154160

155161
function _get_raw_text(element)

0 commit comments

Comments
 (0)