Last active
May 10, 2019 18:05
-
-
Save donly/3507bb9309a7c129b29ac921a0ae32db to your computer and use it in GitHub Desktop.
add the missing date directive below slug when using Pelican
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf8 -*- | |
if __name__ == "__main__": | |
import glob, os, datetime, fileinput | |
cwd = os.getcwd() | |
files = [f for f in glob.glob(cwd + os.path.sep + "**/*.rst", recursive=True)] | |
for f in files: | |
modifieddate = datetime.datetime.fromtimestamp(os.path.getmtime(f)) | |
if not ':date:' in open(f).read(): | |
print("%s %s" % (f, modifieddate)) | |
for line in fileinput.FileInput(f, inplace=1): | |
if ":slug:" in line: | |
line=line.replace(line,line+":date: "+modifieddate.__str__()+"\n") | |
print(line, end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment