Compare commits
No commits in common. "bfba1c36d0d3ad3397890f5cb7c6f592865c8e3d" and "c715887a9f7ff61735b17e1ad9a0fd52cb12ddfe" have entirely different histories.
bfba1c36d0
...
c715887a9f
100
build.py
100
build.py
@ -10,10 +10,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import html
|
|
||||||
from io import StringIO
|
|
||||||
import markdown
|
import markdown
|
||||||
import operator
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
@ -27,8 +24,6 @@ deploy_directory = '~/src/www-home'
|
|||||||
md_extensions = [
|
md_extensions = [
|
||||||
'fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify']
|
'fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables', 'linkify']
|
||||||
|
|
||||||
blog_entries = []
|
|
||||||
|
|
||||||
|
|
||||||
def print_file(in_file, out_file):
|
def print_file(in_file, out_file):
|
||||||
print('%-62s -> %s' % (in_file, out_file))
|
print('%-62s -> %s' % (in_file, out_file))
|
||||||
@ -47,13 +42,6 @@ def copy_static_files():
|
|||||||
shutil.copy2(source, dest)
|
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():
|
def process_markdown_files():
|
||||||
template = open('template.html').read()
|
template = open('template.html').read()
|
||||||
for (dirpath, _, filenames) in os.walk(input_directory):
|
for (dirpath, _, filenames) in os.walk(input_directory):
|
||||||
@ -62,8 +50,6 @@ def process_markdown_files():
|
|||||||
if not markdown_filename.endswith('.md'):
|
if not markdown_filename.endswith('.md'):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
blog_entry = {}
|
|
||||||
|
|
||||||
markdown_file = open(markdown_filename)
|
markdown_file = open(markdown_filename)
|
||||||
text = markdown_file.read()
|
text = markdown_file.read()
|
||||||
markdown_file.close()
|
markdown_file.close()
|
||||||
@ -76,9 +62,6 @@ def process_markdown_files():
|
|||||||
title = match.group(1).lstrip('# ')
|
title = match.group(1).lstrip('# ')
|
||||||
else:
|
else:
|
||||||
title = text
|
title = text
|
||||||
|
|
||||||
blog_entry['title'] = html.escape(title)
|
|
||||||
|
|
||||||
title += ' | Colin McMillen'
|
title += ' | Colin McMillen'
|
||||||
if markdown_filename == os.path.join(input_directory, 'index.md'):
|
if markdown_filename == os.path.join(input_directory, 'index.md'):
|
||||||
title = 'Colin McMillen'
|
title = 'Colin McMillen'
|
||||||
@ -92,16 +75,9 @@ def process_markdown_files():
|
|||||||
if page_url.endswith('index.html'): # strip off index.html
|
if page_url.endswith('index.html'): # strip off index.html
|
||||||
page_url = page_url[:-len('index.html')]
|
page_url = page_url[:-len('index.html')]
|
||||||
|
|
||||||
update_date = find_update_date(text)
|
html = markdown.markdown(
|
||||||
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')
|
text, extensions=md_extensions, output_format='html5')
|
||||||
output = template.format(
|
output = template.format(title=title, content=html, page_url=page_url)
|
||||||
title=title, content=html_content, page_url=page_url)
|
|
||||||
|
|
||||||
os.makedirs(out_dirpath, exist_ok=True)
|
os.makedirs(out_dirpath, exist_ok=True)
|
||||||
print_file(markdown_filename, out_fullpath)
|
print_file(markdown_filename, out_fullpath)
|
||||||
@ -117,71 +93,15 @@ grep -v ^output/google |
|
|||||||
grep -v ^output/drafts |
|
grep -v ^output/drafts |
|
||||||
perl -pe 's|output|https://www.mcmillen.dev|'
|
perl -pe 's|output|https://www.mcmillen.dev|'
|
||||||
> output/sitemap.txt""".split('\n'))
|
> output/sitemap.txt""".split('\n'))
|
||||||
print_file('', 'output/sitemap.txt')
|
|
||||||
os.system(sitemap_command)
|
os.system(sitemap_command)
|
||||||
|
|
||||||
|
|
||||||
def make_atom_feed():
|
def make_rss(): # TODO: implement.
|
||||||
atom_template = '''<?xml version="1.0" encoding="utf-8"?>
|
pass
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
||||||
|
|
||||||
<title>Colin McMillen's Blog</title>
|
|
||||||
<link href="https://www.mcmillen.dev"/>
|
|
||||||
<link rel="self" href="https://www.mcmillen.dev/atom.xml"/>
|
|
||||||
<updated>{last_update}</updated>
|
|
||||||
<author>
|
|
||||||
<name>Colin McMillen</name>
|
|
||||||
</author>
|
|
||||||
<id>https://www.mcmillen.dev/</id>
|
|
||||||
|
|
||||||
{entries}
|
|
||||||
</feed>
|
|
||||||
'''
|
|
||||||
|
|
||||||
entry_template = '''
|
|
||||||
<entry>
|
|
||||||
<title>{title}</title>
|
|
||||||
<id>{url}</id>
|
|
||||||
<link rel="alternate" href="{url}"/>
|
|
||||||
<updated>{updated}</updated>
|
|
||||||
<summary>{summary}</summary>
|
|
||||||
</entry>
|
|
||||||
'''
|
|
||||||
|
|
||||||
blog_entries.sort(key=operator.itemgetter('date'))
|
|
||||||
|
|
||||||
entries_io = StringIO()
|
|
||||||
last_update = None
|
|
||||||
for entry in blog_entries:
|
|
||||||
# We lie and pretend that all entries were written at noon UTC.
|
|
||||||
update_date = entry['date'] + 'T12:00:00+00:00'
|
|
||||||
last_update = update_date
|
|
||||||
entries_io.write(entry_template.format(
|
|
||||||
url=entry['url'],
|
|
||||||
title=entry['title'],
|
|
||||||
updated=update_date,
|
|
||||||
summary='TODO: fill this out.'))
|
|
||||||
|
|
||||||
entries_text = entries_io.getvalue()
|
|
||||||
|
|
||||||
atom_feed = atom_template.format(
|
|
||||||
last_update=last_update,
|
|
||||||
entries=entries_io.getvalue())
|
|
||||||
entries_io.close()
|
|
||||||
|
|
||||||
atom_filename = os.path.join(output_directory, 'atom.xml')
|
|
||||||
print_file('', atom_filename)
|
|
||||||
atom_file = open(atom_filename, 'w')
|
|
||||||
atom_file.write(atom_feed)
|
|
||||||
atom_file.close()
|
|
||||||
|
|
||||||
|
|
||||||
def copy_site():
|
|
||||||
os.system('cp -r output/* %s' % deploy_directory)
|
|
||||||
|
|
||||||
|
|
||||||
def deploy_site():
|
def deploy_site():
|
||||||
copy_site()
|
os.system('cp -r output/* %s' % deploy_directory)
|
||||||
os.chdir(os.path.expanduser(deploy_directory))
|
os.chdir(os.path.expanduser(deploy_directory))
|
||||||
os.system('git add .')
|
os.system('git add .')
|
||||||
os.system('git commit -m "automated update from build.py"')
|
os.system('git commit -m "automated update from build.py"')
|
||||||
@ -196,12 +116,9 @@ def main():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--fast', action='store_true',
|
'--fast', action='store_true',
|
||||||
help='only rebuild content files')
|
help='only rebuild content files')
|
||||||
parser.add_argument(
|
|
||||||
'--copy', action='store_true',
|
|
||||||
help='copy output files to www-home git repo')
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--deploy', action='store_true',
|
'--deploy', action='store_true',
|
||||||
help='deploy the site by pushing the www-home git repo to production')
|
help='deploy the site by pushing to the www-home git repo')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.clean:
|
if args.clean:
|
||||||
@ -211,10 +128,7 @@ def main():
|
|||||||
copy_static_files()
|
copy_static_files()
|
||||||
process_markdown_files()
|
process_markdown_files()
|
||||||
make_sitemap()
|
make_sitemap()
|
||||||
make_atom_feed()
|
make_rss()
|
||||||
|
|
||||||
if args.copy and not args.deploy:
|
|
||||||
copy_site()
|
|
||||||
|
|
||||||
if args.deploy:
|
if args.deploy:
|
||||||
if args.fast:
|
if args.fast:
|
||||||
|
@ -32,7 +32,6 @@ For more details, check my [resumé](resume.html) & [publications](publications.
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
## Latest Updates
|
## Latest Updates
|
||||||
|
|
||||||
You can sign up for occasional updates via my [email newsletter](https://tinyletter.com/mcmillen).
|
You can sign up for occasional updates via my [email newsletter](https://tinyletter.com/mcmillen).
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<link rel="icon" type="image/png" href="/favicon.ico">
|
<link rel="icon" type="image/png" href="/favicon.ico">
|
||||||
<link rel="canonical" href="https://www.mcmillen.dev/{page_url}">
|
<link rel="canonical" href="https://www.mcmillen.dev/{page_url}">
|
||||||
<link rel="alternate" type="application/atom+xml" href="https://www.mcmillen.dev/atom.xml" title="Colin McMillen's Blog - Atom">
|
|
||||||
|
|
||||||
<title>{title}</title>
|
<title>{title}</title>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user