old-homepage/htmlgen/htmlgen.py

26 lines
861 B
Python
Raw Normal View History

2016-04-12 17:41:50 +00:00
import cgitb
import markdown2
cgitb.enable()
class HTMLgen:
def __init__(self, layout, title):
self.layout=layout
self.articles=[]
self.titles=[]
self.title=title
def addArticle(self, name, markdown):
2016-06-12 12:27:29 +00:00
self.articles.append(markdown2.markdown(markdown, extras=["tables","spoiler"]))
2016-04-12 17:41:50 +00:00
self.titles.append(name)
def renderSite(self):
nav=""
x=0
for title in self.titles:
2016-04-12 18:14:54 +00:00
nav=nav+("<a href=\"#%i\">%s</a><br/>" % (x, title))
2016-04-12 17:41:50 +00:00
x=x+1
main=""
x=0
for article in self.articles:
main=main+("<h2 id=\"%i\">%s</h2><article>%s</article>" %(x,self.titles[x],article))
x=x+1
2016-04-12 17:56:41 +00:00
styleargs = {"title":self.title,"nav":nav,"main":main,"aside":str(x),"footer":"Copyright 2016 Morten"}
2016-04-12 17:41:50 +00:00
return self.layout%styleargs