from datetime import date import markdown import os SOURCE_MD = 'source/index.md' HTML_TEXT_TEMPLATE = """ {head} {body} """ HeadText = """ Addison Hu """ BODY_TEXT_TEMPLATE = """
{header} {section} {footer}
""" HEADER_TEXT_TEMPLATE = """

Addison Hu

{position}
{organization}

contact:
cv: download pdf
github: repositories
more? blog

""" FOOTER_TEXT_TEMPLATE = """ """ HeaderText = HEADER_TEXT_TEMPLATE.format( position = 'PhD Student
 ' 'Advisor: Ryan Tibshirani
' 'Statistics & Machine Learning', organization = 'Carnegie Mellon University', cv = 'pdfs/AddisonHu_CV.pdf', headshot_url = '', headshot_text = 'with my bicycle', headshot = 'img/autumn-bicycle.jpg', mail_href = r'mailto:ma%69l%40hui' + r'saddiso%6E.com', mail = r'mail@huisaddison&' + r'#46;com', ) FooterText = FOOTER_TEXT_TEMPLATE.format( generate_script = 'generate_html.py', source = SOURCE_MD, today = date.today().strftime('%Y %B %d'), ) SECTION_TEXT_TEMPLATE = """
{section}
""" section_html = '' with open(SOURCE_MD, 'r', encoding='utf-8') as f: text = f.read() section_html += markdown.markdown(text) SectionText = SECTION_TEXT_TEMPLATE.format( section = section_html, ) BodyText = BODY_TEXT_TEMPLATE.format( header = HeaderText, section = SectionText, footer = FooterText, ) HtmlText = HTML_TEXT_TEMPLATE.format( head = HeadText, body = BodyText, ) if os.path.isfile('index.html'): os.rename('index.html', 'index.html.old') with open('index.html', 'w') as f: f.write(HtmlText)