Compare commits

..

No commits in common. "4395dea1fd53b07cc2d520dc9236bf2e2f5a611c" and "b2509a3c48ee246e64ab45bc5db1397e3b4d1e78" have entirely different histories.

3 changed files with 61 additions and 73 deletions

127
build.py
View File

@ -22,7 +22,6 @@ import os
import re import re
import shutil import shutil
input_directory = 'content' input_directory = 'content'
static_directory = 'static' static_directory = 'static'
output_directory = 'output' output_directory = 'output'
@ -33,86 +32,68 @@ md_extensions = ['fenced_code', 'codehilite', 'nl2br', 'toc', 'smarty', 'tables'
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))
template = open('template.html').read()
def copy_static_files(): os.makedirs(output_directory, exist_ok=True)
for (dirpath, _, filenames) in os.walk(static_directory):
for filename in filenames: for (dirpath, _, filenames) in os.walk(static_directory):
source = os.path.join(dirpath, filename) for filename in filenames:
out_path = dirpath.replace(static_directory, '', 1) source = os.path.join(dirpath, filename)
out_path = out_path.lstrip('/') out_path = dirpath.replace(static_directory, '', 1)
dest_dir = os.path.join(output_directory, out_path) out_path = out_path.lstrip('/')
os.makedirs(dest_dir, exist_ok=True) dest_dir = os.path.join(output_directory, out_path)
dest = os.path.join(dest_dir, filename) os.makedirs(dest_dir, exist_ok=True)
print_file(source, dest) dest = os.path.join(dest_dir, filename)
shutil.copy2(source, dest) print_file(source, dest)
shutil.copy2(source, dest)
def process_markdown_files(): for (dirpath, _, filenames) in os.walk(input_directory):
template = open('template.html').read() for filename in filenames:
for (dirpath, _, filenames) in os.walk(input_directory): markdown_filename = os.path.join(dirpath, filename)
for filename in filenames: if not markdown_filename.endswith('.md'):
markdown_filename = os.path.join(dirpath, filename) continue
if not markdown_filename.endswith('.md'):
continue
markdown_file = open(markdown_filename) markdown_file = open(markdown_filename)
text = markdown_file.read() text = markdown_file.read()
markdown_file.close() markdown_file.close()
if not text.startswith('# '): if not text.startswith('# '):
text = '# ' + text text = '# ' + text
match = re.match(r'^(.*?)\n', text) match = re.match(r'^(.*?)\n', text)
if match: if match:
title = match.group(1).lstrip('# ') title = match.group(1).lstrip('# ')
else: else:
title = text title = text
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'
out_filename = os.path.basename(markdown_filename).replace('.md', '.html') out_filename = os.path.basename(markdown_filename).replace('.md', '.html')
out_dirpath = os.path.join(output_directory, dirpath) out_dirpath = os.path.join(output_directory, dirpath)
out_dirpath = out_dirpath.replace('/content', '', 1) out_dirpath = out_dirpath.replace('/content', '', 1)
out_fullpath = os.path.join(out_dirpath, out_filename) out_fullpath = os.path.join(out_dirpath, out_filename)
page_url = out_fullpath.replace('output/', '', 1) page_url = out_fullpath.replace('output/', '', 1)
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')]
html = markdown.markdown(text, extensions=md_extensions, output_format='html5') html = markdown.markdown(text, extensions=md_extensions, output_format='html5')
output = template.replace('__TITLE_GOES_HERE__', title) output = template.replace('__TITLE_GOES_HERE__', title)
output = output.replace('__CONTENT_GOES_HERE__', html) output = output.replace('__CONTENT_GOES_HERE__', html)
output = output.replace('__PAGE_URL_GOES_HERE__', page_url) output = output.replace('__PAGE_URL_GOES_HERE__', 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)
out_file = open(out_fullpath, 'w') out_file = open(out_fullpath, 'w')
out_file.write(output) out_file.write(output)
out_file.close() out_file.close()
# TODO: make a sitemap / RSS?
def make_sitemap(): #index_filename = os.path.join(output_directory, 'index.html')
sitemap_command = ' '.join(""" #print_file('', index_filename)
find output -regextype posix-extended -regex '.*.(html|pdf)$' | #index = open(index_filename, 'w')
grep -v ^output/google | #for f in out_filenames:
grep -v ^output/drafts | # index.write('<a href="%s">%s</a><br>' % (f, f))
perl -pe 's|output|https://www.mcmillen.dev|' #index.close()
> output/sitemap.txt""".split('\n'))
os.system(sitemap_command)
def make_rss(): # TODO: implement.
pass
def main():
os.makedirs(output_directory, exist_ok=True)
copy_static_files()
process_markdown_files()
make_sitemap()
make_rss()
if __name__ == '__main__':
main()

7
static/sitemap.txt Normal file
View File

@ -0,0 +1,7 @@
https://www.mcmillen.dev
https://www.mcmillen.dev/language_checklist.html
https://www.mcmillen.dev/publications.html
https://www.mcmillen.dev/resume.html
https://www.mcmillen.dev/sigbovik/
https://www.mcmillen.dev/sigbovik/2019.pdf
https://www.mcmillen.dev/sigbovik/splatters.html