Skip to content

Instantly share code, notes, and snippets.

@donly
Last active May 10, 2019 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save donly/3507bb9309a7c129b29ac921a0ae32db to your computer and use it in GitHub Desktop.
Save donly/3507bb9309a7c129b29ac921a0ae32db to your computer and use it in GitHub Desktop.
add the missing date directive below slug when using Pelican
#!/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