diff --git a/build.py b/build.py
index 40fe1f3..f16a56b 100644
--- a/build.py
+++ b/build.py
@@ -10,7 +10,10 @@
import argparse
import glob
+import html
+from io import StringIO
import markdown
+import operator
import os
import re
import shutil
@@ -24,6 +27,8 @@ deploy_directory = '~/src/www-home'
md_extensions = [
'fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify']
+blog_entries = []
+
def print_file(in_file, out_file):
print('%-62s -> %s' % (in_file, out_file))
@@ -42,6 +47,13 @@ def copy_static_files():
shutil.copy2(source, dest)
+def find_update_date(text):
+ match = re.search(r'^Published:? (\d{4}-\d{2}-\d{2})', text, re.MULTILINE)
+ if not match:
+ return None
+ return match.group(1)
+
+
def process_markdown_files():
template = open('template.html').read()
for (dirpath, _, filenames) in os.walk(input_directory):
@@ -50,6 +62,8 @@ def process_markdown_files():
if not markdown_filename.endswith('.md'):
continue
+ blog_entry = {}
+
markdown_file = open(markdown_filename)
text = markdown_file.read()
markdown_file.close()
@@ -62,6 +76,9 @@ def process_markdown_files():
title = match.group(1).lstrip('# ')
else:
title = text
+
+ blog_entry['title'] = html.escape(title)
+
title += ' | Colin McMillen'
if markdown_filename == os.path.join(input_directory, 'index.md'):
title = 'Colin McMillen'
@@ -75,9 +92,16 @@ def process_markdown_files():
if page_url.endswith('index.html'): # strip off index.html
page_url = page_url[:-len('index.html')]
- html = markdown.markdown(
+ update_date = find_update_date(text)
+ if update_date:
+ blog_entry['url'] = 'https://www.mcmillen.dev/' + page_url
+ blog_entry['date'] = update_date
+ blog_entries.append(blog_entry)
+
+ html_content = markdown.markdown(
text, extensions=md_extensions, output_format='html5')
- output = template.format(title=title, content=html, page_url=page_url)
+ output = template.format(
+ title=title, content=html_content, page_url=page_url)
os.makedirs(out_dirpath, exist_ok=True)
print_file(markdown_filename, out_fullpath)
@@ -93,15 +117,71 @@ grep -v ^output/google |
grep -v ^output/drafts |
perl -pe 's|output|https://www.mcmillen.dev|'
> output/sitemap.txt""".split('\n'))
+ print_file('', 'output/sitemap.txt')
os.system(sitemap_command)
-def make_rss(): # TODO: implement.
- pass
+def make_atom_feed():
+ atom_template = '''
+