WIP
This commit is contained in:
parent
a7cd7a073c
commit
5c8aadfb4a
22
geminer.py
22
geminer.py
|
@ -5,6 +5,7 @@ import frontmatter
|
||||||
from jinja2 import Template
|
from jinja2 import Template
|
||||||
import os
|
import os
|
||||||
import locale
|
import locale
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
|
||||||
|
@ -14,6 +15,10 @@ locale.setlocale(locale.LC_ALL, config.locale)
|
||||||
md_path = os.path.expanduser(config.md_dir)
|
md_path = os.path.expanduser(config.md_dir)
|
||||||
gmi_path = os.path.expanduser(config.gmi_dir)
|
gmi_path = os.path.expanduser(config.gmi_dir)
|
||||||
tpl_path = os.path.expanduser(config.tpl_dir)
|
tpl_path = os.path.expanduser(config.tpl_dir)
|
||||||
|
meta_path = os.path.expanduser(config.meta_dir)
|
||||||
|
|
||||||
|
# Initiate post meta list
|
||||||
|
posts_meta = []
|
||||||
|
|
||||||
os.chdir(md_path)
|
os.chdir(md_path)
|
||||||
|
|
||||||
|
@ -52,9 +57,17 @@ for dirname, subdirlist, mdlist in os.walk('.'):
|
||||||
author = meta.get("author", None)
|
author = meta.get("author", None)
|
||||||
date = meta.get("date", None)
|
date = meta.get("date", None)
|
||||||
title = meta.get("title", None)
|
title = meta.get("title", None)
|
||||||
tags = meta.get("tags", None)
|
tags = meta.get("tags", None).split(',')
|
||||||
# For now, tags list must be a comma-separated string
|
# For now, tags list must be a comma-separated string
|
||||||
# TODO: make possible to list tags as a YAML list
|
# TODO: make possible to list tags as a YAML list
|
||||||
|
|
||||||
|
posts_meta.append({
|
||||||
|
"title": title,
|
||||||
|
"author": author,
|
||||||
|
"date": date,
|
||||||
|
"tags": tags
|
||||||
|
})
|
||||||
|
|
||||||
for item in config.replace:
|
for item in config.replace:
|
||||||
mdtext = mdtext.replace(item[0],item[1])
|
mdtext = mdtext.replace(item[0],item[1])
|
||||||
|
|
||||||
|
@ -105,3 +118,10 @@ for dirname, subdirlist, mdlist in os.walk('.'):
|
||||||
print(gmi_subpath+"/"+gmifile)
|
print(gmi_subpath+"/"+gmifile)
|
||||||
with open(gmi_subpath+"/"+gmifile, 'w') as gmi:
|
with open(gmi_subpath+"/"+gmifile, 'w') as gmi:
|
||||||
gmi.write(gmitext)
|
gmi.write(gmitext)
|
||||||
|
|
||||||
|
posts_meta = sorted(posts_meta, key=lambda p: datetime.strptime(p["date"]))
|
||||||
|
|
||||||
|
with open(tpl_path+"/index.tpl", 'r') as tpl:
|
||||||
|
template = Template(tpl.read())
|
||||||
|
|
||||||
|
indextext = template.render(posts_meta=posts_meta)
|
||||||
|
|
Loading…
Reference in New Issue