diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-06-09 11:28:11 +0100 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-06-09 11:28:11 +0100 |
commit | 08fe9f739dcf1570ce0321db979a410fe61ebd60 (patch) | |
tree | 05b98e7f6036682d86be2f66873a1807c753c8db | |
parent | ad5dc9ae41051b5de11904620ea6f973cdf306ad (diff) | |
download | bookup-08fe9f739dcf1570ce0321db979a410fe61ebd60.tar.gz bookup-08fe9f739dcf1570ce0321db979a410fe61ebd60.tar.bz2 |
Feat: improved compilation procedures
-rw-r--r-- | ChangeLog.md | 6 | ||||
-rw-r--r-- | Makefile.bookup | 43 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rwxr-xr-x | bin/archive | 2 | ||||
-rwxr-xr-x | bin/assemble | 2 | ||||
-rwxr-xr-x | bin/compile-book | 58 | ||||
-rwxr-xr-x | bin/compile-notes | 35 |
7 files changed, 114 insertions, 34 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index e2910fe..0fac6dd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.0.5 - unreleased + +### Features + +* [x] Improved compilation procedures. + ## v0.0.4 - 2024-06-08 ### Fixes diff --git a/Makefile.bookup b/Makefile.bookup index 3df0384..2701b1b 100644 --- a/Makefile.bookup +++ b/Makefile.bookup @@ -27,6 +27,7 @@ WEBSITE ?= $(PROJECT) PDF_STYLE ?= bookdown::tufte_book2 # HTML style +#HTML_STYLE ?= bookdown::html_book HTML_STYLE ?= bookdown::gitbook # @@ -72,9 +73,9 @@ archive: clean: @true @rm -f $(OUTPUT).aux $(OUTPUT).log $(OUTPUT).nav $(OUTPUT).out $(OUTPUT).snm $(OUTPUT).tex $(OUTPUT).toc $(OUTPUT).vrb - @#rm -f index.md index.Rmd + @rm -f index.md index.Rmd @rm -f _main.log _main.tex _main.loe _main.Rmd - @rm -rf _book _bookdown_files + @rm -rf _book _bookdown_files _main_files # # Submodules @@ -98,26 +99,10 @@ metadata: # compile_book: metadata - @rm -f $(OUTPUT).md - @#cat sections/*.md >> $(OUTPUT).md - @/bin/bash -c 'cat _bookup.yml >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md' - @/bin/bash -c 'cat _biblio.yml >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md' - @/bin/bash -c 'for file in $(BOOKUP)/structure/00*.yml; do cat $$file >> $(OUTPUT).md ; echo "---" >> $(OUTPUT).md; done' - @/bin/bash -c 'for file in $(BOOKUP)/structure/00*.md; do cat $$file >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md; done' - @#/bin/bash -c 'for file in content/sections/*/*.md; do cat $$file >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md ; cat $(BOOKUP)/templates/references.md >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md; done' - @#/bin/bash -c 'for file in content/sections/*.md; do cat $$file >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md ; cat $(BOOKUP)/templates/references.md >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md; done' - @/bin/bash -c 'find content/sections -type f | grep '\.md$$' | sort | while read file; do cat $$file >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md ; cat $(BOOKUP)/templates/references.md >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md; done' - @/bin/bash -c 'for file in $(BOOKUP)/structure/99*.md; do cat $$file >> $(OUTPUT).md ; echo "" >> $(OUTPUT).md; done' - @sed -i -e "s|%%revision%%|$(REVISION)|g" -e "s|%%date%%|$(DATE)|g" $(OUTPUT).md - @test -e snippets/terminology.sed && sed -i -f snippets/terminology.sed $(OUTPUT).md || true - @ln -sf $(OUTPUT).md $(OUTPUT).Rmd + @$(BOOKUP)/bin/compile-book $(OUTPUT) $(REVISION) $(DATE) compile_notes: metadata - @rm -f notes.md - @/bin/bash -c 'find content/notes -type f | grep '\.md$$' | sort | while read file; do cat $$file >> notes.md; echo "" >> notes.md; done; echo "# Bibliografia" >> notes.md' - @sed -i -e "s|%%revision%%|$(REVISION)|g" -e "s|%%date%%|$(DATE)|g" notes.md - @test -e snippets/terminology.sed && sed -i -f snippets/terminology.sed notes.md || true - @ln -s notes.md notes.Rmd + @$(BOOKUP)/bin/compile-notes notes $(REVISION) $(DATE) compile: compile_book move_book compile_notes move_note @true @@ -130,11 +115,7 @@ bookdown_clean: @rm -f _main.Rmd bookdown_html: - @# Needs to backup the index.html to avoid overwriting - @#mv index.html index.html.old - # Cleanup - @#rm -rf $(OUTPUT)/html $(OUTPUT)/$(OUTPUT).html @rm -rf $(OUTPUT_FOLDER) # Fix references @@ -150,11 +131,12 @@ bookdown_html: # Restore $(OUTPUT).md after the weird reference fix @#mv $(OUTPUT).md.base $(OUTPUT).md + # Fix the index file name # See https://stackoverflow.com/questions/58340924/bookdown-generates-index-file-with-a-chapter-title-instead-of-index-html-when # Fixed using section ID naming in the preamble - #@cd _book && ln -s "inĂcio.html" index.html - @#mv _book $(OUTPUT)/html - @#mv index.html.old index.html + #@cd _book && ln -s "introduction.html" index.html + + # Move the book to the output folder @mv _book $(OUTPUT_FOLDER) # Replace fuse.js from CDN to local @@ -181,8 +163,6 @@ bookdown_pdf: @Rscript -e 'bookdown::render_book("$(OUTPUT).md", "$(PDF_STYLE)")' # Move - @#mv _main.pdf $(OUTPUT).pdf - @#mv _book/_main.pdf $(OUTPUT)/$(OUTPUT).pdf @mv _book/_main.pdf $(OUTPUT_FOLDER)/$(OUTPUT).pdf # Use sed to convert tufte::margin_note to marginfigure @@ -228,7 +208,7 @@ move_notes: # Too many section levels (nesting) to produce a PDF output #bookdown_notes_pdf: -# @Rscript -e 'bookdown::render_book("notes.Rmd", "bookdown::tufte_book2")' +# @Rscript -e 'bookdown::render_book("notes.Rmd", "$(PDF_STYLE)")' bookdown_notes_html: # Fix references @@ -237,8 +217,7 @@ bookdown_notes_html: @sed -e 's/\\\\citet{\([^}]*\)}/@\1/g' notes.md > notes.new && mv notes.new notes.md # Build - @#Rscript -e 'bookdown::render_book("notes.Rmd", "bookdown::html_book")' - @Rscript -e 'bookdown::render_book("notes.Rmd", "bookdown::gitbook")' + @Rscript -e 'bookdown::render_book("notes.Rmd", "$(HTML_STYLE)")' # Cleanup old notes @rm -rf notebook @@ -7,6 +7,8 @@ multiple book volumes. It was conceived as the underlying system used by [Projeto Vertigem][]. +It has _lots_ of conventions and heuristics. + At this point Bookup is not highly customized, and probably will not suit your needs, but still can be used as a reference if you're planning to do something similar. diff --git a/bin/archive b/bin/archive index 8949268..ef77b9d 100755 --- a/bin/archive +++ b/bin/archive @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Archiver # diff --git a/bin/assemble b/bin/assemble index 3b5b287..04ae785 100755 --- a/bin/assemble +++ b/bin/assemble @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Assembler # diff --git a/bin/compile-book b/bin/compile-book new file mode 100755 index 0000000..42f7f67 --- /dev/null +++ b/bin/compile-book @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# +# Book compiler +# + +# Parameters +BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" +DIRNAME="`dirname $0`" +BASEDIR="$DIRNAME/.." +OUTPUT="${1:-book}" +REVISION="$2" +DATE="$3" + +# Remove any dangling output files +rm -f $OUTPUT.md $OUTPUT.Rmd + +# Bookup config +cat _bookup.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md + +# Bibliography +cat _biblio.yml >> $OUTPUT.md ; echo "" >> $OUTPUT.md + +# YAML headers +for file in $BASEDIR/structure/00*.yml; do + cat $file >> $OUTPUT.md + echo "---" >> $OUTPUT.md +done + +# Markdown headers +for file in $BASEDIR/structure/00*.md; do + cat $file >> $OUTPUT.md + echo "" >> $OUTPUT.md +done + +# Sections +find content/sections -type f | grep '\.md$' | sort | while read file; do + cat $file >> $OUTPUT.md + echo "" >> $OUTPUT.md + cat $BASEDIR/templates/references.md >> $OUTPUT.md + echo "" >> $OUTPUT.md +done + +# Footers +for file in $BASEDIR/structure/99*.md; do + cat $file >> $OUTPUT.md + echo "" >> $OUTPUT.md +done + +# Revision information +sed -i -e "s|%%revision%%|$REVISION|g" -e "s|%%date%%|$DATE|g" $OUTPUT.md + +# Post-processing +if [ -e "snippets/terminology.sed" ]; then + sed -i -f snippets/terminology.sed $OUTPUT.md +fi + +# Symlink as a Bookdown source +ln -sf $OUTPUT.md $OUTPUT.Rmd diff --git a/bin/compile-notes b/bin/compile-notes new file mode 100755 index 0000000..1e55dcc --- /dev/null +++ b/bin/compile-notes @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# +# Book compiler +# + +# Parameters +BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" +DIRNAME="`dirname $0`" +BASEDIR="$DIRNAME/.." +OUTPUT="${1:-notes}" +REVISION="$2" +DATE="$3" + +# Remove any dangling output files +rm -f $OUTPUT.md + +# Content +find content/notes -type f | grep '\.md$' | sort | while read file; do + cat $file >> $OUTPUT.md + echo "" >> $OUTPUT.md +done + +# Bibliography section +echo "# Bibliografia" >> $OUTPUT.md + +# Revision information +sed -i -e "s|%%revision%%|$REVISION|g" -e "s|%%date%%|$REVISION|g" $OUTPUT.md + +# Post-processing +if [ -e "snippets/terminology.sed" ]; then + sed -i -f snippets/terminology.sed $OUTPUT.md +fi + +# Symlink as a Bookdown source +ln -s $OUTPUT.md notes.Rmd |