-
-
Save bmaupin/6e3649af73120fac2b6907169632be2c to your computer and use it in GitHub Desktop.
body { | |
text-align: justify; | |
} | |
code, pre { | |
font-family: "DejaVuSansMono", monospace; | |
} | |
h1, h2, h3, h4, h5, h6 { | |
text-align: left; | |
} | |
pre { | |
/* Don't make it too dark or it will be harder to read on e-ink devices */ | |
background-color: #f5f5f5; | |
border-radius: 3px; | |
font-size: 0.85em; | |
padding: 10px; | |
text-align: left; | |
/* Wrap the text of pre sections */ | |
white-space: pre-wrap; | |
} | |
@font-face { | |
font-family: "DejaVuSansMono"; | |
src: url(DejaVuSansMono.ttf) format("truetype"); | |
} |
sudo apt install fonts-dejavu-core git pandoc unzip zip | |
git clone https://github.com/getify/You-Dont-Know-JS.git | |
wget -O You-Dont-Know-JS/epub.css https://gist.githubusercontent.com/bmaupin/6e3649af73120fac2b6907169632be2c/raw/epub.css | |
cd You-Dont-Know-JS | |
# Clean up redundant headings that end up getting split into separate chapters by themselves | |
find . -iname "*.md" -exec sed -i '/# You Don'\''t Know JS.*/d' {} \; | |
# Fix <br> tags which pandoc won't convert to <br /> | |
find . -iname "*.md" -exec sed -i 's#<br>#<br />#' {} \; | |
# Close img tags | |
find . -iname "*.md" -exec sed -i -r 's#(<img.*[^/])>#\1 />#' {} \; | |
cd up\ \&\ going | |
# --no-highlight is used because syntax highlighting can make reading more difficult on e-ink devices | |
pandoc -S -o ../"You Don't Know JS: Up & Going.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: Up & Going" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
apA.md | |
cd .. | |
cd scope\ \&\ closures | |
wget -O foreword.html https://shanehudson.net/2014/06/03/foreword-dont-know-js/ | |
pandoc -S -o foreword.md foreword.html | |
pandoc -S -o ../"You Don't Know JS: Scope & Closures.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: Scope & Closures" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
ch4.md \ | |
ch5.md \ | |
apA.md \ | |
apB.md \ | |
apC.md \ | |
apD.md | |
cd .. | |
cd this\ \&\ object\ prototypes | |
pandoc -S -o ../"You Don't Know JS: this & Object Prototypes.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: this & Object Prototypes" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
ch4.md \ | |
ch5.md \ | |
ch6.md \ | |
apA.md \ | |
apB.md | |
cd .. | |
cd types\ \&\ grammar | |
pandoc -S -o ../"You Don't Know JS: Types & Grammar.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: Types & Grammar" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
ch4.md \ | |
ch5.md \ | |
apA.md \ | |
apB.md | |
cd .. | |
cd async\ \&\ performance | |
pandoc -S -o ../"You Don't Know JS: Async & Performance.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: Async & Performance" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
ch4.md \ | |
ch5.md \ | |
ch6.md \ | |
apA.md \ | |
apB.md \ | |
apC.md | |
cd .. | |
cd es6\ \&\ beyond | |
pandoc -S -o ../"You Don't Know JS: ES6 & Beyond.epub" \ | |
--epub-cover-image=cover.jpg \ | |
--epub-embed-font=/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf \ | |
--epub-stylesheet=../epub.css \ | |
--no-highlight \ | |
-M author="Kyle Simpson" \ | |
-M title="You Don't Know JS: ES6 & Beyond" \ | |
foreword.md \ | |
../preface.md \ | |
ch1.md \ | |
ch2.md \ | |
ch3.md \ | |
ch4.md \ | |
ch5.md \ | |
ch6.md \ | |
ch7.md \ | |
ch8.md \ | |
apA.md | |
cd .. | |
# Workaround for https://github.com/jgm/pandoc/issues/3792 | |
for epubfile in *.epub; do | |
mkdir tmp-epub | |
cd tmp-epub | |
unzip ../"$epubfile" | |
sed -i 's/ & / \& /' title_page.xhtml | |
zip -X ../"$epubfile" mimetype | |
zip -rX ../"$epubfile" * -x mimetype | |
cd .. | |
rm -rf tmp-epub | |
done |
Very cool, thanks for sharing!
Just tried running this on a machine with Linux freshly installed. Had to apt install
zip and unzip, too.
Forked and added those to the top line. Thanks for writing this script!
@bennett39 Updated, thanks!
@bmaupin thanks for this.
My version of pandoc (2.7.2) indicates that --epub-stylesheet
is to be replaced with --css
. Similarly, the -S
flag is deprecated ; instead, the formulation pandoc -f markdown+smart -o ../"You Don't Know JS: Up & Going.epub"
may be used.
On Arch Linux, you will need to install the package ttf-dejavu
(not fonts-dejavu-core
) and modify the font path, to /usr/share/fonts/TTF/DejaVuSansMono.ttf
.
@bmaupin Thanks for sharing this!
I made a docker image for this. So people don't have to install dependencies on their machine:
https://github.com/gongzhang/you-dont-know-js-epub
@bmaupin thanks for this snippet, i forked it and modified it to work on macOS and also added a script to download Kyle's latest book on functional programming in JS.
my fork is available here for anyone interested in my macos version