# # Parameters # # Customize to your needs in your main Makefile. Examples: # # BOOKUP = vendor/bookup # OUTPUT = my-essay # OUTPUT = essay # WEBSITE = some.hostname # Bookup base folder BOOKUP ?= . # Project name PROJECT ?= bookup # Output file names (prefix) OUTPUT ?= $(PROJECT) # Destination website hostname (for rsync+ssh) WEBSITE ?= $(PROJECT) # # Exclusion patterns # #EXCLUDES = --exclude=.htpasswd #EXCLUDES = --exclude=Makefile.local EXCLUDES = archive # # Metadata # REVISION = $(shell git describe --tags 2> /dev/null || git log -1 --format=oneline | cut -d ' ' -f 1) DATE = $(shell date) YEAR = $(shell date +%Y) # # Phony targets # .PHONY: archive # # Default target # all: submodules book clean @true # # Archive # archive: @$(BOOKUP)/bin/archive # # Cleanup # 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 _main.log _main.tex _main.loe _main.Rmd @rm -rf _book _bookdown_files # # Submodules # submodules: @git submodule update --init --recursive # # Metadata # metadata: @mkdir -p .metadata @echo $(REVISION) > .metadata/revision.txt @echo $(DATE) > .metadata/date.txt @echo $(YEAR) > .metadata/year.txt # # Compilation # 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/published/*/*.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 $(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 @#sed -i -f snippets/terminology.sed $(OUTPUT).md @ln -sf $(OUTPUT).md $(OUTPUT).Rmd compile: compile_book move_book @true # # Main bookdown targets # 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 compiled # Fix references # Use sed to fix a weird reference issue on fig.cap inside knitr blocks that are not properly converted. # Not using "sed -i" since it yields a permission denied error when running inside a guest VM. # This fix no longer works with citeproc. @#cp $(OUTPUT).md $(OUTPUT).md.base @#sed -e 's/\\\\citet{\([^}]*\)}/@\1/g' $(OUTPUT).md > $(OUTPUT).new && mv $(OUTPUT).new $(OUTPUT).md # Build Rscript -e 'bookdown::render_book("$(OUTPUT).md", "bookdown::gitbook")' # Restore $(OUTPUT).md after the weird reference fix @#mv $(OUTPUT).md.base $(OUTPUT).md # 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 @mv _book compiled # Replace fuse.js from CDN to local # This ensures the HTML output can be browsed offline #@find $(OUTPUT)/html -name *.html -exec sed -i -e 's|https://cdn.jsdelivr.net/npm/fuse.js@[^"]*|../../vendor/Fuse.js/dist/fuse.min.js|' {} \; @mkdir compiled/js @cp vendor/bookup/vendor/Fuse.js/dist/fuse.min.js compiled/js @find compiled -name *.html -exec sed -i -e 's|https://cdn.jsdelivr.net/npm/fuse.js@[^"]*|js/fuse.min.js|' {} \; # Add revision information @echo $(REVISION) > compiled/revision # Add symlink to the archive and to the slides # This symlink is useful for checking things in localhost # But it tends to be replaced during remote deployment @cd compiled > /dev/null && ln -s ../archive @cd compiled > /dev/null && ln -s ../slides bookdown_pdf: # Cleanup old builds @rm -rf _book/_main.pdf # Build @Rscript -e 'bookdown::render_book("$(OUTPUT).md", "bookdown::tufte_book2")' # Move @#mv _main.pdf $(OUTPUT).pdf @#mv _book/_main.pdf $(OUTPUT)/$(OUTPUT).pdf @mv _book/_main.pdf compiled/$(OUTPUT).pdf # Use sed to convert tufte::margin_note to marginfigure # Also, "sed -i" yields a permission denied error when running inside a guest VM. bookdown_epub: @# EPUB format is broken right now @true # Fix margin notes @#sed -e 's/r tufte::margin_note/marginfigure/' $(OUTPUT).md > $(OUTPUT).new && mv $(OUTPUT).new $(OUTPUT).md # Build @#Rscript -e 'bookdown::render_book("$(OUTPUT).md", "bookdown::epub_book")' # Move @##mv _book/_main.epub $(OUTPUT)/$(OUTPUT).epub @#mv _book/_main.epub compiled/$(OUTPUT)s.epub # Cleanup @#rm _book/reference-keys.txt @#rmdir _book bookdown: bookdown_clean bookdown_html bookdown_pdf bookdown_epub # # Build the book # move_book: @mv $(OUTPUT).* compiled/ book: archive compile_book bookdown move_book clean # # Remote copies # web_deploy: @rsync -avz --delete $(EXCLUDES) ./compiled/ $(WEBSITE):/ @rsync -avz --delete ./archive/ $(WEBSITE):/archive/ @rsync -avz --delete ./slides/ $(WEBSITE):/slides/ # # Offline copies # usb_stick: sudo rsync -av --exclude=backups --delete ./ /media/usb/$(PROJECT)/