forked from swaroopch/byte-of-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.bash
More file actions
executable file
·144 lines (113 loc) · 3.6 KB
/
Copy pathcommands.bash
File metadata and controls
executable file
·144 lines (113 loc) · 3.6 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
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
143
144
#!/usr/bin/env bash
## References:
## http://asciidoctor.org/docs/asciidoc-writers-guide/
SLUG="byte_of_python"
FOPUB="$HOME/code/asciidoctor/asciidoctor-fopub/fopub"
function doctor() {
backend=$1
shift
asciidoctor -n -a 'source-highlighter=pygments' -b $backend ${SLUG}.asciidoc
}
function make_html () {
doctor html5
ls -lh "$PWD/$SLUG.html"
}
function make_pdf () {
doctor docbook
$FOPUB ${SLUG}.xml
# OR
# a2x -f pdf --fop ${SLUG}.asciidoc
ls -lh "$PWD/$SLUG.pdf"
}
# TODO Syntax highlighting in output
# - http://docbook.sourceforge.net/release/xsl/current/doc/fo/highlight.source.html
# - ~/code/asciidoctor/asciidoctor-fopub/src/dist/docbook-xsl/xslthl-config.xml
# - http://www.vogella.com/tutorials/DocBook/article.html#advanced_syntaxhighlighting
function make_epub () {
doctor docbook
dbtoepub ${SLUG}.xml
# OR
# a2x -f epub ${SLUG}.xml
epubcheck "$PWD/$SLUG.epub"
ls -lh "$PWD/$SLUG.epub"
}
function make_mobi () {
doctor html5
kindlegen -verbose ${SLUG}.html -o ${SLUG}.mobi
ls -lh "$PWD/$SLUG.mobi"
}
function install_deps_osx () {
# http://brew.sh
brew update
brew install docbook docbook-xsl fop epubcheck git
brew tap homebrew/binary
brew install kindlegen
# brew install asciidoc
# http://s3tools.org/usage
pip install -U python-magic
pip install -U https://github.com/s3tools/s3cmd/archive/master.zip
# http://asciidoctor.org/docs/install-asciidoctor-macosx/
sudo gem update --system
sudo gem install asciidoctor -N
# https://groups.google.com/forum/#!topic/asciidoc/FC-eOwU8rYg
echo >> ~/.bash_profile
echo 'export XML_CATALOG_FILES="/usr/local/etc/xml/catalog"' >> ~/.bash_profile
# https://github.com/asciidoctor/asciidoctor-fopub/blob/master/README.adoc
mkdir -p $HOME/code/asciidoctor/
cd $HOME/code/asciidoctor/
git clone https://github.com/asciidoctor/asciidoctor-fopub
}
function install_deps_linux() {
sudo apt-get update
sudo apt-get install -y dbtoepub docbook docbook-xsl epubcheck fop git python-pip python-virtualenv ruby2.0 ruby2.0-dev
# TODO Perhaps use rvm / rbenv to point to Ruby 2.0 by default
sudo pip install -U python-magic
sudo pip install -U https://github.com/s3tools/s3cmd/archive/master.zip
sudo gem2.0 install --no-rdoc --no-ri asciidoctor kindlegen pygments.rb
echo "Update PATH to point to kindlegen - see `gem2.0 contents kindlegen | fgrep bin`"
mkdir -p $HOME/code/asciidoctor/
cd $HOME/code/asciidoctor/
git clone https://github.com/asciidoctor/asciidoctor-fopub
}
function s3_put () {
filename=$1
shift
if [[ -f $filename ]]
then
s3cmd --verbose \
--access_key=$AWS_ACCESS_KEY \
--secret_key=$AWS_SECRET_KEY \
--acl-public \
put \
"$filename" \
"s3://files.swaroopch.com/python/$filename"
fi
}
# https://en.wikipedia.org/wiki/Tput#Usage
function say () {
echo "$(tput setaf 2)$(tput bold)$@$(tput sgr0)"
}
function make_upload () {
CWD=$PWD
say "Generating HTML"
make_html
say "Syncing to blog server"
cp -v "$SLUG.html" ../blog/notes/python/index.html
rm -vf ../blog/notes/python/*.png
cp -v *.png ../blog/notes/python/
cd ../blog
blog_sync # Defined in ~/.bash_profile
cd $CWD
say "Generating EPUB"
make_epub
say "Uploading EPUB"
s3_put "$SLUG.epub"
say "Generating PDF"
make_pdf
say "Uploading PDF"
s3_put "$SLUG.pdf"
say "Generating MOBI"
make_mobi
say "Uploading MOBI"
s3_put "$SLUG.mobi"
}