commands.bash 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #!/usr/bin/env bash
  2. ## References:
  3. ## http://asciidoctor.org/docs/asciidoc-writers-guide/
  4. SLUG="byte_of_python"
  5. FOPUB="$HOME/code/asciidoctor/asciidoctor-fopub/fopub"
  6. function doctor() {
  7. backend=$1
  8. shift
  9. asciidoctor -n -a 'source-highlighter=pygments' -b $backend ${SLUG}.asciidoc
  10. }
  11. function make_html () {
  12. doctor html5
  13. ls -lh "$PWD/$SLUG.html"
  14. }
  15. function make_pdf () {
  16. doctor docbook
  17. $FOPUB ${SLUG}.xml
  18. # OR
  19. # a2x -f pdf --fop ${SLUG}.asciidoc
  20. ls -lh "$PWD/$SLUG.pdf"
  21. }
  22. # TODO Syntax highlighting in output
  23. # - http://docbook.sourceforge.net/release/xsl/current/doc/fo/highlight.source.html
  24. # - ~/code/asciidoctor/asciidoctor-fopub/src/dist/docbook-xsl/xslthl-config.xml
  25. # - http://www.vogella.com/tutorials/DocBook/article.html#advanced_syntaxhighlighting
  26. function make_epub () {
  27. doctor docbook
  28. dbtoepub ${SLUG}.xml
  29. # OR
  30. # a2x -f epub ${SLUG}.xml
  31. epubcheck "$PWD/$SLUG.epub"
  32. ls -lh "$PWD/$SLUG.epub"
  33. }
  34. function make_mobi () {
  35. doctor html5
  36. kindlegen -verbose ${SLUG}.html -o ${SLUG}.mobi
  37. ls -lh "$PWD/$SLUG.mobi"
  38. }
  39. function install_deps_osx () {
  40. # http://brew.sh
  41. brew update
  42. brew install docbook docbook-xsl fop epubcheck git
  43. brew tap homebrew/binary
  44. brew install kindlegen
  45. # brew install asciidoc
  46. # http://s3tools.org/usage
  47. pip install -U python-magic
  48. pip install -U https://github.com/s3tools/s3cmd/archive/master.zip
  49. # http://asciidoctor.org/docs/install-asciidoctor-macosx/
  50. sudo gem update --system
  51. sudo gem install asciidoctor -N
  52. # https://groups.google.com/forum/#!topic/asciidoc/FC-eOwU8rYg
  53. echo >> ~/.bash_profile
  54. echo 'export XML_CATALOG_FILES="/usr/local/etc/xml/catalog"' >> ~/.bash_profile
  55. # https://github.com/asciidoctor/asciidoctor-fopub/blob/master/README.adoc
  56. mkdir -p $HOME/code/asciidoctor/
  57. cd $HOME/code/asciidoctor/
  58. git clone https://github.com/asciidoctor/asciidoctor-fopub
  59. }
  60. function s3_put () {
  61. filename=$1
  62. shift
  63. if [[ -f $filename ]]
  64. then
  65. s3cmd --verbose \
  66. --access_key=$AWS_ACCESS_KEY \
  67. --secret_key=$AWS_SECRET_KEY \
  68. --acl-public \
  69. put \
  70. "$filename" \
  71. "s3://files.swaroopch.com/python/$filename"
  72. fi
  73. }
  74. # https://en.wikipedia.org/wiki/Tput#Usage
  75. function say () {
  76. echo "$(tput setaf 2)$(tput bold)$@$(tput sgr0)"
  77. }
  78. function make_upload () {
  79. CWD=$PWD
  80. say "Generating HTML"
  81. make_html
  82. say "Syncing to blog server"
  83. cp -v "$SLUG.html" ../blog/notes/python/index.html
  84. rm -v ../blog/notes/python/*.png
  85. cp -v *.png ../blog/notes/python/
  86. cd ../blog
  87. blog_sync # Defined in ~/.bash_profile
  88. cd $CWD
  89. say "Generating EPUB"
  90. make_epub
  91. say "Uploading EPUB"
  92. s3_put "$SLUG.epub"
  93. say "Generating PDF"
  94. make_pdf
  95. say "Uploading PDF"
  96. s3_put "$SLUG.pdf"
  97. say "Generating MOBI"
  98. make_mobi
  99. say "Uploading MOBI"
  100. s3_put "$SLUG.mobi"
  101. }