Created
July 11, 2018 14:02
-
-
Save arjkb/0b922ca0f7cd39a017cab4735fd3e0b4 to your computer and use it in GitHub Desktop.
Script to take the date fron .md file and put it as a front matter inside the file. Helps when migrating from Jekyll to Hugo.
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 | |
import fileinput | |
def main(): | |
files = [f for f in os.listdir() if f.endswith('.md')] | |
for filename in files: | |
date = filename[:10] | |
print(date, filename) | |
with fileinput.FileInput(filename, inplace=1) as f: | |
for line in f: | |
if 'title:' in line: | |
print("{}\ndate: {}".format(line.strip(), date)) | |
else: | |
print(line.strip()) | |
print(" {} files.".format(len(files))) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment