|
| 1 | +# Script to build the MultiDocumenter docs |
| 2 | +# |
| 3 | +# julia --project docs/make.jl [--temp] [deploy] |
| 4 | +# |
| 5 | +# When `deploy` is passed as an argument, it goes into deployment mode |
| 6 | +# and attempts to push the generated site to gh-pages. You can also pass |
| 7 | +# `--temp`, in which case the source repositories are cloned into a temporary |
| 8 | +# directory (as opposed to `docs/clones`). |
| 9 | +using Documenter: Documenter |
1 | 10 | using ITensorDocsNext: ITensorDocsNext
|
2 |
| -using Documenter: Documenter, DocMeta, deploydocs, makedocs |
| 11 | +using MultiDocumenter: MultiDocumenter |
3 | 12 |
|
4 |
| -DocMeta.setdocmeta!( |
5 |
| - ITensorDocsNext, :DocTestSetup, :(using ITensorDocsNext); recursive=true |
6 |
| -) |
| 13 | +clonedir = ("--temp" in ARGS) ? mktempdir() : joinpath(@__DIR__, "clones") |
| 14 | +outpath = mktempdir() |
| 15 | +@info """ |
| 16 | +Cloning packages into: $(clonedir) |
| 17 | +Building aggregate site into: $(outpath) |
| 18 | +""" |
7 | 19 |
|
| 20 | +@info "Building Documenter site for ITensorDocsNext" |
8 | 21 | include("make_index.jl")
|
9 |
| - |
10 |
| -makedocs(; |
| 22 | +Documenter.makedocs(; |
| 23 | + sitename="ITensor ecosystem docs", |
11 | 24 | modules=[ITensorDocsNext],
|
12 |
| - authors="ITensor developers <support@itensor.org> and contributors", |
13 |
| - sitename="ITensorDocsNext.jl", |
14 |
| - format=Documenter.HTML(; |
15 |
| - canonical="https://ITensor.github.io/ITensorDocsNext.jl", |
16 |
| - edit_link="main", |
17 |
| - assets=String[], |
18 |
| - ), |
19 |
| - pages=["Home" => "index.md", "Reference" => "reference.md"], |
| 25 | + warnonly=true, |
| 26 | + pages=["index.md"], |
20 | 27 | )
|
21 | 28 |
|
22 |
| -deploydocs(; |
23 |
| - repo="github.com/ITensor/ITensorDocsNext.jl", devbranch="main", push_preview=true |
| 29 | +@info "Building aggregate ITensorDocsNext site" |
| 30 | +function itensor_multidocref(pkgname::String; clonedir::String=clonedir) |
| 31 | + return MultiDocumenter.MultiDocRef(; |
| 32 | + upstream=joinpath(clonedir, pkgname), |
| 33 | + path=pkgname, |
| 34 | + name=pkgname, |
| 35 | + giturl="https://github.com/ITensor/$(pkgname).jl.git", |
| 36 | + ) |
| 37 | +end |
| 38 | +docs = [ |
| 39 | + # We also add ITensorDocsNext's own generated pages |
| 40 | + MultiDocumenter.MultiDocRef(; |
| 41 | + upstream=joinpath(@__DIR__, "build"), |
| 42 | + path="Overview", |
| 43 | + name="Home", |
| 44 | + fix_canonical_url=false, |
| 45 | + ), |
| 46 | + MultiDocumenter.MegaDropdownNav( |
| 47 | + "Array Libraries", |
| 48 | + itensor_multidocref.([ |
| 49 | + "ITensorBase", |
| 50 | + "NamedDimsArrays", |
| 51 | + "BlockSparseArrays", |
| 52 | + "SparseArraysBase", |
| 53 | + "DiagonalArrays", |
| 54 | + "TensorAlgebra", |
| 55 | + ]), |
| 56 | + ), |
| 57 | + MultiDocumenter.MegaDropdownNav( |
| 58 | + "Group Symmetric Arrays", itensor_multidocref.(["GradedUnitRanges", "SymmetrySectors"]) |
| 59 | + ), |
| 60 | + MultiDocumenter.MegaDropdownNav( |
| 61 | + "Developer Tools", |
| 62 | + itensor_multidocref.(["DerivableInterfaces", "TypeParameterAccessors", "MapBroadcast"]), |
| 63 | + ), |
| 64 | +] |
| 65 | + |
| 66 | +MultiDocumenter.make( |
| 67 | + outpath, |
| 68 | + docs; |
| 69 | + search_engine=MultiDocumenter.SearchConfig(; |
| 70 | + index_versions=["stable"], engine=MultiDocumenter.FlexSearch |
| 71 | + ), |
| 72 | + rootpath="/ITensorDocsNext/", |
| 73 | + canonical_domain="https://itensor.github.io/", |
| 74 | + sitemap=true, |
24 | 75 | )
|
| 76 | + |
| 77 | +if "deploy" in ARGS |
| 78 | + @warn "Deploying to GitHub" ARGS |
| 79 | + gitroot = normpath(joinpath(@__DIR__, "..")) |
| 80 | + run(`git pull`) |
| 81 | + outbranch = "gh-pages" |
| 82 | + has_outbranch = true |
| 83 | + if !success(`git checkout $outbranch`) |
| 84 | + has_outbranch = false |
| 85 | + if !success(`git switch --orphan $outbranch`) |
| 86 | + @error "Cannot create new orphaned branch $outbranch." |
| 87 | + exit(1) |
| 88 | + end |
| 89 | + end |
| 90 | + for file in readdir(gitroot; join=true) |
| 91 | + endswith(file, ".git") && continue |
| 92 | + rm(file; force=true, recursive=true) |
| 93 | + end |
| 94 | + for file in readdir(outpath) |
| 95 | + cp(joinpath(outpath, file), joinpath(gitroot, file)) |
| 96 | + end |
| 97 | + run(`git add .`) |
| 98 | + if success(`git commit -m 'Aggregate documentation'`) |
| 99 | + @info "Pushing updated documentation." |
| 100 | + if has_outbranch |
| 101 | + run(`git push`) |
| 102 | + else |
| 103 | + run(`git push -u origin $outbranch`) |
| 104 | + end |
| 105 | + run(`git checkout main`) |
| 106 | + else |
| 107 | + @info "No changes to aggregated documentation." |
| 108 | + end |
| 109 | +else |
| 110 | + @info "Skipping deployment, 'deploy' not passed. Generated files in docs/out." ARGS |
| 111 | + cp(outpath, joinpath(@__DIR__, "out"); force=true) |
| 112 | +end |
0 commit comments