Add a generic Makefile to generate all types of documents.

This commit is contained in:
Graham Williams 2017-03-26 20:36:24 +08:00
Родитель 513ba589e7
Коммит f33ce6cb89
3 изменённых файлов: 814 добавлений и 1948 удалений

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

68
Makefile Normal file
Просмотреть файл

@ -0,0 +1,68 @@
BASE := $(dir $(lastword $(MAKEFILE_LIST)))
RMD=$(wildcard *_*.Rmd)
RCD=$(RMD:.Rmd=.R)
HTM=$(RMD:.Rmd=.html)
PDF=$(RMD:.Rmd=.pdf)
ODT=$(RMD:.Rmd=.odt)
DOC=$(RMD:.Rmd=.docx)
MDN=$(RMD:.Rmd=.md)
IPY=$(RMD:.Rmd=.ipynb)
site: $(RCD) $(PDF) $(HTM) $(DOC) $(ODT) $(MDN) $(IPY)
Rscript -e 'rmarkdown::render_site("index.Rmd")'
site.view: site
firefox _site/index.html &
book.pdf: *.Rmd
Rscript -e 'bookdown::render_book("index.Rmd", output_format="bookdown::pdf_book")'
mv _book/_main.pdf $@
rmdir _book
book.html: *.Rmd
Rscript -e 'bookdown::render_book("index.Rmd", output_format="bookdown::gitbook")'
mv _book _html
%.R: %.Rmd
Rscript -e 'knitr::purl("$*.Rmd")'
%.md: %.Rmd
Rscript -e 'rmarkdown::render("$*.Rmd", "rmarkdown::md_document")'
%.html: %.Rmd
Rscript -e 'rmarkdown::render("$*.Rmd", "rmarkdown::html_document")'
%.pdf: %.Rmd
Rscript -e 'rmarkdown::render("$*.Rmd", "rmarkdown::pdf_document")'
%.view: %.pdf
evince $^
%.ipynb: %.Rmd
notedown $^ --nomagic > $@
sh $(BASE)fix_ipynb.sh $@
%.docx: %.Rmd
Rscript -e 'rmarkdown::render("$*.Rmd", "rmarkdown::word_document")'
%.odt: %.Rmd
Rscript -e 'rmarkdown::render("$*.Rmd", "rmarkdown::odt_document")'
install: realclean site
sudo rsync -avzh _site/ /var/www/html/resources/
sudo chmod -R go+rX /var/www/html/resources/
rsync -avzh _site/*.ipynb adsapldsvm:notebooks/dsr/
firefox /var/www/html/resources/index.html &
clean:
rm -f *.docx *.R *.odt *.pdf *.html *.md *.ipynb
realclean: clean
rm -f *~
rm -rf _book _site _html data models
rm -rf app_education_files
wwwclean:
sudo rm -rf /var/www/html/resources/*

25
fix_ipynb.sh Normal file
Просмотреть файл

@ -0,0 +1,25 @@
#!/bin/sh
#
# Author: Graham Williams
# Date: 20170111
#
# This is not done by notedown but it is what is on the end of a
# sample notebook so add it here and the document kernel is recognised
# as R.
perl -pi -e 's|"metadata": \{\},| "metadata": {\
"anaconda-cloud": {},\
"kernelspec": {\
"display_name": "R",\
"language": "R",\
"name": "ir"\
},\
"language_info": {\
"codemirror_mode": "r",\
"file_extension": ".r",\
"mimetype": "text/x-r-source",\
"name": "R",\
"pygments_lexer": "r",\
"version": "3.2.2"\
}\
},|' $1