forked from swcarpentry/DEPRECATED-bc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
142 lines (115 loc) · 4.63 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#======================================================================
# Re-make lecture materials.
#======================================================================
# Directories.
SITE = _site
INSTALL = $(HOME)/sites/software-carpentry.org/v5
LINKS = /tmp/bc-links
CACHED = .
# Templates for nbconvert and Pandoc.
IPYNB_TPL = _templates/ipynb.tpl
# Temporary book file.
BOOK_MD = ./book.md
# Principal target files.
INDEX = $(SITE)/index.html
# Jekyll configuration file.
CONFIG = _config.yml
# Directives.
.INTERMEDIATE : $(BOOK_MD)
#----------------------------------------------------------------------
# Specify the default target before any other targets are defined so
# that we're sure which one Make will choose.
#----------------------------------------------------------------------
all : commands
#----------------------------------------------------------------------
# Extra files the site depends on.
#----------------------------------------------------------------------
EXTRAS = \
$(wildcard css/*.css) \
$(wildcard css/*/*.css) \
$(wildcard novice/*/img/*.png) \
$(wildcard novice/*/img/*.svg)
#----------------------------------------------------------------------
# Create Markdown versions of IPython Notebooks in CACHED directory.
# This is currently the same as the source directory so that files
# will be in the right places after Jekyll converts them.
# ----------------------------------------------------------------------
# IPython Notebooks (split by directory so that they can be
# interpolated into other variables later on).
IPYNB_SRC_PYTHON = \
$(sort $(wildcard novice/python/??-*.ipynb)) \
$(sort $(wildcard intermediate/python/??-*.ipynb))
IPYNB_SRC_SQL = \
$(sort $(wildcard novice/sql/??-*.ipynb))
# Notebooks converted to Markdown.
IPYNB_TX_PYTHON = $(patsubst %.ipynb,$(CACHED)/%.md,$(IPYNB_SRC_PYTHON))
IPYNB_TX_SQL = $(patsubst %.ipynb,$(CACHED)/%.md,$(IPYNB_SRC_SQL))
# Convert a .ipynb to .md.
$(CACHED)/%.md : %.ipynb $(IPYNB_TPL)
ipython nbconvert --template=$(IPYNB_TPL) --to=markdown --output="$(subst .md,,$@)" "$<"
#----------------------------------------------------------------------
# Build everything with Jekyll.
#----------------------------------------------------------------------
# Book source (in Markdown). These are listed in the order in which
# they appear in the final book-format version of the notes, and
# include Markdown files generated by other tools from other formats.
BOOK_SRC = \
intro.md \
team.md \
novice/shell/index.md $(sort $(wildcard novice/shell/??-*.md)) \
novice/git/index.md $(sort $(wildcard novice/git/??-*.md)) \
novice/python/index.md $(IPYNB_TX_PYTHON) \
novice/sql/index.md $(IPYNB_TX_SQL) \
novice/extras/index.md $(sort $(wildcard novice/extras/??-*.md)) \
novice/teaching/index.md $(sort $(wildcard novice/teaching/??-*.md)) \
novice/ref/index.md $(sort $(wildcard novice/ref/??-*.md)) \
bib.md \
gloss.md \
rules.md \
LICENSE.md
# All source pages (including things not in the book).
PAGES_SRC = \
contents.md \
$(wildcard intermediate/python/*.md) \
$(BOOK_SRC)
# Build the temporary input for the book by concatenating relevant
# sections of Markdown files, patching glossary references and image
# paths, and then running the whole shebang through Jekyll at the same
# time as everything else.
$(BOOK_MD) : $(PAGES_SRC) bin/make-book.py
python bin/make-book.py $(BOOK_SRC) > $@
# Convert from Markdown to HTML. This builds *all* the pages (Jekyll
# only does batch mode), and erases the SITE directory first, so
# having the output index.html file depend on all the page source
# Markdown files triggers the desired build once and only once.
$(INDEX) : $(BOOK_MD) $(CONFIG) $(EXTRAS)
jekyll -t build -d $(SITE)
rm -rf $(SITE)/novice/*/??-*_files
#----------------------------------------------------------------------
# Targets.
#----------------------------------------------------------------------
## commands : show all commands.
commands :
@grep -E '^##' Makefile | sed -e 's/## //g'
## site : build the site as GitHub will see it.
site : $(INDEX)
## install : install on the server.
install : $(INDEX)
rm -rf $(INSTALL)
mkdir -p $(INSTALL)
cp -r $(SITE)/* $(INSTALL)
mv $(INSTALL)/contents.html $(INSTALL)/index.html
## contribs : list contributors (uses .mailmap file).
contribs :
git log --pretty=format:%aN | sort | uniq
## fixme : find places where fixes are needed.
fixme :
@grep -i -n FIXME $$(find novice -type f -print | grep -v .ipynb_checkpoints)
## clean : clean up all generated files.
clean : tidy
rm -rf $(SITE)
## tidy : clean up odds and ends.
tidy :
rm -rf \
$$(find . -name '*~' -print) \
$$(find . -name '*.pyc' -print)