Skip to content

Instantly share code, notes, and snippets.

@arjkb
Created July 11, 2018 14:02
Show Gist options
  • Save arjkb/0b922ca0f7cd39a017cab4735fd3e0b4 to your computer and use it in GitHub Desktop.
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.
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