First version of the homepage
This commit is contained in:
commit
489e8d0337
5 changed files with 89 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
__pycache__/
|
||||
*.pyc
|
1
htmlgen/__init__.py
Normal file
1
htmlgen/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
__all__ = ["htmlgen","pagelayout"]
|
25
htmlgen/htmlgen.py
Normal file
25
htmlgen/htmlgen.py
Normal file
|
@ -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+("<a href=\"#%i\">%s</a>" % (x, title))
|
||||
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
|
||||
styleargs = {"title":self.title,"nav":nav,"main":main,"aside":"","footer":"Copyright 2016 Morten"}
|
||||
return self.layout%styleargs
|
57
htmlgen/pagelayout.py
Normal file
57
htmlgen/pagelayout.py
Normal file
|
@ -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)
|
4
index.py
Normal file
4
index.py
Normal file
|
@ -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())
|
Loading…
Reference in a new issue