Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Used this script to unpublish all jekyll posts before a particular year
import os
PATTERN = "author: leonson"
YEAR = 2012
def unpublish(filepath, pattern):
file_handle = open(filepath, "r")
contents = file_handle.readlines()
index = 0
for i in range(len(contents)):
if pattern in contents[i]:
index = i
contents.insert(index+1,"published: false\n")
f_write = open(filepath, "w")
contents = "".join(contents)
def process_folder(path):
file_list = os.listdir(path)
for entry in file_list:
year = int(entry.split('-')[0])
if(year < YEAR):
file_path = "/".join([path, entry])
unpublish(file_path, PATTERN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.