From nobody Sat Nov 6 11:10:04 2021 X-Original-To: dev-commits-doc-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id A934A18300F1 for ; Sat, 6 Nov 2021 11:10:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HmZR046Hsz3NCC; Sat, 6 Nov 2021 11:10:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 691401E48; Sat, 6 Nov 2021 11:10:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A6BA4nY084456; Sat, 6 Nov 2021 11:10:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A6BA4HF084453; Sat, 6 Nov 2021 11:10:04 GMT (envelope-from git) Date: Sat, 6 Nov 2021 11:10:04 GMT Message-Id: <202111061110.1A6BA4HF084453@gitrepo.freebsd.org> To: doc-committers@FreeBSD.org, dev-commits-doc-all@FreeBSD.org From: "Danilo G. Baio" Subject: git: 038be2aa83 - main - documentation: Add an option to archive/compress HTML offline files List-Id: Commit messages for all branches of the doc repository List-Archive: https://lists.freebsd.org/archives/dev-commits-doc-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-doc-all@freebsd.org X-BeenThere: dev-commits-doc-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dbaio X-Git-Repository: doc X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 038be2aa83b06064a952308730b6c7449d14e799 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by dbaio: URL: https://cgit.FreeBSD.org/doc/commit/?id=038be2aa83b06064a952308730b6c7449d14e799 commit 038be2aa83b06064a952308730b6c7449d14e799 Author: Danilo G. Baio AuthorDate: 2021-11-04 23:07:26 +0000 Commit: Danilo G. Baio CommitDate: 2021-11-06 11:08:24 +0000 documentation: Add an option to archive/compress HTML offline files Reviewed by: carlavilla Differential Revision: https://reviews.freebsd.org/D32867 --- documentation/Makefile | 23 ++++++++++- documentation/tools/asciidoctor.sh | 82 ++++++++++++++++++++++++++++++-------- 2 files changed, 86 insertions(+), 19 deletions(-) diff --git a/documentation/Makefile b/documentation/Makefile index 3e63ccef69..3b1a29d9bc 100644 --- a/documentation/Makefile +++ b/documentation/Makefile @@ -10,7 +10,10 @@ # run - serves the built documentation site for local browsing # pdf - build PDF versions of the articles and books. # html - build HTML versions of the articles and books for -# offline use +# offline use. +# If variable DOC_HTML_ARCHIVE is set, all documents will be +# archived/compressed, and only these files will be kept in the public +# directory. # # The run target uses hugo's built-in webserver to make the documentation site # available for local browsing. The documentation should have been built prior @@ -205,7 +208,7 @@ pdf-articles-clean: # # HTML targets # -html: generate-books-toc-offline build-offline html-clean-global html-clean-articles html-clean-books +html: generate-books-toc-offline build-offline html-clean-global html-clean-articles html-clean-books html-archive html-archive-clean-files html-clean: hugo-clean @@ -223,3 +226,19 @@ html-clean-books: .for _lang in ${BOOK_LANGS} rm -fr ${.CURDIR}/public/${_lang}/books/index.html .endfor + +html-archive: +.if defined(DOC_HTML_ARCHIVE) +.for _lang in ${ARTICLE_LANGS} + ./tools/asciidoctor.sh articles ${_lang} archive +.endfor +.for _lang in ${BOOK_LANGS} + ./tools/asciidoctor.sh books ${_lang} archive +.endfor +.endif + +html-archive-clean-files: +.if defined(DOC_HTML_ARCHIVE) + find ${.CURDIR}/public/ ! -name '*.pdf' ! -name '*.tar.gz' -type f -delete + find ${.CURDIR}/public/ -type d -empty -delete +.endif diff --git a/documentation/tools/asciidoctor.sh b/documentation/tools/asciidoctor.sh index 6f33181e25..28924d0b03 100755 --- a/documentation/tools/asciidoctor.sh +++ b/documentation/tools/asciidoctor.sh @@ -69,7 +69,7 @@ build_pdf() { -r ./shared/lib/cross-document-references-macro.rb \ --doctype="$asciidoctor_type" \ -a skip-front-matter \ - -a lang=${doc_lang} \ + -a lang="$doc_lang" \ -a isonline=1 \ -a env-beastie=1 \ -a pdf-theme=default-with-fallback-font \ @@ -81,6 +81,49 @@ build_pdf() { # build_epub() +archive() { + if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then + exit 1 + fi + + local doc_type="$1" + local doc_lang="$2" + local doc_name="$3" + + if [ -d "public/$doc_lang" ]; then + local pub_dir="public/$doc_lang/$doc_type/$doc_name/" + elif [ -d "public/$doc_type" ]; then + # single language build + local pub_dir="public/$doc_type/$doc_name/" + fi + + if [ -f "${pub_dir}${doc_name}_${doc_lang}.tar.gz" ]; then + rm -f "${pub_dir}${doc_name}_${doc_lang}.tar.gz" + fi + + local source_doc_dir="" + if [ -d "public/source/$doc_type/$doc_name/" ]; then + source_doc_dir="public/source/$doc_type/$doc_name/" + fi + + local image_doc_dir="" + if [ -d "public/images/$doc_type/$doc_name/" ]; then + image_doc_dir="public/images/$doc_type/$doc_name/" + fi + + tar -czf "public/${doc_name}_${doc_lang}.tar.gz" \ + "$pub_dir" \ + public/css/ \ + public/fonts/ \ + public/js/ \ + $source_doc_dir \ + $image_doc_dir + + mv -f "public/${doc_name}_${doc_lang}.tar.gz" "$pub_dir" + +} + + main() { if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then echo "Needs parameters (type, language and format)." @@ -97,22 +140,27 @@ main() { 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 + case "$doc_format" in + pdf) + for document in $(find "content/$doc_lang/$doc_type/" -type d -mindepth 1 -maxdepth 1 | awk -F '/' '{ print $4 }' | sort -n); do + if [ "$document" = "pgpkeys" ]; then + continue + fi + echo "asciidoctor build_pdf: $doc_type $doc_lang $document" + build_pdf "$doc_type" "$doc_lang" "$document" + done + ;; + archive) + for document in $(find "content/$doc_lang/$doc_type/" -type d -mindepth 1 -maxdepth 1 | awk -F '/' '{ print $4 }' | sort -n); do + echo "generate archive: $doc_type $doc_lang $document" + archive "$doc_type" "$doc_lang" "$document" + done + ;; + *) + echo "Formats available: archive, pdf" + exit 1 + ;; + esac } main "$@"