diff options
Diffstat (limited to 'strike.py')
-rwxr-xr-x | strike.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/strike.py b/strike.py index b417bf1..0679bd1 100755 --- a/strike.py +++ b/strike.py @@ -25,13 +25,27 @@ def read_config(location): return basedir, parser def handle_file(location): - metadata = dict( + meta_dict = dict( title = '.'.join(path.basename(location).split('.')[:-1]), date = strftime('%a, %d %b %Y %H:%M:%S GMT', gmtime(path.getmtime(location))) ) with open(location, 'r') as fin: file_contents = fin.read() - return file_contents, metadata + contents = handle_frontmatter(file_contents, meta_dict) + return contents, meta_dict + +def handle_frontmatter(file_contents, meta_dict): + delim = '---\n' + if not file_contents.startswith(delim): + return file_contents + parts = file_contents.split(delim, maxsplit=2) + meta_lines = parts[1].splitlines() + meta = dict( + (x.strip(), y.strip()) + for x, y in (kvp.split('=') for kvp in meta_lines) + ) + meta_dict.update(meta) + return parts[2] def apply_template(content, metadata, template="{content}"): return template.format( |