Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """Update Ghost via cli and change CSS for Casper default theme.
- I like Casper, the Ghost standard theme. But I cannot stand the fact that the
- first paragraph in every blog post is immensely huge. This might make sense for
- journalists and magazines, but not for the majority of blogs. Since there are
- often Casper updates with a new Ghost version, I needed a solution to
- a) Update Ghost to the latest and greatest via cli
- b) Remove the CSS for this horrible, horrible first paragraph.
- Voila! It is not fool-proof, it is not beautiful, but it works and is in use.
- """
- import re
- import os
- import argparse
- import glob
- import sys
- if __name__ == "__main__":
- # Parsing arguments
- parser = argparse.ArgumentParser(
- prog='update_ghost_casper.py'
- )
- parser.add_argument(
- '-p',
- '--path',
- type=str,
- help='Ghost installation path'
- )
- args = parser.parse_args()
- ghost_path = args.path
- # Take the Ghost installation path as an argument.
- # If there is no path given, we stop right here.
- if ghost_path is None:
- print('No path specified')
- sys.exit(1)
- # Changing in the Ghost install dir and updating
- os.chdir(ghost_path)
- os.system('ghost update')
- # Changing into the Casper directory, install gulp and all of its
- # 500 million fucking prerequisites
- os.chdir('content/themes/casper/')
- npm_install_cmd = ('npm install autoprefixer cssnano gulp gulp-livereload '
- 'gulp-nodemon gulp-postcss gulp-sourcemaps gulp-util '
- 'gulp-watch postcss-color-function gulp-zip '
- 'postcss-custom-properties postcss-easy-import'
- )
- os.system(npm_install_cmd)
- # Delete the old minified .map and CSS file
- built_css_files = 'assets/built/screen.css*'
- for file in glob.glob(built_css_files):
- os.remove(file)
- # Backup copy of the current CSS file
- os.rename('assets/css/screen.css', 'assets/css/screen.css.sav')
- # Yes, I know you should not 'slurp' the whole file, but due to the regex
- # it was the solution with the least headache potential I could think of
- with open("assets/css/screen.css.sav", 'r+') as f:
- css = f.read()
- f.close()
- # Remove that fucking CSS paragraph. Rip it out.
- newcss = re.sub('\.post-template \.kg-card-markdown > '
- 'p:first-child \{\n.*\n.*\n\}\n\n', '', css)
- # Write the new, updated CSS file to disk
- with open("assets/css/screen.css", 'w') as f:
- f.write(newcss)
- f.close()
- # Recreate the map and minified CSS file
- os.system('gulp css')
- # Go back to the Ghost install directory and restart to apply changes
- os.chdir(ghost_path)
- os.system('ghost restart')
Add Comment
Please, Sign In to add comment