Skip to content

Instantly share code, notes, and snippets.

@tioover
Last active May 14, 2017 16:24
Show Gist options
  • Select an option

  • Save tioover/6d11f181ff58af2a95ebd5d3097a91c1 to your computer and use it in GitHub Desktop.

Select an option

Save tioover/6d11f181ff58af2a95ebd5d3097a91c1 to your computer and use it in GitHub Desktop.

Revisions

  1. tioover revised this gist May 14, 2017. 1 changed file with 18 additions and 5 deletions.
    23 changes: 18 additions & 5 deletions jekyll-manage.py
    Original file line number Diff line number Diff line change
    @@ -6,13 +6,27 @@
    import sys
    import datetime

    OPEN_EDITOR_COMMAND = "open"

    # 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.'''
    pass
    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. '''
    @@ -26,7 +40,7 @@ def new_post(filename, title=""):
    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', filename)
    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)
    @@ -43,7 +57,6 @@ def new_post(filename, title=""):
    elif len(arg) == 3:
    new_post(arg[1], title=arg[2])
    elif arg[0] == 'depoly':
    os.system('JEKYLL_ENV=production bundle exec jekyll build')
    depoly()
    else:
    os.system('bundle exec jekyll ' + ' '.join(arg))
    run('bundle exec jekyll ' + ' '.join(arg))
  2. tioover created this gist May 13, 2017.
    49 changes: 49 additions & 0 deletions jekyll-manage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    #!/usr/bin/env python3
    '''
    Simple Jekyll site manage script.
    '''
    import os
    import sys
    import datetime

    OPEN_EDITOR_COMMAND = "open"
    TIMEZONE = '+0800' # Maybe shoud use pytz?


    def depoly():
    ''' Your depoly script.'''
    pass

    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', 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':
    os.system('JEKYLL_ENV=production bundle exec jekyll build')
    depoly()
    else:
    os.system('bundle exec jekyll ' + ' '.join(arg))