From 489e8d03371372197e3d9028d5aa76c0a3f41ccb Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Tue, 12 Apr 2016 19:41:50 +0200 Subject: [PATCH] First version of the homepage --- .gitignore | 2 ++ htmlgen/__init__.py | 1 + htmlgen/htmlgen.py | 25 +++++++++++++++++++ htmlgen/pagelayout.py | 57 +++++++++++++++++++++++++++++++++++++++++++ index.py | 4 +++ 5 files changed, 89 insertions(+) create mode 100644 .gitignore create mode 100644 htmlgen/__init__.py create mode 100644 htmlgen/htmlgen.py create mode 100644 htmlgen/pagelayout.py create mode 100644 index.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7a60b85 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +*.pyc diff --git a/htmlgen/__init__.py b/htmlgen/__init__.py new file mode 100644 index 0000000..2abcef9 --- /dev/null +++ b/htmlgen/__init__.py @@ -0,0 +1 @@ +__all__ = ["htmlgen","pagelayout"] diff --git a/htmlgen/htmlgen.py b/htmlgen/htmlgen.py new file mode 100644 index 0000000..82f334b --- /dev/null +++ b/htmlgen/htmlgen.py @@ -0,0 +1,25 @@ +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): + self.articles.append(markdown2.markdown(markdown)) + self.titles.append(name) + def renderSite(self): + nav="" + x=0 + for title in self.titles: + nav=nav+("%s" % (x, title)) + x=x+1 + main="" + x=0 + for article in self.articles: + main=main+("

%s

%s
" %(x,self.titles[x],article)) + x=x+1 + styleargs = {"title":self.title,"nav":nav,"main":main,"aside":"","footer":"Copyright 2016 Morten"} + return self.layout%styleargs diff --git a/htmlgen/pagelayout.py b/htmlgen/pagelayout.py new file mode 100644 index 0000000..d5f9d85 --- /dev/null +++ b/htmlgen/pagelayout.py @@ -0,0 +1,57 @@ +from xml.etree.ElementTree import Element, SubElement +from xml.etree import ElementTree + +def getLayoutXML(): + root = Element("html") + root.set("lang","en") + head = SubElement(root, "head") + body = SubElement(root, "body") + title = SubElement(head, "title") + title.text = "%(title)s" + charset = SubElement(head, "meta") + charset.set("charset","utf-8") + link1 = SubElement(head, "link") + link1.set("rel", "stylesheet") + link1.set("type", "text/css") + link1.set("media", "screen and (max-width: 1023px)") + link1.set("href", "mobilestyle.css") + link2 = SubElement(head, "link") + link2.set("rel", "stylesheet") + link2.set("type", "text/css") + link2.set("media", "screen and (min-width: 1024px)") + link2.set("href", "mainstyle.css") + meta = SubElement(head, "meta") + meta.set("name", "viewport") + meta.set("content", "width=device-width, initial-scale=1.0") + topLink = SubElement(body, "a") + topLink.set("id", "top") + title2 = SubElement(body, "h1") + title2.text = "%(title)s" + table = SubElement(body, "div") + table.set("class", "table") + tablerow = SubElement(table, "div") + tablerow.set("class", "tablerow") + navspoiler = SubElement(tablerow, "div") + navspoiler.set("class", "spoiler") + navspoiler.set("tabindex", "1") + navspoiler.text = "Navigation" + nav = SubElement(tablerow, "nav") + nav.set("class","spoilerContent") + nav.text="%(nav)s" + main = SubElement(tablerow, "main") + main.text="%(main)s" + asidespoiler = SubElement(tablerow, "div") + asidespoiler.set("class", "spoiler") + asidespoiler.set("tabindex", "2") + aside = SubElement(tablerow, "aside") + aside.set("class", "spoilerContent") + aside.text="%(aside)s" + footer = SubElement(body, "footer") + footer.text="%(footer)s" + upbar = SubElement(body, "a") + upbar.set("class", "upbar") + upbar.set("href", "#top") + upbar.set("style", "float:right") + upbar.text=u"↑" + + return ElementTree.tostring(root) diff --git a/index.py b/index.py new file mode 100644 index 0000000..2368e57 --- /dev/null +++ b/index.py @@ -0,0 +1,4 @@ +from htmlgen import * +html=htmlgen.HTMLgen(pagelayout.getLayoutXML().decode('utf-8'),"Home Page") +html.addArticle("Markdown test","*Hello, World!*") +print(html.renderSite())