|
| 1 | +// SPDX-FileCopyrightText: © 2024 Sebastian Davids <[email protected]> |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | += asciidoc_html_build |
| 4 | +:script_url: https://github.com/sdavids/sdavids-shell-misc/blob/main/scripts/asciidoc/asciidoc_html_build.sh |
| 5 | +:main_adoc_url: https://github.com/sdavids/sdavids-shell-misc/blob/main/scripts/asciidoc/example-html/src/main.adoc |
| 6 | +:docinfo_url: https://github.com/sdavids/sdavids-shell-misc/blob/main/scripts/asciidoc/example-html/src/docinfo/docinfo.html |
| 7 | + |
| 8 | +{script_url}[This script^] will typeset the documents of a given source directory into HTML. |
| 9 | + |
| 10 | +The following parameters are optional: |
| 11 | + |
| 12 | +`f` :: delete the output directory before typesetting |
| 13 | +`n` :: turn caching off |
| 14 | +`o` :: the output directory (`$PWD/build` if not given) |
| 15 | +`s` :: the source directory (`$PWD/src` if not given) |
| 16 | + |
| 17 | +[NOTE] |
| 18 | +==== |
| 19 | +`*.adoc` files inside directories named `_includes` will not be typeset. |
| 20 | +
|
| 21 | +This is useful for https://docs.asciidoctor.org/asciidoc/latest/directives/include/#when-is-an-include-directive-useful[AsciiDoc includes]. |
| 22 | +==== |
| 23 | + |
| 24 | +[NOTE] |
| 25 | +==== |
| 26 | +This scripts configures Asciidoctor |
| 27 | +to not use https://docs.asciidoctor.org/asciidoctor/latest/html-backend/default-stylesheet/#disable-or-modify-the-web-fonts[webfonts], |
| 28 | +use https://docs.asciidoctor.org/asciidoctor/latest/html-backend/local-font-awesome/#switch-to-your-local-font-awesome-assets[local FontAwesome assets], |
| 29 | +https://docs.asciidoctor.org/asciidoctor/latest/html-backend/manage-images/#embed-images-with-the-data-uri-attribute[embed images], and |
| 30 | +https://docs.asciidoctor.org/asciidoctor/latest/html-backend/custom-stylesheet/#stylesdir-and-linkcss[inline CSS]. |
| 31 | +==== |
| 32 | + |
| 33 | +[NOTE] |
| 34 | +==== |
| 35 | +If you want to use custom fonts, this script assumes that the `woff2` fonts are found in the `<source directory>/fonts` directory. |
| 36 | +==== |
| 37 | + |
| 38 | +[TIP] |
| 39 | +==== |
| 40 | +Depending on your use case, you might want to use https://docs.antora.org/antora/latest/[Antora] instead of this script. |
| 41 | +==== |
| 42 | + |
| 43 | +== Usage |
| 44 | + |
| 45 | +[,shell] |
| 46 | +---- |
| 47 | +$ tree --noreport -I scripts |
| 48 | +. |
| 49 | +└── src |
| 50 | + └── index.adoc |
| 51 | +$ scripts/asciidoc/asciidoc_html_build.sh |
| 52 | +$ tree --noreport -I scripts |
| 53 | +. |
| 54 | +├── build |
| 55 | +│ └── index.html <1> |
| 56 | +└── src |
| 57 | + └── index.adoc |
| 58 | +
|
| 59 | +$ tree --noreport -a /tmp/example |
| 60 | +/tmp/example |
| 61 | +└── src |
| 62 | + ├── _includes |
| 63 | + │ └── footer.adoc |
| 64 | + ├── a |
| 65 | + │ ├── b |
| 66 | + │ │ └── sub.adoc |
| 67 | + │ └── dir.adoc |
| 68 | + ├── css |
| 69 | + │ └── font-awesome.css <2> |
| 70 | + ├── docinfo |
| 71 | + │ └── docinfo.html <3> |
| 72 | + ├── fonts |
| 73 | + │ └── fontawesome-webfont-4.7.0.woff2 <2> |
| 74 | + └── index.adoc |
| 75 | +$ cat /tmp/example/src/docinfo/docinfo.html <3> |
| 76 | +<style> |
| 77 | + pre.rouge .hll { <4> |
| 78 | + background-color: #ffffe0; |
| 79 | + display: block; |
| 80 | + } |
| 81 | + pre.rouge .hll * { <4> |
| 82 | + background-color: initial; |
| 83 | + } |
| 84 | +</style> |
| 85 | +$ cat /tmp/example/src/a/b/sub.adoc |
| 86 | += 1. sub |
| 87 | +:source-highlighter: rouge <4> |
| 88 | +:rouge-style: github |
| 89 | +:docinfo: shared <3> |
| 90 | +:docinfodir: ../../docinfo <3> |
| 91 | +
|
| 92 | +[NOTE] <2> |
| 93 | +==== |
| 94 | +Test |
| 95 | +==== |
| 96 | +
|
| 97 | +[plantuml] <5> |
| 98 | +.... |
| 99 | +@startuml |
| 100 | +
|
| 101 | +!include https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Context.puml |
| 102 | +
|
| 103 | +Person(p, "Support") |
| 104 | +
|
| 105 | +System(s, "Test System") |
| 106 | +
|
| 107 | +Rel(p, s, "Uses", "https") |
| 108 | +
|
| 109 | +@enduml |
| 110 | +.... |
| 111 | +
|
| 112 | +[,shell,highlight=2..3;5] <4> |
| 113 | +.... |
| 114 | +A |
| 115 | +B |
| 116 | +C |
| 117 | +D |
| 118 | +E |
| 119 | +F |
| 120 | +G |
| 121 | +.... |
| 122 | +
|
| 123 | +includes::../../_includes/footer.adoc[] |
| 124 | +$ scripts/asciidoc/asciidoc_html_build.sh -s /tmp/example/src -o /tmp/example/out |
| 125 | +$ tree --noreport -a /tmp/example -I src |
| 126 | +/tmp/example |
| 127 | +└── out <6> |
| 128 | + ├── a |
| 129 | + │ ├── b |
| 130 | + │ │ ├── .asciidoctor <8> |
| 131 | + │ │ │ └── diagram |
| 132 | + │ │ │ └── diag-plantuml-md5-757a0ec403d52693302a4f18fd7ec102.png.cache |
| 133 | + │ │ ├── css |
| 134 | + │ │ │ └── font-awesome.css <7> |
| 135 | + │ │ ├── diag-plantuml-md5-757a0ec403d52693302a4f18fd7ec102.png <8> |
| 136 | + │ │ ├── fonts |
| 137 | + │ │ │ └── fontawesome-webfont-4.7.0.woff2 <7> |
| 138 | + │ │ └── sub.html |
| 139 | + │ ├── css |
| 140 | + │ │ └── font-awesome.css <7> |
| 141 | + │ ├── dir.html |
| 142 | + │ └── fonts |
| 143 | + │ └── fontawesome-webfont-4.7.0.woff2 <7> |
| 144 | + ├── css |
| 145 | + │ └── font-awesome.css <7> |
| 146 | + ├── fonts |
| 147 | + │ └── fontawesome-webfont-4.7.0.woff2 <7> |
| 148 | + └── index.html |
| 149 | +$ scripts/asciidoc/asciidoc_html_build.sh -s /tmp/example/src -o /tmp/example/out -f -n |
| 150 | +$ tree --noreport -a /tmp/example -I src |
| 151 | +/tmp/example |
| 152 | +└── out <9> |
| 153 | + ├── a |
| 154 | + │ ├── b |
| 155 | + │ │ ├── css |
| 156 | + │ │ │ └── font-awesome.css |
| 157 | + │ │ ├── fonts |
| 158 | + │ │ │ └── fontawesome-webfont-4.7.0.woff2 |
| 159 | + │ │ └── sub.html |
| 160 | + │ ├── css |
| 161 | + │ │ └── font-awesome.css |
| 162 | + │ ├── dir.html |
| 163 | + │ └── fonts |
| 164 | + │ └── fontawesome-webfont-4.7.0.woff2 |
| 165 | + ├── css |
| 166 | + │ └── font-awesome.css |
| 167 | + ├── fonts |
| 168 | + │ └── fontawesome-webfont-4.7.0.woff2 |
| 169 | + └── index.html |
| 170 | +---- |
| 171 | + |
| 172 | +<1> the typeset HTML |
| 173 | +<2> https://docs.asciidoctor.org/asciidoc/latest/blocks/admonitions/[admonitions] need https://docs.asciidoctor.org/asciidoctor/latest/html-backend/local-font-awesome/[Font Awesome] |
| 174 | +<3> https://docs.asciidoctor.org/asciidoc/latest/docinfo[custom styles] |
| 175 | +<4> use https://docs.asciidoctor.org/asciidoc/latest/verbatim/highlight-lines/#rouge[Rogue source highlighter] |
| 176 | +<5> a document with an https://docs.asciidoctor.org/diagram-extension/latest/diagram_types/plantuml/[PlantUML diagram] |
| 177 | +<6> notice there is no `footer.html` in an `_includes` directory |
| 178 | +<7> Asciidoctor currently https://github.com/asciidoctor/asciidoctor/issues/4622[does not support a nested set of documents] well |
| 179 | +<8> the files of the https://docs.asciidoctor.org/diagram-extension/latest/generate/#diagram_caching[diagram cache] |
| 180 | +<9> the output directory has been cleaned (`-f`) and no files for the cache have been created (`-n`) |
| 181 | + |
| 182 | +[#asciidoc-html-build-example] |
| 183 | +== Example |
| 184 | + |
| 185 | +{main_adoc_url}[main.adoc], |
| 186 | +{docinfo_url}[docinfo.html] |
| 187 | + |
| 188 | +[,console] |
| 189 | +---- |
| 190 | +$ cd scripts/asciidoc/example-html |
| 191 | +$ ../asciidoc_html_build.sh |
| 192 | +---- |
| 193 | + |
| 194 | +=> `build/main.html` |
| 195 | + |
| 196 | +== Prerequisites |
| 197 | + |
| 198 | +* xref:developer-guide::dev-environment/dev-installation.adoc#docker[Docker] |
| 199 | + |
| 200 | +== Related Scripts |
| 201 | + |
| 202 | +* xref:scripts/asciidoc/asciidoc-pdf-build.adoc[] |
| 203 | + |
| 204 | +== More Information |
| 205 | + |
| 206 | +* https://github.com/asciidoctor/docker-asciidoctor[docker-asciidoctor] |
| 207 | +* https://asciidoctor.org[Asciidoctor] |
| 208 | +* https://docs.asciidoctor.org/asciidoc/latest/[AsciiDoc] |
| 209 | +* https://docs.asciidoctor.org/asciidoc/latest/docinfo[Docinfo Files] |
| 210 | +* https://docs.asciidoctor.org/asciidoctor/latest/html-backend/default-stylesheet/#disable-or-modify-the-web-fonts[Disable or modify the web fonts] |
| 211 | +* https://docs.asciidoctor.org/asciidoctor/latest/html-backend/local-font-awesome/[Use Local Font Awesome] |
0 commit comments