commands.bash 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. sudo pip install -U python-magic
  48. sudo 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. # brew install s3cmd
  66. s3cmd --verbose \
  67. --access_key=$AWS_ACCESS_KEY \
  68. --secret_key=$AWS_SECRET_KEY \
  69. --acl-public \
  70. put \
  71. "$filename" \
  72. "s3://files.swaroopch.com/python/$filename"
  73. fi
  74. }
  75. # https://en.wikipedia.org/wiki/Tput#Usage
  76. function say () {
  77. echo "$(tput setaf 2)$(tput bold)$@$(tput sgr0)"
  78. }
  79. function make_upload () {
  80. CWD=$PWD
  81. say "Generating HTML"
  82. make_html
  83. say "Syncing to blog server"
  84. cp -v "$SLUG.html" ../blog/notes/python/index.html
  85. rm -v ../blog/notes/python/*.png
  86. cp -v *.png ../blog/notes/python/
  87. cd ../blog
  88. blog_sync # Defined in ~/.bash_profile
  89. cd $CWD
  90. say "Generating EPUB"
  91. make_epub
  92. say "Uploading EPUB"
  93. s3_put "$SLUG.epub"
  94. say "Generating PDF"
  95. make_pdf
  96. say "Uploading PDF"
  97. s3_put "$SLUG.pdf"
  98. say "Generating MOBI"
  99. make_mobi
  100. say "Uploading MOBI"
  101. s3_put "$SLUG.mobi"
  102. }