diff options
| author | Sergio Carlavilla Delgado <carlavilla@FreeBSD.org> | 2021-11-03 16:39:08 +0000 |
|---|---|---|
| committer | Sergio Carlavilla Delgado <carlavilla@FreeBSD.org> | 2021-11-03 16:44:52 +0000 |
| commit | 64acd169b82416fe39ad8c4b1be106680d4a3eb3 (patch) | |
| tree | 05b8bc3182dc4cfcf0a8a0964b4303903a4abf56 /documentation/tools/asciidoctor.sh | |
| parent | 0636d709faeb6b7d1a44882ae33a02015d32774b (diff) | |
Build offline documentation using Hugo and other improvements
* Allow to build the documentation offline using Hugo
* Fix link problems
* Remove SVN entities
* Fix lang problems to help weblate
* Move all the AsciiDoctor translations to the shared folder to
help weblate
* Allow the possibility to build each document. For example each
document can be edited in and watched the result in real time in
VS Code or Vim/NeoVim.
Breaking changes:
Eliminate the possibility of building books or articles.
They must be builded at the same time.
This functionality will be restored when version 0.89.0 is in the
repositories in a couple of weeks.
Reviewed by: dbaio@
Differential Revision: https://reviews.freebsd.org/D31926
Diffstat (limited to 'documentation/tools/asciidoctor.sh')
| -rwxr-xr-x | documentation/tools/asciidoctor.sh | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/documentation/tools/asciidoctor.sh b/documentation/tools/asciidoctor.sh new file mode 100755 index 0000000000..6f33181e25 --- /dev/null +++ b/documentation/tools/asciidoctor.sh @@ -0,0 +1,118 @@ +#!/bin/sh +# +# Copyright (c) 2021 Danilo G. Baio <dbaio@FreeBSD.org> +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# shellcheck disable=SC3043 + + +LOCALBASE="/usr/local" +ASCIIDOCTORPDF_CMD="${LOCALBASE}/bin/asciidoctor-pdf" + +build_pdf() { + if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then + exit 1 + fi + + local doc_type="$1" + local doc_lang="$2" + local doc_name="$3" + + local cur_dir_source="content/$doc_lang/$doc_type/$doc_name/" + local cur_dir_output="public/$doc_lang/$doc_type/$doc_name/" + + if [ ! -d "$cur_dir_output" ]; then + mkdir -p "$cur_dir_output" + fi + + if [ "$doc_type" = "books" ]; then + local asciidoctor_type="book" + + if [ -f "${cur_dir_source}book.adoc" ]; then + local asciidoctor_file_name="book.adoc" + else + local asciidoctor_file_name="_index.adoc" + fi + fi + + if [ "$doc_type" = "articles" ]; then + local asciidoctor_type="article" + local asciidoctor_file_name="_index.adoc" + fi + + $ASCIIDOCTORPDF_CMD \ + -r ./shared/lib/man-macro.rb \ + -r ./shared/lib/git-macro.rb \ + -r ./shared/lib/packages-macro.rb \ + -r ./shared/lib/inter-document-references-macro.rb \ + -r ./shared/lib/sectnumoffset-treeprocessor.rb \ + -r ./shared/lib/cross-document-references-macro.rb \ + --doctype="$asciidoctor_type" \ + -a skip-front-matter \ + -a lang=${doc_lang} \ + -a isonline=1 \ + -a env-beastie=1 \ + -a pdf-theme=default-with-fallback-font \ + -o "${cur_dir_output}${doc_name}_${doc_lang}.pdf" \ + "${cur_dir_source}${asciidoctor_file_name}" +} + + +# build_epub() + + +main() { + if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then + echo "Needs parameters (type, language and format)." + echo "$0 articles en pdf" + exit 1 + fi + + local doc_type="$1" + local doc_lang="$2" + local doc_format="$3" + + if [ ! "$doc_type" = "articles" ] && [ ! "$doc_type" = "books" ]; then + echo "First parameter needs to be 'articles' or 'books'" + exit 1 + fi + + if [ ! "$doc_format" = "pdf" ]; then + # Default pdf + doc_format="pdf" + fi + + for document in $(find "content/$doc_lang/$doc_type/" -type d -mindepth 1 -maxdepth 1 | awk -F '/' '{ print $4 }' | sort -n); do + if [ "$doc_format" = "pdf" ] && [ "$document" = "pgpkeys" ]; then + continue + fi + + if [ "$doc_format" = "pdf" ]; then + echo "asciidoctor build_pdf: $doc_type $doc_lang $document $doc_format" + build_pdf "$doc_type" "$doc_lang" "$document" + fi + + done +} + +main "$@" |
