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

Add url_prefix for JuliaMono and Mousetrap #263

Merged
merged 1 commit into from
Dec 9, 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
5 changes: 2 additions & 3 deletions defaults/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
<link rel="shortcut icon" type="image/png" href="/favicon.png"/>
<link rel="stylesheet" href="/style.css"/>
$if(mousetrap)$
<script src="/mousetrap.min.js"></script>
<script src="$url-prefix$/mousetrap.min.js"></script>
$endif$
<!-- TODO: Add url_prefix. -->
<style>
@font-face {
font-family: JuliaMono-Regular;
src: url("/JuliaMono-Regular.woff2");
src: url("$url-prefix$/JuliaMono-Regular.woff2");
}
</style>
$for(header-includes)$
Expand Down
16 changes: 9 additions & 7 deletions src/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function verify_cross_references(h)
end
end

function pandoc_html(project::AbstractString; fail_on_error=false)
function _pandoc_html(project::AbstractString, url_prefix::AbstractString; fail_on_error=false)
input_path = write_input_markdown(project)
copy_extra_directories(project)
html_template_path = pandoc_file("template.html")
Expand All @@ -195,7 +195,7 @@ function pandoc_html(project::AbstractString; fail_on_error=false)
copy_mousetrap()
copy_juliamono()

args = [
args = String[
input_path;
crossref;
citeproc;
Expand All @@ -206,8 +206,10 @@ function pandoc_html(project::AbstractString; fail_on_error=false)
metadata;
template;
extra_args;
# The url_prefix is either "" or startswith '/'.
"--variable=url-prefix:$url_prefix";
# output
]::Vector{String}
]
_, out = call_pandoc(args)
if fail_on_error
verify_cross_references(out)
Expand Down Expand Up @@ -280,11 +282,11 @@ function html(; project="default", extra_head="", fail_on_error=false, build_sit
if config(project, "highlight")::Bool
extra_head = extra_head * highlight(url_prefix)
end
h = pandoc_html(project; fail_on_error)
h = _pandoc_html(project, url_prefix; fail_on_error)
if build_sitemap
sitemap(project, h)
end
write_html_pages(url_prefix, h, extra_head)
return write_html_pages(url_prefix, h, extra_head)
end

"""
Expand All @@ -296,14 +298,14 @@ However, the user can show the homepage also to offline visitors via the configu
function ignore_homepage(project, input_paths)
c = config(project)
override::Bool = config(project, "include_homepage_outside_html")
override ? input_paths : input_paths[2:end]
return override ? input_paths : input_paths[2:end]
end

function juliamono_path()
artifact = Artifacts.artifact"JuliaMono"
dir = joinpath(artifact, "juliamono-$JULIAMONO_VERSION")
# The forward slash is required by LaTeX.
dir * '/'
return dir * '/'
end
const JULIAMONO_PATH = juliamono_path()

Expand Down
9 changes: 5 additions & 4 deletions test/build.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@testset "build" begin
docs_dir = joinpath(Books.PROJECT_ROOT, "docs")
url_prefix = ""
out = cd(docs_dir) do
test_markdown_path = joinpath(docs_dir, "contents", "test.md")
test_markdown = raw"""
Expand All @@ -16,7 +17,7 @@

mkpath(joinpath(Books.BUILD_DIR, "images"))
gen("test"; project="test")
out = Books.pandoc_html("test")
out = Books._pandoc_html("test", url_prefix)
return out
end

Expand Down Expand Up @@ -48,13 +49,13 @@
mkpath(joinpath(Books.BUILD_DIR, "images"))
gen("test"; project="test")
try
Books.pandoc_html("test"; fail_on_error=true)
error("Expected pandoc_html to fail.")
Books._pandoc_html("test", url_prefix; fail_on_error=true)
error("Expected _pandoc_html to fail.")
catch
end
try
Books.html("test", fail_on_error=false)
error("Expected pandoc_html to fail.")
error("Expected _pandoc_html to fail.")
catch
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/sitemap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end

project = "test"
cd(joinpath(Books.PROJECT_ROOT, "docs")) do
h = Books.pandoc_html(project)
h = Books._pandoc_html(project, online_url_prefix)
text = Books.sitemap(project, h)
@test startswith(text, "<?xml")
@test endswith(rstrip(text), "</urlset>")
Expand Down