sorta works, flips html stuff around

This commit is contained in:
Amber 2022-03-05 01:04:26 -06:00
parent b5e1841885
commit 6dce6b723d
3 changed files with 71 additions and 46 deletions

View File

@ -1,29 +1,51 @@
#!/usr/bin/python #!/usr/bin/python
import bs4 from bs4 import BeautifulSoup as bs
import datetime import datetime
import re
class readHead(): class readHead():
inFile = "" inFile = ""
outHead = "" outHead = ""
time = [] sTime = []
sTitle = "" sTitle = ""
footStr = "\n</body>\n</html>" footStr = "\n</body>\n</html>"
def __init__(self, headerFile, title): def __init__(self, headerFile, sTitle):
self.inFile = headerFile self.inFile = headerFile
self.sTitle = title self.sTitle = sTitle
self.outHead = "" self.outHead = ""
self.time = [] self.stime = []
self.footStr = "\n</body>\n</html>" self.footStr = "\n</body>\n</html>"
def getTime(self): def getTime(self):
gettime = datetime.datetime.now() gettime = datetime.datetime.now()
modDate = 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 modDate = 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
createDate = self.modDate #TODO: make this seperate createDate = modDate #TODO: make this seperate
global time global sTime
time.append(str(modDate)) self.sTime.append(str(modDate))
time.append(str.createDate) self.sTime.append(str(createDate))
return(self.sTime)
def read(self):
file = open(self.inFile, "r")
headStr = file.read()
file.close()
return(headStr)
def __str__(self):
return(str(self.sed()))
def sed(self):
stdin = (str(self.read()))
#soupSed = soup(stdin, "lxml")
self.getTime()
stdin = str(re.sub("CREATEDATE", str(self.sTime[0]), stdin))
stdin = str(re.sub("MODDATE", str(self.sTime[1]), stdin))
soup = bs(stdin, "lxml")
soup.head.title = str(self.sTitle)
return(soup)

View File

@ -7,3 +7,6 @@
<meta name="created" content="CREATEDATE"/> <meta name="created" content="CREATEDATE"/>
<meta name="changed" content="MODDATE"/> <meta name="changed" content="MODDATE"/>
</head> </head>
<body>
</body>
</html>

72
main.py
View File

@ -24,47 +24,47 @@ def parseMd(inFile):
m2h = str(readFile.readMarkdown(inFile)) m2h = str(readFile.readMarkdown(inFile))
return(m2h) return(m2h)
def metadata(inFile): #def metadata(inFile):
# Read metadata from possible file # # Read metadata from possible file
## Pretend there's code here # ## Pretend there's code here
#
# Generate metadata # # Generate metadata
getTime = datetime.datetime.now() # 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 # 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 # timeCreate = timeMod
#
title = inFile.split(".") # title = inFile.split(".")
title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename # title = str(title[0]) #TODO: figure out a way to make longer titles without putting spaces in the filename
# Take title as optional command-line arguement # # Take title as optional command-line arguement
#
# Generate html # # Generate html
global headerStr # global headerStr
headerStr = """\ # headerStr = """\
<!DOCTYPE HTML> #<!DOCTYPE HTML>
<html> #<html>
<head> #<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/> # <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>""" # <title>"""
headerStr1 = """</title> # headerStr1 = """</title>
<meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/> # <meta name="generator" content="HTML.xonsh https://git.nixnet.services/amber/html.xonsh"/>
<meta name="created" content=" """ # <meta name="created" content=" """
headerStr2 = """"/> # headerStr2 = """"/>
<meta name="changed" content=" """ # <meta name="changed" content=" """
headerStr3 = """"/> # headerStr3 = """"/>
</head> #</head>
<body> #<body>
""" #"""
#
headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3 # headerStr = headerStr + str(title) + headerStr1 + timeMod + headerStr2 + timeCreate + headerStr3
#
return(str(headerStr)) # return(str(headerStr))
def css(): def css():
print("placeholder") print("placeholder")
def main(): def main():
metadata("sample.md") # metadata("sample.md")
parseMd("sample.md") parseMd("sample.md")
printHtml(headerStr, m2h, footStr, "outdir/index.html") printHtml(headerStr, m2h, footStr, "outdir/index.html")
@ -75,7 +75,7 @@ def test():
#print(parseMd("sample.md")) #print(parseMd("sample.md"))
#metadata("sample.md") #metadata("sample.md")
header.readHead("htmlTemplate/header.header.html", "string") print(str(header.readHead("htmlTemplate/header.html", "string")))
#main() #main()
test() test()