This is a quick little script that converts pelican metadata syntax into pandoc metadata syntax. This is simply as you just need to fence it in with 3-dashes. This adds this to all files in current dir with .md extension.
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
"""This is a quick little script that converts pelican metadata syntax into | |
pandoc metadata syntax. This is simply as you just need to fence it in with 3-dashes. | |
This adds this to all files in current dir with .md extension | |
""" | |
from os import walk | |
def list_files(directory, extension): | |
for (dirpath, dirnames, filenames) in walk(directory): | |
return (f for f in filenames if f.endswith('.' + extension)) | |
def add_yaml(files): | |
for f in files: | |
# pull file contents into a temp var | |
f_read = open(directory + f, 'r') | |
buff = f_read.read() | |
f_read.close() | |
# add a string to the beginning | |
new = '---\n' + buff | |
# find the first double break, which indicates end of title block | |
new = new.replace('\n\n', '\n---\n\n',1) | |
f_write = open(directory + f, 'w') | |
f_write.write(new) | |
f_write.close() | |
print("Updating file: %s" % f) | |
return | |
if __name__ == "__main__": | |
directory = '/content/' | |
files = list_files(directory, "md") | |
add_yaml(files) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment