Skip to content
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

Make things work with LiveServer #164

Merged
merged 7 commits into from
Jun 30, 2024
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
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 @@
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 @@ -108,7 +108,7 @@
if isfile(joinpath(doc.user.build, settings.md_output_path, "public", "logo.png"))
push!(replacers, "logo: 'REPLACE_ME_DOCUMENTER_VITEPRESS'" => "logo: { src: '/logo.png', width: 24, height: 24}")
else
@warn "DocumenterVitepress: No logo.png file found in `docs/src/assets`. Skipping logo replacement."

Check warning on line 111 in src/vitepress_config.jl

View workflow job for this annotation

GitHub Actions / build

DocumenterVitepress: No logo.png file found in `docs/src/assets`. Skipping logo replacement.
push!(replacers, "logo: 'REPLACE_ME_DOCUMENTER_VITEPRESS'," => "")
end
end
Expand All @@ -128,7 +128,8 @@

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 @@
"""
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 @@
# 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 @@
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 @@
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 Expand Up @@ -679,7 +696,7 @@
# Code blocks
function render(io::IO, mime::MIME"text/plain", node::Documenter.MarkdownAST.Node, code::MarkdownAST.CodeBlock, page, doc; kwargs...)
if startswith(code.info, "@")
@warn """

Check warning on line 699 in src/writer.jl

View workflow job for this annotation

GitHub Actions / build

DocumenterVitepress: un-expanded `@doctest` block encountered on page src/code_example.md. The first few lines of code in this node are: ``` julia> 1 + 1 2 ```
DocumenterVitepress: un-expanded `$(code.info)` block encountered on page $(page.source).
The first few lines of code in this node are:
```
Expand Down
Loading