meta-pages #1

Merged
raspbeguy merged 10 commits from meta-pages into master 2020-12-03 21:43:18 +01:00
1 changed files with 21 additions and 1 deletions
Showing only changes of commit 5c8aadfb4a - Show all commits

View File

@ -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)