Created
December 9, 2018 01:29
-
-
Save leonson/6a5a022bd80a120d065a86cae5c45cfc to your computer and use it in GitHub Desktop.
Used this script to unpublish all jekyll posts before a particular year
This file contains 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
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