-
Notifications
You must be signed in to change notification settings - Fork 24
/
Makefile
92 lines (68 loc) · 2.28 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
# Makefile for generating EPubs from a Jekyll dir
# Configuration: change these variables
TITLE = your title here
AUTHOR = your name here
# change these if you like; they will default to the title you fill in above
EPUB_FILENAME = $(TITLE).epub
PDF_FILENAME = $(TITLE).pdf
LICENSE = Creative Commons Non-Commercial Share Alike 3.0
LANGUAGE = en-us
# path to markdown files (default: current directory)
MD_PATH = .
# Paths to chapters, in order, separated by spaces. Should be all on one line;
# if the line becomes too long, you may continue a line by putting a backslash
# at the end of the line. Paths are relative to MD_PATH.
MD_FILES = article1.md article2.md article3.md article4.md article5.md \
article6.md article7.md article8.md article9.md article10.md
# paths to programs/files
PANDOC = pandoc
# folder where to put the generated files
EPUB_FOLDER = _epub
PDF_FOLDER = _pdf
TITLE_PAGE_FILE = title.md
METADATA_FILE = $(EPUB_FOLDER)/metadata.xml
EPUB_MD_PREREQS = $(addprefix $(EPUB_FOLDER)/, $(MD_FILES))
.PHONY: epub
epub: $(EPUB_FILENAME)
.PHONY: title
title: $(TITLE_PAGE_FILE)
.PHONY: metadata
metadata: $(METADATA_FILE)
# NB: THe PDF strips out all of the metadata from the markdown files for now.
.PHONY: pdf
pdf: $(PDF_FILENAME)
.PHONY: clean
clean:
-rm $(TITLE_PAGE_FILE)
-rm $(METADATA_FILE)
-rm -r $(EPUB_FOLDER)
-rm -r $(PDF_FOLDER)
$(EPUB_FOLDER):
mkdir -p $@
$(PDF_FOLDER):
mkdir -p $@
$(TITLE_PAGE_FILE):
echo "% $(AUTHOR)" > $@
echo "% $(TITLE)" >> $@
echo '' >> $@
$(METADATA_FILE): | $(EPUB_FOLDER)
echo "<dc:rights>$(LICENSE)</dc:rights>" > $@
echo "<dc:language>$(LANGUAGE)</dc:language>" >> $@
echo '' >> $@
$(EPUB_FILENAME): $(TITLE_PAGE_FILE) $(METADATA_FILE) $(EPUB_MD_PREREQS)
$(PANDOC) -S --epub-metadata=$(METADATA_FILE) -o $(EPUB_FILENAME) \
$(TITLE_PAGE_FILE) $(EPUB_MD_PREREQS)
$(PDF_FILENAME): $(TITLE_PAGE_FILE) $(addprefix $(PDF_FOLDER)/, $(MD_FILES))
$(PANDOC) -S -o $@ $^
define MD_SUB
cp $< $@
perl -ni -e 'if($$y){if(/^---$$/){$$y=0;next}s/^layout:.*$$//;\
s/^title:\s*(.*)$$/# $$1/;s/^author:\s*(.*)$$/**$$1**/;print;} \
$$y = 1 if /^---$$/;print unless $$y' $@
perl -p0i -e 's/^\s*//' $@
echo '' >> $@
endef
$(EPUB_FOLDER)/%.md: $(MD_PATH)/%.md | $(EPUB_FOLDER)
$(MD_SUB)
$(PDF_FOLDER)/%.md: $(MD_PATH)/%.md | $(PDF_FOLDER)
$(MD_SUB)