Last active
May 14, 2017 16:24
-
-
Save tioover/6d11f181ff58af2a95ebd5d3097a91c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
Simple Jekyll site manage script. | |
''' | |
import os | |
import sys | |
import datetime | |
# Settings | |
POSTS_DIR = '_posts' | |
TARGET_DIR = '_site' | |
OPEN_EDITOR_COMMAND = 'open' | |
TIMEZONE = '+0800' # Maybe shoud use pytz? | |
SSH = "[email protected]:/var/www/ioover.net/html/" | |
run = os.system | |
def depoly(): | |
''' Your depoly script.''' | |
run('JEKYLL_ENV=production bundle exec jekyll build') | |
print("=> JEKYLL DONE") | |
run('npm run webpack') | |
print("=> WEBPACK DONE") | |
run('rsync -rav {target}/* {dest}'.format(target=TARGET_DIR, dest=SSH)) | |
print("=> RSYNC DONE") | |
print('ALL DONE') | |
def new_post(filename, title=""): | |
''' Create new post. ''' | |
now = datetime.datetime.now() | |
source = '''--- | |
layout: post | |
title: "{}" | |
date: {} | |
category: | |
typora-root-url: ../ | |
typora-copy-images-to: ../media | |
---'''.format(title, now.strftime('%Y-%m-%d %H:%M:%S '+TIMEZONE)) | |
filename = now.strftime('%Y-%m-%d-') + filename + '.md' | |
path = os.path.join(POSTS_DIR, filename) | |
if not os.path.exists(path): | |
with open(path, mode='w', encoding='utf-8') as new: | |
new.write(source) | |
else: | |
print('File {} already exists!'.format(filename)) | |
os.popen(OPEN_EDITOR_COMMAND + " " + path) | |
if __name__ == '__main__': | |
arg = sys.argv[1:] | |
if arg[0] == 'post': | |
if len(arg) == 2: | |
new_post(arg[1]) | |
elif len(arg) == 3: | |
new_post(arg[1], title=arg[2]) | |
elif arg[0] == 'depoly': | |
depoly() | |
else: | |
run('bundle exec jekyll ' + ' '.join(arg)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment