Skip to content

Instantly share code, notes, and snippets.

@leonson
Created December 9, 2018 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonson/6a5a022bd80a120d065a86cae5c45cfc to your computer and use it in GitHub Desktop.
Save leonson/6a5a022bd80a120d065a86cae5c45cfc to your computer and use it in GitHub Desktop.
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()
file_handle.close()
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)
f_write.write(contents)
f_write.close()
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