html.xonsh/main.py

81 lines
1.9 KiB
Python
Raw Normal View History

#!/usr/bin/python
2022-03-03 02:00:20 +00:00
import readFile
import datetime
import header
2022-03-03 00:41:53 +00:00
2022-03-03 02:00:20 +00:00
#outFile = outFile + ".html"
timeCreate = ""
timeMod = ""
2022-03-03 03:59:46 +00:00
m2h = "" # markdown 2 html
2022-03-04 02:40:32 +00:00
headerStr = ""
footStr = "\n</body>\n</html>"
2022-03-03 00:41:53 +00:00
2022-03-04 02:40:32 +00:00
def printHtml(head, body, foot, outFile):
2022-03-03 00:41:53 +00:00
print("placeholder")
2022-03-03 02:00:20 +00:00
file = open(outFile, 'w')
2022-03-04 02:40:32 +00:00
file.write(str(head + body + foot))
2022-03-03 02:00:20 +00:00
2022-03-03 03:59:46 +00:00
file.close()
2022-03-03 00:41:53 +00:00
2022-03-03 03:59:46 +00:00
def parseMd(inFile):
2022-03-04 02:40:32 +00:00
global m2h
m2h = str(readFile.readMarkdown(inFile))
2022-03-03 03:59:46 +00:00
return(m2h)
2022-03-03 00:41:53 +00:00
def metadata(inFile):
# Read metadata from possible file
## Pretend there's code here
# Generate metadata
getTime = datetime.datetime.now()
timeMod = str(getTime.strftime("%A, %B %d, %Y at %X UTC06:00")) #TODO: I don't want to hard-code this but the %z utc offset isn't printing
timeCreate = timeMod
title = inFile.split(".")
title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename
2022-03-04 02:40:32 +00:00
# Take title as optional command-line arguement
# Generate html
global headerStr
headerStr = """\
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>"""
headerStr1 = """</title>
<meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/>
<meta name="created" content=" """
headerStr2 = """"/>
<meta name="changed" content=" """
headerStr3 = """"/>
</head>
<body>
2022-03-04 02:40:32 +00:00
"""
headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3
return(str(headerStr))
2022-03-03 00:41:53 +00:00
def css():
print("placeholder")
def main():
2022-03-04 02:40:32 +00:00
metadata("sample.md")
parseMd("sample.md")
printHtml(headerStr, m2h, footStr, "outdir/index.html")
2022-03-03 02:40:58 +00:00
def test():
2022-03-03 03:59:46 +00:00
#print(readFile.readMarkdown("/home/amber/website.sh/sample.md"))
#print(parseMd("sample.md"))
2022-03-03 02:40:58 +00:00
#metadata("sample.md")
header.readHead("htmlTemplate/header.header.html", "string")
#main()
test()