Write Once Post Twice

 

Since my Jekyll site becomes more and more complicated, the loading time becomes an issue. So I created a lite version of my blog reserving most of its content while reducing as much unnecessary element as possible. I miss how fast stock Jekyll compiles!!!

Python scripts

Exporter

This script exports posts from original blog folder to the target folder.

import os
import re
import fileinput


tar_dir = '../leo-blog/_posts/'
os.system('cp -r ./_posts/ '+tar_dir)
cur_dir = tar_dir
excluded = ['2018-10-19-happy-birthday.markdown']

try:
    for filename in os.listdir(cur_dir):
        print(filename)
        if(filename in excluded):
            os.system('rm '+tar_dir+filename)
            print('removed '+filename+'!')
            continue
        with fileinput.FileInput(cur_dir+'/'+filename, inplace=True, backup='.bak') as file:
            for line in file:
                print(line.replace('layout: post', 'layout: article'), end='')

    os.system('rm '+tar_dir+'*.bak')
except:
    print('error, try again from exporter.py')

Uploader

import os
import time
import exporter
import sys

cur = time.asctime(time.localtime(time.time()))

try:
    exporter
except:
    sys.exit()

os.system('git add .')
os.system('git commit -S -m "update at '+ cur +'"')
os.system('git push')
os.system('cd ../leo-blog \n git add . \n git commit -S -m "update at '+ cur +'" \n git push')

Time-teller

import time
print(time.strftime("%Y-%m-%d %H:%M:%S +0800", time.localtime(time.time())))