Skip to content

Commit

Permalink
Make things work with LiveServer (#164)
Browse files Browse the repository at this point in the history
* Make things work with LiveServer

* Add force as an option in devdocs

* Kwargs go after main arg...

* bump version

* touch the file

* Touch properly

* Normpath correctly
  • Loading branch information
asinghvi17 authored Jun 30, 2024
1 parent ef3bc2d commit f29f8a5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DocumenterVitepress"
uuid = "4710194d-e776-4893-9690-8d956a29c365"
authors = ["Lazaro Alonso <lazarus.alon@gmail.com>", "Anshul Singhvi <as6208@columbia.edu>"]
version = "0.1.1"
version = "0.1.2"

[deps]
ANSIColoredPrinters = "a4c015fc-c6ff-483c-b24f-f7ea428134e9"
Expand Down
5 changes: 3 additions & 2 deletions src/vitepress_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function modify_config_file(doc, settings, deploy_decision)
builddir = isabspath(doc.user.build) ? doc.user.build : joinpath(doc.user.root, doc.user.build)
sourcedir = isabspath(doc.user.source) ? doc.user.source : joinpath(doc.user.root, doc.user.source)
source_vitepress_dir = joinpath(sourcedir, ".vitepress")
build_vitepress_dir = joinpath(builddir, settings.md_output_path, ".vitepress")
build_vitepress_dir = normpath(joinpath(builddir, settings.md_output_path, ".vitepress"))
template_vitepress_dir = joinpath(dirname(@__DIR__), "template", "src", ".vitepress")
mkpath(joinpath(builddir, settings.md_output_path, ".vitepress", "theme"))
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.
Expand Down Expand Up @@ -128,7 +128,8 @@ function modify_config_file(doc, settings, deploy_decision)

new_config = replace(config, replacers...)
write(vitepress_config_file, new_config)

yield()
touch(vitepress_config_file)

#

Expand Down
6 changes: 3 additions & 3 deletions src/vitepress_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Work is in progress to let the user pass the config object to fix this.
This does **NOT** run `makedocs` - you have to do that yourself!
Think of it as the second stage of `LiveServer.jl` for DocumenterVitepress specifically.
"""
dev_docs(builddir::String; md_output_path = ".documenter") = run_vitepress_command(builddir, "dev"; md_output_path)
dev_docs(builddir::String; md_output_path = ".documenter") = run_vitepress_command(builddir, "dev"; md_output_path, kwargs = `--force`)

"""
build_docs(builddir::String; md_output_path = ".documenter")
Expand All @@ -25,7 +25,7 @@ If passing a String, pass the path to the `builddir`, i.e., `\$packagepath/docs/
build_docs(builddir::String; md_output_path = ".documenter") = run_vitepress_command(builddir, "build"; md_output_path)


function run_vitepress_command(builddir::String, command::String; md_output_path = ".documenter")
function run_vitepress_command(builddir::String, command::String; md_output_path = ".documenter", kwargs = ``)
@assert ispath(builddir)
builddir = abspath(builddir)
@info "DocumenterVitepress: running `vitepress $command`."
Expand All @@ -50,7 +50,7 @@ function run_vitepress_command(builddir::String, command::String; md_output_path
end
run(`$(npm) install`)
end
run(`$(npm) run env -- vitepress $command $(joinpath(splitpath(builddir)[end], md_output_path))`)
run(`$(npm) run env -- vitepress $command $(normpath(joinpath(splitpath(builddir)[end], md_output_path))) $(kwargs)`)
end
end
catch e
Expand Down
67 changes: 42 additions & 25 deletions src/writer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@ where `Eltype` is the type of the `element` field of the `node` object which you
"""
function render(doc::Documenter.Document, settings::MarkdownVitepress=MarkdownVitepress())
@info "DocumenterVitepress: rendering MarkdownVitepress pages."

# We manually obtain the Documenter deploy configuration,
# so we can use it to set Vitepress's settings.
if settings.deploy_decision === nothing
# TODO: make it so that the user does not have to provide a repo url!
deploy_config = Documenter.auto_detect_deploy_system()
deploy_decision = Documenter.deploy_folder(
deploy_config;
repo = settings.repo, # this must be the full URL!
devbranch = settings.devbranch,
devurl = settings.devurl,
push_preview=true,
)
else
deploy_decision = settings.deploy_decision
end

# copy_assets(doc, settings.md_output_path)
# Handle the case where the site name has to be set...
mime = MIME"text/plain"() # TODO: why?
Expand All @@ -110,12 +127,22 @@ function render(doc::Documenter.Document, settings::MarkdownVitepress=MarkdownVi
# Then, we create a path to the folder where we will emit the markdown,
mkpath(joinpath(builddir, settings.md_output_path))
# and copy the previous build files to the new location.
for file_or_dir in current_build_files_or_dirs
src = joinpath(builddir, file_or_dir)
dst = joinpath(builddir, settings.md_output_path, file_or_dir)
cp(src, dst)
rm(src; recursive = true)
if settings.md_output_path != "."
for file_or_dir in current_build_files_or_dirs
src = joinpath(builddir, file_or_dir)
dst = joinpath(builddir, settings.md_output_path, file_or_dir)
if src != dst
cp(src, dst; force = true)
rm(src; recursive = true)
else
println(src, dest)
end
end
end

# from `vitepress_config.jl`
modify_config_file(doc, settings, deploy_decision)

# Documenter.jl wants assets in `assets/`, but Vitepress likes them in `public/`,
# so we rename the folder.
if isdir(joinpath(sourcedir, "assets")) && !isdir(joinpath(sourcedir, "public"))
Expand All @@ -126,13 +153,19 @@ function render(doc::Documenter.Document, settings::MarkdownVitepress=MarkdownVi
if any(logo_files)
for file in files[logo_files]
file_relpath = relpath(file, joinpath(builddir, settings.md_output_path, "assets"))
cp(file, joinpath(builddir, settings.md_output_path, "public", file_relpath))
file_destpath = joinpath(builddir, settings.md_output_path, "public", file_relpath)
if normpath(file) != normpath(file_destpath)
cp(file, file_destpath; force = true)
end
end
end
if any(favicon_files)
for file in files[favicon_files]
file_relpath = relpath(file, joinpath(builddir, settings.md_output_path, "assets"))
cp(file, joinpath(builddir, settings.md_output_path, "public", file_relpath))
file_destpath = joinpath(builddir, settings.md_output_path, "public", file_relpath)
if normpath(file) != normpath(file_destpath)
cp(file, file_destpath; force = true)
end
end
end
end
Expand All @@ -148,25 +181,9 @@ function render(doc::Documenter.Document, settings::MarkdownVitepress=MarkdownVi
end

mkpath(joinpath(builddir, "final_site"))

# We manually obtain the Documenter deploy configuration,
# so we can use it to set Vitepress's settings.
if settings.deploy_decision === nothing
# TODO: make it so that the user does not have to provide a repo url!
deploy_config = Documenter.auto_detect_deploy_system()
deploy_decision = Documenter.deploy_folder(
deploy_config;
repo = settings.repo, # this must be the full URL!
devbranch = settings.devbranch,
devurl = settings.devurl,
push_preview=true,
)
else
deploy_decision = settings.deploy_decision
if isfile(joinpath(builddir, settings.md_output_path, ".vitepress", "config.mts"))
touch(joinpath(builddir, settings.md_output_path, ".vitepress", "config.mts"))
end

# from `vitepress_config.jl`
modify_config_file(doc, settings, deploy_decision)

# Now that the Markdown files are written, we can build the Vitepress site if required.
if settings.build_vitepress
Expand Down

0 comments on commit f29f8a5

Please sign in to comment.