Guest User

Untitled

a guest
Nov 24th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #!/usr/bin/env python
  2. """Update Ghost via cli and change CSS for Casper default theme.
  3.  
  4. I like Casper, the Ghost standard theme. But I cannot stand the fact that the
  5. first paragraph in every blog post is immensely huge. This might make sense for
  6. journalists and magazines, but not for the majority of blogs. Since there are
  7. often Casper updates with a new Ghost version, I needed a solution to
  8. a) Update Ghost to the latest and greatest via cli
  9. b) Remove the CSS for this horrible, horrible first paragraph.
  10.  
  11. Voila! It is not fool-proof, it is not beautiful, but it works and is in use.
  12. """
  13.  
  14. import re
  15. import os
  16. import argparse
  17. import glob
  18. import sys
  19.  
  20. if __name__ == "__main__":
  21. # Parsing arguments
  22. parser = argparse.ArgumentParser(
  23. prog='update_ghost_casper.py'
  24. )
  25. parser.add_argument(
  26. '-p',
  27. '--path',
  28. type=str,
  29. help='Ghost installation path'
  30. )
  31. args = parser.parse_args()
  32. ghost_path = args.path
  33. # Take the Ghost installation path as an argument.
  34. # If there is no path given, we stop right here.
  35.  
  36. if ghost_path is None:
  37. print('No path specified')
  38. sys.exit(1)
  39.  
  40. # Changing in the Ghost install dir and updating
  41. os.chdir(ghost_path)
  42. os.system('ghost update')
  43.  
  44. # Changing into the Casper directory, install gulp and all of its
  45. # 500 million fucking prerequisites
  46. os.chdir('content/themes/casper/')
  47. npm_install_cmd = ('npm install autoprefixer cssnano gulp gulp-livereload '
  48. 'gulp-nodemon gulp-postcss gulp-sourcemaps gulp-util '
  49. 'gulp-watch postcss-color-function gulp-zip '
  50. 'postcss-custom-properties postcss-easy-import'
  51. )
  52. os.system(npm_install_cmd)
  53.  
  54. # Delete the old minified .map and CSS file
  55. built_css_files = 'assets/built/screen.css*'
  56. for file in glob.glob(built_css_files):
  57. os.remove(file)
  58.  
  59. # Backup copy of the current CSS file
  60. os.rename('assets/css/screen.css', 'assets/css/screen.css.sav')
  61. # Yes, I know you should not 'slurp' the whole file, but due to the regex
  62. # it was the solution with the least headache potential I could think of
  63. with open("assets/css/screen.css.sav", 'r+') as f:
  64. css = f.read()
  65. f.close()
  66.  
  67. # Remove that fucking CSS paragraph. Rip it out.
  68. newcss = re.sub('\.post-template \.kg-card-markdown > '
  69. 'p:first-child \{\n.*\n.*\n\}\n\n', '', css)
  70.  
  71. # Write the new, updated CSS file to disk
  72. with open("assets/css/screen.css", 'w') as f:
  73. f.write(newcss)
  74. f.close()
  75.  
  76. # Recreate the map and minified CSS file
  77. os.system('gulp css')
  78. # Go back to the Ghost install directory and restart to apply changes
  79. os.chdir(ghost_path)
  80. os.system('ghost restart')
Add Comment
Please, Sign In to add comment