python-webgen/stitcher.py

36 lines
1.4 KiB
Python
Raw Permalink Normal View History

2025-03-11 21:03:39 -07:00
import parser
# function defs
def generateBody(infilePath):
title = parser.getTitle(infilePath)
body = parser.convertFile(infilePath)
timestamp = parser.getMetadata(infilePath)["date"]
date = parser.convertDate(timestamp)
final = "<h1> {} </h1>\n<h3 class=\"date\">{}</h3>\n<hr/>\n{}".format(title, date, body)
return final
def createArticle(infilePath, templatePath, mainTitle = ""):
if mainTitle != "":
mainTitle = " | " + mainTitle
template = open("{}article.html".format(templatePath), 'r').read()
navbar = open("{}navbar.html".format(templatePath), 'r').read()
foot = open("{}footer.html".format(templatePath), 'r').read()
body = generateBody(infilePath)
articleTitle = parser.getTitle(infilePath) + mainTitle
article = template.format(title = articleTitle, main = body, nav = navbar, footer = foot)
return article
def createMainPage(titles, templatePath, main_title):
template = open("{}main.html".format(templatePath), 'r').read()
navbar = open("{}navbar.html".format(templatePath), 'r').read()
foot = open("{}footer.html".format(templatePath), 'r').read()
articles = ""
fstring = '<article><h2><a href = "{}">{}</a></h2></article>\n'
for title in titles:
articles = articles + fstring.format(title[1], title[0])
final = template.format(title = main_title, toc = articles, nav = navbar, footer = foot)
return final