Ghost修改screen.css的脚本

Ghost更新越来越频繁,每次都要手动更新css实在伤不起。。。

反正改动的地方也不多,干脆做成一键脚本好了,把之前upgrade的脚本再扩展一下:

首先更改#7,改动如下,增加了change logo position

#change post page what to show...
echo '7. replace "excerpt" with "content" ---------------'
#excerpt -> content
#read more -> >>
sed -i "s#<p>{{excerpt words=\"26\"}} <a class=\"read-more\" href=\"{{url}}\">&raquo;#<p>{{content words=\"32\"}} <a class=\"read-more\" href=\"{{url}}\">\&raquo;\&raquo;#g" ./content/themes/casper/partials/loop.hbs

#change logo position
sed -i 's~{{#if @blog.logo}}<a class="blog-logo" href="{{@blog.url}}"><img src="{{@blog.logo}}" alt="Blog Logo" /></a>{{/if}}~~g' ./content/themes/casper/index.hbs
sed -i 's~<h1 class="page-title">{{@blog.title}}</h1>~{{#if @blog.logo}}<a class="blog-logo" href="{{@blog.url}}/about"><img src="{{@blog.logo}}" alt="Blog Logo" /></a>{{/if}}<h1 class="page-title">{{@blog.title}}</h1>~g' ./content/themes/casper/index.hbs

再就是考虑到自己智商太低,难以驾驭sed的多行匹配,所以祭出Python;脚本中加上这句:

#call python to do multiple lines replacement
python ~/ghost_css_adjustment.py

import re

cssfile='./content/themes/casper/assets/css/screen.css'
infile=open(cssfile, 'r')

replacements = {
            '.blog-logo {([^\}]*)((float: left){1})([^\{]*)}':'.blog-logo {\n    display: block;\n    float: center;\n    background: none !important;\n    border: none !important;\n}', #make logo center
            '.blog-logo img {([^\}]*)((width: auto){1})([^\{]*)}':'.blog-logo img {\n    width: 100px;\n    height: 100px;\n    border: 2px solid white;\n    -webkit-border-radius: 100px;\n    -moz-border-radius: 100px;\n    -ms-border-radius: 100px;\n    -o-border-radius: 100px;\n    border-radius: 100px;\n}', #make logo likes pertty
            '.blog-logo img {([\s]*)((height: 26px;){1})([\s]*)}':'', #remove useless blog-logo img css
            '.blog-logo img {([\s]*)((max-height: 80px;){1})([\s]*)}':'', #same as above
            '.blog-logo img {([\s]*)((padding: 4px 0;){1})([\s]*)}':'', #same as above
            '.blog-logo {([\s]*)((padding: 10px 10px;){1})([\s]*)}':'', #same as above
            '.post-content img {':'.post-content img, .post-excerpt img {' #make sure the excerpt img apparanet like content
            }

data = infile.read()
for src, target in replacements.iteritems():
        data = re.sub(src, target, data)
infile.close()

outfile = open(cssfile, 'w')
outfile.write(data)
outfile.close()

至此,以后升级终于可以轻松一键搞定了~~ LOL~~

记录一下~