|
| 1 | +CI = get(ENV, "CI", nothing) == "true" || get(ENV, "GITHUB_TOKEN", nothing) !== nothing |
| 2 | + |
| 3 | +import Pkg |
| 4 | +Pkg.pkg"add Documenter@1" |
| 5 | + |
| 6 | +# Load documenter |
| 7 | +using Documenter |
| 8 | +using DocumenterTools: Themes |
| 9 | +ENV["JULIA_DEBUG"] = "Documenter" |
| 10 | + |
| 11 | +# For easier debugging when downloading from a specific branch. |
| 12 | +github_user = "JuliaDynamics" |
| 13 | +branch = "master" |
| 14 | +download_path = "https://raw.githubusercontent.com/$github_user/doctheme/$branch" |
| 15 | + |
| 16 | +import Downloads |
| 17 | +for file in ("juliadynamics-lightdefs.scss", "juliadynamics-darkdefs.scss", "juliadynamics-style.scss") |
| 18 | + Downloads.download("$download_path/$file", joinpath(@__DIR__, file)) |
| 19 | +end |
| 20 | + |
| 21 | +# create the themes |
| 22 | +for w in ("light", "dark") |
| 23 | + header = read(joinpath(@__DIR__, "juliadynamics-style.scss"), String) |
| 24 | + theme = read(joinpath(@__DIR__, "juliadynamics-$(w)defs.scss"), String) |
| 25 | + write(joinpath(@__DIR__, "juliadynamics-$(w).scss"), header*"\n"*theme) |
| 26 | +end |
| 27 | + |
| 28 | +# compile the themes |
| 29 | +Themes.compile(joinpath(@__DIR__, "juliadynamics-light.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-light.css")) |
| 30 | +Themes.compile(joinpath(@__DIR__, "juliadynamics-dark.scss"), joinpath(@__DIR__, "src/assets/themes/documenter-dark.css")) |
| 31 | + |
| 32 | +# Download and apply CairoMakie plotting style |
| 33 | +using CairoMakie |
| 34 | +Downloads.download("$download_path/style.jl", joinpath(@__DIR__, "style.jl")) |
| 35 | +include("style.jl") |
| 36 | + |
| 37 | +""" |
| 38 | + build_docs_with_style(pages::Vector, modules... ; |
| 39 | + bib = nothing, authors = "George Datseris and contributors", |
| 40 | + htmlkw = NamedTuple(), kw... |
| 41 | + ) |
| 42 | +
|
| 43 | +Call the `makedocs` function with some predefined style components. |
| 44 | +The first module dictates site name, while the rest need to be included |
| 45 | +to expand and cross-referrence docstrings from other modules. |
| 46 | +`kw` are propagated to `makedocs` while `htmlkw` are propagated to |
| 47 | +`Documenter.HTML`. |
| 48 | +""" |
| 49 | +function build_docs_with_style(pages, modules...; |
| 50 | + bib = nothing, authors = "George Datseris", draft = false, |
| 51 | + htmlkw = NamedTuple(), kwargs... |
| 52 | + ) |
| 53 | + settings = ( |
| 54 | + modules = [modules...], |
| 55 | + format = Documenter.HTML(; |
| 56 | + prettyurls = CI, |
| 57 | + assets = [ |
| 58 | + asset("https://fonts.googleapis.com/css?family=Montserrat|Source+Code+Pro&display=swap", class=:css), |
| 59 | + ], |
| 60 | + collapselevel = 3, |
| 61 | + htmlkw..., |
| 62 | + ), |
| 63 | + sitename = "$(modules[1]).jl", |
| 64 | + authors, |
| 65 | + pages, |
| 66 | + draft, |
| 67 | + doctest = false, |
| 68 | + checkdocs = :exported, |
| 69 | + linkcheck_timeout = 2, |
| 70 | + # The following Documenter fails will NOT ERROR the docbuild! |
| 71 | + warnonly = [:doctest, :missing_docs], |
| 72 | + kwargs... |
| 73 | + ) |
| 74 | + |
| 75 | + if isnothing(bib) |
| 76 | + makedocs(; settings...) |
| 77 | + else |
| 78 | + makedocs(; plugins=[bib], settings...) |
| 79 | + end |
| 80 | + |
| 81 | + if CI |
| 82 | + deploydocs( |
| 83 | + repo = "github.com/JuliaDynamics/$(modules[1]).jl.git", |
| 84 | + target = "build", |
| 85 | + push_preview = true |
| 86 | + ) |
| 87 | + end |
| 88 | + |
| 89 | +end |
0 commit comments