Compare commits
No commits in common. "7c5a7fe392f5ff87aa05b47d65205a0e87ab081a" and "e5f7b3b511893ddedf574d2003728c6fec2ce27a" have entirely different histories.
7c5a7fe392
...
e5f7b3b511
|
|
@ -5,14 +5,10 @@
|
||||||
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 = "/srv/my-site-content/posts"
|
md_dir = "~/repo/htg-content/content/posts"
|
||||||
|
|
||||||
# path to directory where gemini files will be exported
|
# path to directory where gemini files will be exported
|
||||||
gmi_dir = "/srv/gemini/my-site/posts"
|
gmi_dir = "/tmp/gemini"
|
||||||
|
|
||||||
# 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"
|
||||||
|
|
|
||||||
36
geminer.py
36
geminer.py
|
|
@ -5,7 +5,6 @@ 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
|
||||||
|
|
||||||
|
|
@ -15,19 +14,12 @@ 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 links
|
# Custom function to apply to local 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('.'):
|
||||||
|
|
@ -57,10 +49,9 @@ 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).split(',')
|
tags = meta.get("tags", None)
|
||||||
# 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])
|
||||||
|
|
||||||
|
|
@ -75,7 +66,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,
|
||||||
link_func=add_ext_gmi,
|
rellink_func=add_ext_gmi,
|
||||||
table_tag=config.table_tag
|
table_tag=config.table_tag
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -108,25 +99,6 @@ 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