-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
title: You May Forget | ||
author: Sappho | ||
country: Greece | ||
year: 600/500 bc | ||
gender: female | ||
tags: | ||
- time | ||
- love | ||
- lyric | ||
- memory | ||
--- | ||
|
||
You may forget but | ||
let me tell you | ||
this: someone in | ||
some future time | ||
will think of us. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
markdown | ||
PyYaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Script to convert poems & stories written in Zenup to HTML | ||
usage: | ||
zenup.py <folder-to-zenup-files> | ||
copyright: | ||
(c) 2014 by Priyatam Mudivarti | ||
license: | ||
BSD-style License; see LICENSE for more details. | ||
""" | ||
|
||
import sys | ||
import os | ||
import yaml | ||
import markdown as md | ||
import argparse | ||
|
||
|
||
def load(path): | ||
"""Create a dictionary for retrieving content's raw body, metadata""" | ||
data = [] | ||
for fname in os.listdir(path): | ||
if fname.endswith('.md') or fname.endswith('.txt'): | ||
try: | ||
meta, raw = read_contents(path, fname) | ||
content = { | ||
"name": meta.get("_type", "contents") + "/" + fname, | ||
"original": raw, | ||
"html": md.markdown(post['body']), | ||
"modified_date": format_date(path + os.sep + fname) | ||
} | ||
content.update(meta) | ||
data.append(content) | ||
except: | ||
logger.error("Error while reading contents: %s: %s" % (fname, sys.exc_info()[0])) | ||
else: | ||
logger.warning("Incorrect Extension: %s" % fname) | ||
return data | ||
|
||
|
||
def read_contents(directory, fname): | ||
"""Splits subdir/fname into a tuple of YAML and raw content""" | ||
with open(directory + os.sep + fname, "r", "utf-8") as fin: | ||
yaml_and_raw = fin.read().split('\n---\n') | ||
if len(yaml_and_raw) == 1: | ||
return {}, yaml_and_raw[0] | ||
else: | ||
return yaml.load(yaml_and_raw[0]), yaml_and_raw[1] | ||
|
||
|
||
def format_date(fname): | ||
"""Formats to internal date format""" | ||
return datetime.strptime(time.ctime(os.path.getmtime(fname)), "%a %b %d %H:%M:%S %Y").strftime("%m-%d-%y") | ||
|
||
|
||
def parse_cmdline_args(args): | ||
"""Parse command line args""" | ||
parser = argparse.ArgumentParser(description='Zenup: A minimalist static site generator and router.') | ||
parser.add_argument("root", type=str, | ||
help='path to root project folder containing zenup files') | ||
return parser.parse_args(args[1:]) | ||
|
||
if __name__ == '__main__': | ||
args = parse_cmdline_args(sys.argv) | ||
if args.root: | ||
load(args) |