-
-
Save flowb/57975f847f24cac2d040c35a67566deb to your computer and use it in GitHub Desktop.
Orbweaver alpha
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import markdown | |
import glob | |
import re | |
import datetime as dt | |
import os.path as ospath | |
#boilerplate | |
head = '<head><link rel="stylesheet" href="styles.css"></head>\n' | |
header = '<header><a href="http://..."><img src="img/fancy_a_sm.png" class="logo"></a><hr></header>\n' | |
def mkHtml(fileName): | |
with open(fileName, "r", encoding="utf-8") \ | |
as input_file: | |
text = input_file.read() | |
html = markdown.markdown(text) | |
return html | |
def addLinks(html, docTitles): | |
for t in docTitles: | |
html = re.sub(t,'<a class="herelink" href="'+t+'.html">'+t+'</a>',html,flags=re.I) | |
return html | |
def main(): | |
mdList_ = glob.glob(r"*.md") | |
docList_ = [] | |
for m in mdList_: | |
docList_.append(m.split('.md')[0]) | |
for m in mdList_: | |
title = m.split('.md')[0] | |
doctitle = '<div class="doctitle">'+title+'</div><hr>' | |
source_ts = dt.datetime.fromtimestamp(ospath.getmtime(m)).replace(microsecond=0).isoformat() | |
obw_ts = dt.datetime.now().replace(microsecond=0).isoformat() | |
footer = '<footer><hr>'+ source_ts + ' | src<br>' + obw_ts + ' | orbweaver</footer>' | |
html = mkHtml(m) | |
html += footer | |
html = addLinks(html,docList_) | |
with open(title+".html", "w", encoding = "utf-8", errors = "xmlcharrefreplace") \ | |
as output_file: | |
output_file.write(head+header+doctitle+html) | |
# build index.html | |
docList_.sort() | |
html = '' | |
for m in docList_: | |
print(m) | |
html += m+'<br>' | |
obw_ts = dt.datetime.now().replace(microsecond=0).isoformat() | |
html+= '<footer><hr>'+ obw_ts + ' | orbweaver</footer>' | |
html = addLinks(html, docList_) | |
with open("index.html", "w", encoding = "utf-8", errors = "xmlcharrefreplace") \ | |
as output_file: | |
output_file.write(head+header+html) | |
return | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment