From d5075a0d2c21ac9bd9b8863d7f9c9782f06b4443 Mon Sep 17 00:00:00 2001 From: Phyks Date: Sun, 27 Oct 2013 20:15:46 +0100 Subject: [PATCH] Added support for external includes for header and footer in static pages. --- pre-commit.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pre-commit.py b/pre-commit.py index 23168e3..24a76ae 100755 --- a/pre-commit.py +++ b/pre-commit.py @@ -821,3 +821,27 @@ try: archives_fh.write(archives) except IOError: sys.exit("[ERROR] Unable to write blog/archives.html file.") + +# Include header and footer for pages that need it +for i in os.listdir("blog/"): + if (os.path.isdir("blog/"+i) or i in ["header.html", "footer.html", + "rss.xml", "style.css", "index.html", + "archives.html", "humans.txt"]): + continue + + with open("blog/"+i, 'r+') as fh: + content = fh.read() + fh.seek(0) + + if content.find("#header") != -1: + content = content.replace("#header", + header.replace("@title", + (params["BLOG_TITLE"] + + " - "+i[:-5].title()), + 1), + 1) + fh.write(content) + fh.seek(0) + + if content.find("#footer") != -1: + fh.write(content.replace("#footer", footer, 1))