Added basic css and theme support

This commit is contained in:
Amber 2022-03-08 21:39:44 -06:00
parent a46ca2bdb6
commit fb7b0d727d
7 changed files with 133 additions and 25 deletions

4
TODO
View File

@ -2,7 +2,7 @@ Multiple template files
Nice HTML tabs
Don't hard-code timezone
Build system
Take input file as a command-line arguement
Take input file as a command-line arguement, search multiple places for theme
title, template, markdown
Figure out licencing
Try to replace beautifulsoup
#Try to replace beautifulsoup

43
css/home.css Normal file
View File

@ -0,0 +1,43 @@
/* CSS stolen from https://www.alm.website with permission */
body {
font-family: sans-serif;
}
code {
font-family: monospace;
background-color: #eee;
border-radius: 3px;
}
pre {
font-family: monospace;
background-color: #eee;
border-radius: 3px;
}
.align-left {
float: left;
}
.align-right {
float: right;
}
.align-center {
margin: auto;
width: 50%;
}
table, th, td {
border: solid 1px black;
border-collapse: collapse;
}
th, td {
margin: 2px;
}
/*nav {
speak: always;
}*/

28
css/navbar.css Normal file
View File

@ -0,0 +1,28 @@
/* Stolen from www.alm.website with permission */
nav {
display: flow;
border: solid 2px black;
margin: auto;
width: fit-content;
text-align: center;
justify-content: center;
white-space: nowrap;
}
nav li {
list-style: none;
border: solid 1px black;
margin: 2px;
}
nav h1 {
margin-top: 0;
margin-bottom: 0;
margin-right: 10px;
}
nav strong {
font-family: serif;
font-size: x-large;
}

View File

@ -1,20 +1,23 @@
#!/usr/bin/python
import datetime
import theme
class readHead():
outHead = ""
#outHead = ""
sTime = []
sTitle = ""
sTheme = "basicTheme"
def __init__(self, sTitle):
def __init__(self, sTitle, sTheme = "basicTheme"):
self.sTitle = sTitle
# self.outHead = ""
self.stime = []
self.sTheme = sTheme
def __str__(self):
return(str(self.genHead())) #TODO: pick css theme and append to output
return(str(self.genHead())) #TODO: Append CSS, navbar, sidebar, footer
# Start genHead()
def genHead(self):
@ -27,7 +30,10 @@ class readHead():
headerStr = "<!DOCTYPE HTML>\n<html>\n<head>\n\t<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n\t<title>"
headerStr1 = "</title>\n\t<meta name=\"generator\" content=\"HTML.xonsh https://git.nixnet.services/amber/html.xonsh\"/>\n\t<meta name=\"created\" content=\""
headerStr2 = "\">\n\t<meta name=\"changed\" content=\""
headerStr3 = "\"/>\n</head>\n<body>\n\t"
headerStr3 = "\n</head>\n<body>\n\t"
outHead = headerStr + str(self.sTitle) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3
outHead = headerStr + str(self.sTitle) + headerStr1 + timeMod + headerStr2 + timeCreate
#append css
outHead = outHead + "\">" + str(theme.css())
outHead = outHead + headerStr3
return(outHead)

14
main.py
View File

@ -5,15 +5,11 @@ import datetime
import header
#outFile = outFile + ".html"
timeCreate = ""
timeMod = ""
m2h = "" # markdown 2 html
headerStr = ""
footStr = "\n</body>\n</html>"
def printHtml(head, body, foot, outFile):
print("placeholder")
file = open(outFile, 'w')
file.write(str(head + body + foot))
@ -24,16 +20,14 @@ def parseMd(inFile):
m2h = str(readFile.readMarkdown(inFile))
return(m2h)
def css():
print("placeholder")
def main():
# metadata("sample.md")
parseMd("sample.md")
printHtml(headerStr, m2h, footStr, "outdir/index.html")
humanReadableArg = str(header.readHead("Big Grand Tigle"))
printHtml(humanReadableArg, m2h, footStr, "outdir/index.html")
def test():
print(str(header.readHead("string")) + str(parseMd("sample.md")) + footStr)
#main()
test()
main()
#test()

View File

@ -12,18 +12,15 @@ class readMarkdown():
self.mdFile = mdFile
def markdown(self, mdFile):
print("placeholder")
def markdown(self):
file = open(self.mdFile, 'r')
#middleVar = file.read()
self.outStr = str(markdown.markdown(file.read())) #TODO: I really want nice tab indentations
outStr = str(markdown.markdown(file.read())) #TODO: I really want nice tab indentations
file.close()
return(self.outStr)
return(outStr)
def __str__(self):
return(str(self.markdown(self.mdFile)))
return(str(self.markdown()))
# might want to find a way to diff html from a file and readMarkdown()'s output if I want to update pages
# Edit: just keep the original markdown files dumbass
# Edit: just keep the original markdown files dumbass

40
theme.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/python
# Add argparse support, create themes
# Default theme will use the stuff I currently have on the home page
# TODO: don't hard-code theme, look into extensability
basic = {
"navCss": "css/navbar.css",
"bodyCss": "css/home.css",
"headerCss": "",
"footCss": ""
}
class css():
# sTheme = ""
def __init__(self, sTheme = basic):
self.sTheme = sTheme
def getTheme(self):
outStr = ""
for i in self.sTheme:
outStr = outStr + "\n\t<link rel=\"stylesheet\" href=\""
outStr = outStr + str(self.sTheme[i])
outStr = outStr + "\" media=\"\">"
return(outStr)
def __str__(self):
return(self.getTheme())
#def test(sTheme):
# outStr = ""
#
# for i in sTheme.values():
# print(str(i))
#test(basic)