1
0
mirror of https://git.FreeBSD.org/doc.git synced 2026-06-02 19:35:07 +00:00

documentation: Add experimental support for EPUB output

This commit is contained in:
Danilo G. Baio
2021-11-06 10:53:31 -03:00
parent 12e79a273b
commit 82c271aa23
2 changed files with 114 additions and 2 deletions
+57
View File
@@ -14,6 +14,7 @@
# If variable DOC_HTML_ARCHIVE is set, all documents will be
# archived/compressed, and only these files will be kept in the public
# directory.
# epub - build EPUB versions of the articles and books (Experimental).
#
# 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
@@ -116,6 +117,11 @@ requirements-pdf:
@(echo ${LOCALBASE}/bin/asciidoctor-pdf not found, please run 'pkg install rubygem-asciidoctor-pdf'; exit 1)
.endif
requirements-epub:
.if !exists(${LOCALBASE}/bin/asciidoctor-epub3)
@(echo ${LOCALBASE}/bin/asciidoctor-epub3 not found, please run 'pkg install rubygem-asciidoctor-epub3'; exit 1)
.endif
starting-message: .PHONY
@echo ---------------------------------------------------------------
@echo Building the documentation
@@ -242,3 +248,54 @@ html-archive-clean-files:
find ${.CURDIR}/public/ ! -name '*.pdf' ! -name '*.tar.gz' -type f -delete
find ${.CURDIR}/public/ -type d -empty -delete
.endif
#
# EPUB targets
# Use DOC_LANG to choose the language, e.g., make DOC_LANG="en fr" pdf-books
#
epub: epub-articles epub-books
epub-books: requirements-epub generate-books-toc
@echo ---------------------------------------------------------------
@echo !!! EPUB output is experimental !!!
@echo
@echo Asciidoctor EPUB3 is currently alpha software. Use accordingly. Although the
@echo bulk of AsciiDoc content is converted, theres still work needed to fill in
@echo gaps where conversion is incomplete or unstyled.
@echo https://docs.asciidoctor.org/epub3-converter/latest/#project-status
@echo ---------------------------------------------------------------
.for _lang in ${BOOK_LANGS}
./tools/asciidoctor.sh books ${_lang} epub
.endfor
epub-articles: requirements-epub
@echo ---------------------------------------------------------------
@echo !!! EPUB output is experimental !!!
@echo
@echo Asciidoctor EPUB3 is currently alpha software. Use accordingly. Although the
@echo bulk of AsciiDoc content is converted, theres still work needed to fill in
@echo gaps where conversion is incomplete or unstyled.
@echo https://docs.asciidoctor.org/epub3-converter/latest/#project-status
@echo ---------------------------------------------------------------
.for _lang in ${ARTICLE_LANGS}
./tools/asciidoctor.sh articles ${_lang} epub
.endfor
epub-clean: epub-articles-clean epub-books-clean
epub-books-clean:
.for _lang in ${BOOK_LANGS}
rm -fr ${.CURDIR}/public/${_lang}/books
-rmdir ${.CURDIR}/public/${_lang}
.endfor
-rmdir ${.CURDIR}/public/
epub-articles-clean:
.for _lang in ${ARTICLE_LANGS}
rm -fr ${.CURDIR}/public/${_lang}/articles
.if !exists(${.CURDIR}/public/${_lang}/books)
rm -fr ${.CURDIR}/public/${_lang}
.endif
.endfor
-rmdir ${.CURDIR}/public
+57 -2
View File
@@ -28,6 +28,7 @@
LOCALBASE="/usr/local"
ASCIIDOCTORPDF_CMD="${LOCALBASE}/bin/asciidoctor-pdf"
ASCIIDOCTOREPUB_CMD="${LOCALBASE}/bin/asciidoctor-epub3"
build_pdf() {
if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ]; then
@@ -78,7 +79,52 @@ build_pdf() {
}
# build_epub()
build_epub() {
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
$ASCIIDOCTOREPUB_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 \
-o "${cur_dir_output}${doc_name}_${doc_lang}_POC_.epub" \
"${cur_dir_source}${asciidoctor_file_name}"
}
archive() {
@@ -156,8 +202,17 @@ main() {
archive "$doc_type" "$doc_lang" "$document"
done
;;
epub)
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 epub: $doc_type $doc_lang $document"
build_epub "$doc_type" "$doc_lang" "$document"
done
;;
*)
echo "Formats available: archive, pdf"
echo "Formats available: archive, pdf, epub"
exit 1
;;
esac