Skip to content
Open
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
20 changes: 15 additions & 5 deletions src/html/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,22 @@ struct HTMLAsset
class :: Symbol
uri :: String
islocal :: Bool
load_early :: Bool
attributes::Dict{Symbol, String}

function HTMLAsset(class::Symbol, uri::String, islocal::Bool, attributes::Dict{Symbol, String}=Dict{Symbol,String}())
function HTMLAsset(class::Symbol, uri::String, islocal::Bool, load_early::Bool=false, attributes::Dict{Symbol, String}=Dict{Symbol,String}())
if !islocal && match(r"^https?://", uri) === nothing
error("Remote asset URL must start with http:// or https://")
end
if islocal && isabspath(uri)
@error("Local asset should not have an absolute URI: $uri")
end
class in [:ico, :css, :js] || error("Unrecognised asset class $class for `$(uri)`")
new(class, uri, islocal, attributes)
new(class, uri, islocal, load_early, attributes)
end
end


"""
asset(uri)

Expand All @@ -133,6 +135,9 @@ elements in `<head>`, respectively.
relative to the documentation source directory (conventionally `src/`). This can be useful
when it is necessary to override the asset class of a local asset.

**`load_early`** can be used to load the JS before requirejs when the script
is not Asynchronous Module Definition (AMD) compatible.

# Usage

```julia
Expand All @@ -148,15 +153,15 @@ Documenter.HTML(assets = [
])
```
"""
function asset(uri; class = nothing, islocal=false, attributes=Dict{Symbol,String}())
function asset(uri; class = nothing, islocal=false, load_early=false, attributes=Dict{Symbol,String}())
if class === nothing
class = assetclass(uri)
(class === nothing) && error("""
Unable to determine asset class for: $(uri)
It can be set explicitly with the `class` keyword argument.
""")
end
HTMLAsset(class, uri, islocal, attributes)
HTMLAsset(class, uri, islocal, load_early, attributes)
end

function assetclass(uri)
Expand Down Expand Up @@ -1005,6 +1010,10 @@ function render_head(ctx, navnode)
end,

script("documenterBaseURL=\"$(relhref(src, "."))\""),

# Custom user-provided assets which are loaded early for non-AMD compatible modules.
asset_links(src, filter(x -> x.load_early, ctx.settings.assets)),

script[
:src => RD.requirejs_cdn,
Symbol("data-main") => relhref(src, ctx.documenter_js)
Expand All @@ -1026,8 +1035,9 @@ function render_head(ctx, navnode)
return e
end,
script[:src => relhref(src, ctx.themeswap_js)],

# Custom user-provided assets.
asset_links(src, ctx.settings.assets),
asset_links(src, filter(x -> !x.load_early, ctx.settings.assets))
)
end

Expand Down
2 changes: 1 addition & 1 deletion test/examples/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function html_doc(
"assets/favicon.ico",
"assets/custom.css",
asset("https://example.com/resource.js"),
asset("http://example.com/fonts?param=foo", class=:css),
asset("http://example.com/fonts?param=foo", class=:css, load_early=true),
asset("https://fonts.googleapis.com/css?family=Nanum+Brush+Script&display=swap", class=:css),
],
prettyurls = true,
Expand Down