From fb7b0d727d8b2b09d462b5b3e57ce00b04fed426 Mon Sep 17 00:00:00 2001 From: Amber Date: Tue, 8 Mar 2022 21:39:44 -0600 Subject: [PATCH] Added basic css and theme support --- TODO | 4 ++-- css/home.css | 43 +++++++++++++++++++++++++++++++++++++++++++ css/navbar.css | 28 ++++++++++++++++++++++++++++ header.py | 16 +++++++++++----- main.py | 14 ++++---------- readFile.py | 13 +++++-------- theme.py | 40 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 css/home.css create mode 100644 css/navbar.css create mode 100644 theme.py diff --git a/TODO b/TODO index 3ca97f2..89b059b 100644 --- a/TODO +++ b/TODO @@ -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 \ No newline at end of file +#Try to replace beautifulsoup \ No newline at end of file diff --git a/css/home.css b/css/home.css new file mode 100644 index 0000000..cb20569 --- /dev/null +++ b/css/home.css @@ -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; +}*/ diff --git a/css/navbar.css b/css/navbar.css new file mode 100644 index 0000000..29b89f8 --- /dev/null +++ b/css/navbar.css @@ -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; +} diff --git a/header.py b/header.py index a198e8e..e7654c4 100755 --- a/header.py +++ b/header.py @@ -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 = "\n\n\n\t\n\t" headerStr1 = "\n\t\n\t\n\t\n\n\n\t" + headerStr3 = "\n\n\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) diff --git a/main.py b/main.py index b23f130..939f412 100755 --- a/main.py +++ b/main.py @@ -5,15 +5,11 @@ import datetime import header #outFile = outFile + ".html" -timeCreate = "" -timeMod = "" m2h = "" # markdown 2 html -headerStr = "" footStr = "\n\n" 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() diff --git a/readFile.py b/readFile.py index 9b3ee8a..b2bd379 100755 --- a/readFile.py +++ b/readFile.py @@ -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 \ No newline at end of file +# Edit: just keep the original markdown files dumbass diff --git a/theme.py b/theme.py new file mode 100644 index 0000000..86678b6 --- /dev/null +++ b/theme.py @@ -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" + return(outStr) + + def __str__(self): + return(self.getTheme()) + + +#def test(sTheme): +# outStr = "" +# +# for i in sTheme.values(): +# print(str(i)) + + +#test(basic) \ No newline at end of file