meta-pages #1
|
@ -5,10 +5,14 @@
|
||||||
locale = "fr_FR.utf8"
|
locale = "fr_FR.utf8"
|
||||||
|
|
||||||
# path to directory containing markdonw files to convert
|
# path to directory containing markdonw files to convert
|
||||||
md_dir = "~/repo/htg-content/content/posts"
|
md_dir = "/srv/my-site-content/posts"
|
||||||
|
|
||||||
# path to directory where gemini files will be exported
|
# path to directory where gemini files will be exported
|
||||||
gmi_dir = "/tmp/gemini"
|
gmi_dir = "/srv/gemini/my-site/posts"
|
||||||
|
|
||||||
|
# path to directory where meta pages will be generated
|
||||||
|
# such as home page, tags list, tag pages, author pages...
|
||||||
|
meta_dir = "/srv/gemini/my-site"
|
||||||
|
|
||||||
# path to directory containing templates
|
# path to directory containing templates
|
||||||
tpl_dir = "~/repo/htg-content/gemini/templates"
|
tpl_dir = "~/repo/htg-content/gemini/templates"
|
||||||
|
|
34
geminer.py
34
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,12 +15,19 @@ 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)
|
||||||
|
|
||||||
def add_ext_gmi(link):
|
def add_ext_gmi(link):
|
||||||
# Custom function to apply to local links
|
# Custom function to apply to links
|
||||||
|
if "://" not in link: # apply only on local links
|
||||||
return link+".gmi"
|
return link+".gmi"
|
||||||
|
else:
|
||||||
|
return link
|
||||||
|
|
||||||
# Walk through markdown directories
|
# Walk through markdown directories
|
||||||
for dirname, subdirlist, mdlist in os.walk('.'):
|
for dirname, subdirlist, mdlist in os.walk('.'):
|
||||||
|
@ -49,9 +57,10 @@ 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
|
||||||
|
|
||||||
for item in config.replace:
|
for item in config.replace:
|
||||||
mdtext = mdtext.replace(item[0],item[1])
|
mdtext = mdtext.replace(item[0],item[1])
|
||||||
|
|
||||||
|
@ -66,7 +75,7 @@ for dirname, subdirlist, mdlist in os.walk('.'):
|
||||||
plain=config.plain,
|
plain=config.plain,
|
||||||
strip_html=config.strip_html,
|
strip_html=config.strip_html,
|
||||||
base_url=config.base_url,
|
base_url=config.base_url,
|
||||||
rellink_func=add_ext_gmi,
|
link_func=add_ext_gmi,
|
||||||
table_tag=config.table_tag
|
table_tag=config.table_tag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -99,6 +108,25 @@ for dirname, subdirlist, mdlist in os.walk('.'):
|
||||||
gmifile = basename
|
gmifile = basename
|
||||||
if config.gmi_extension:
|
if config.gmi_extension:
|
||||||
gmifile += ".gmi"
|
gmifile += ".gmi"
|
||||||
|
|
||||||
|
posts_meta.append({
|
||||||
|
"title": title,
|
||||||
|
"author": author,
|
||||||
|
"date": date,
|
||||||
|
"tags": tags,
|
||||||
|
"filename": gmifile
|
||||||
|
})
|
||||||
|
|
||||||
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.sort(key=lambda p: p["date"], reverse=True)
|
||||||
|
|
||||||
|
with open(tpl_path+"/index.tpl", 'r') as tpl:
|
||||||
|
template = Template(tpl.read())
|
||||||
|
|
||||||
|
indextext = template.render(posts_meta=posts_meta)
|
||||||
|
|
||||||
|
with open(meta_path+"/index.gmi", 'w') as index:
|
||||||
|
index.write(indextext)
|
||||||
|
|
Loading…
Reference in New Issue