-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
54 lines (42 loc) · 2.7 KB
/
Copy pathMakefile
File metadata and controls
54 lines (42 loc) · 2.7 KB
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
# usage: make help
.PHONY: help spell prep-html-files html html-local pdf epub upload check-links-local check-links-all clean
.DEFAULT_GOAL := help
help: ## this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-22s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
# pip install codespell
spell: ## spellcheck
@codespell --write-changes --skip "*.pdf" --skip "*.json"
prep-html-files: ## prepare html-files
echo book-front.html > chapters-html.txt
perl -ne 's|\.md|.html|; print' chapters-md.txt >> chapters-html.txt
html: prep-html-files ## make html version w/ scripts linking to their url at my github repo
python build/mdbook/md-to-html.py
html-local: prep-html-files ## make html version w/ scripts remaining local
python build/mdbook/md-to-html.py --local
pdf: html ## make pdf version (from html files)
prince --no-author-style -s build/prince_style.css --pdf-title="Stas Bekman - Stas' Python Cookbook ($$(date))" -o out1.pdf $$(cat chapters-html.txt | tr "\n" " ")
pdftk out1.pdf dump_data output pdf-bookmarks.txt
pdftk out1.pdf cat 2-end 1 output out2.pdf
pdftk images/Python-Cookbook-book-cover.pdf out2.pdf output out3.pdf
pdftk out3.pdf update_info pdf-bookmarks.txt output "Stas Bekman - Stas' Python Cookbook.pdf"
epub: html ## make epub version (from html files)
python build/mdbook/preprocess-html-for-epub.py && \
pandoc --from html --to epub3 \
--output "Stas Bekman - Stas' Python Cookbook.epub" \
--metadata title="Stas' Python Cookbook" \
--metadata author="Stas Bekman" \
--metadata date="$$(date +%Y-%m-%d)" \
--metadata language="en" \
--epub-cover-image=images/Python-Cookbook-book-cover.png \
--resource-path=.:$$(cat chapters-html.txt | xargs -n1 dirname | awk '!seen[$$0]++' | tr "\n" ":") \
$$(cat chapters-html.txt | tr "\n" " ")
upload: pdf epub ## upload pdf to the hub
cp "Stas Bekman - Stas' Python Cookbook.pdf" python-cookbook/
cp "Stas Bekman - Stas' Python Cookbook.epub" python-cookbook/
cd python-cookbook/ && git commit -m "new version" "Stas Bekman - Stas' Python Cookbook.pdf" "Stas Bekman - Stas' Python Cookbook.epub" && git push
check-links-local: html-local ## check local links
linkchecker --config build/linkcheckerrc $$(cat chapters-html.txt | tr "\n" " ") | tee linkchecker-local.txt
check-links-all: html ## check all links including external ones
linkchecker --config build/linkcheckerrc $$(cat chapters-html.txt | tr "\n" " ") --check-extern --user-agent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0" | tee linkchecker-all.txt
clean: ## remove build files
find . -name "*html" -exec rm {} \;