Compare commits

...

11 Commits

Author SHA1 Message Date
raspbeguy 7c5a7fe392 Merge pull request 'meta-pages' (#1) from meta-pages into master
Reviewed-on: #1
2020-12-03 20:43:17 +00:00
Guy Godfroy 0381920b95 fix fucking indentation 2020-12-03 21:18:38 +01:00
Guy Godfroy 030b1c4cdb pass filename to template 2020-12-03 21:17:21 +01:00
Guy Godfroy 4490a7d5ed how about that? 2020-12-03 20:52:30 +01:00
Guy Godfroy 785e4c4cf2 not at all 2020-12-03 20:50:37 +01:00
Guy Godfroy 662c46b0f0 normally that should work 2020-12-03 20:44:02 +01:00
Guy Godfroy 5c8aadfb4a WIP 2020-12-03 20:24:20 +01:00
Guy Godfroy a7cd7a073c oups 2020-12-03 18:46:43 +01:00
Guy Godfroy 37465d721a fix wrong parameter name 2020-12-03 18:39:42 +01:00
Guy Godfroy cda71c374b change to adapt to link_func 2020-12-03 18:36:35 +01:00
Guy Godfroy e8d60d0d26 WIP: add meta pages 2020-12-03 17:06:52 +01:00
2 changed files with 38 additions and 6 deletions

View File

@ -5,10 +5,14 @@
locale = "fr_FR.utf8"
# 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
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
tpl_dir = "~/repo/htg-content/gemini/templates"

View File

@ -5,6 +5,7 @@ import frontmatter
from jinja2 import Template
import os
import locale
from datetime import datetime
import config
@ -14,12 +15,19 @@ locale.setlocale(locale.LC_ALL, config.locale)
md_path = os.path.expanduser(config.md_dir)
gmi_path = os.path.expanduser(config.gmi_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)
def add_ext_gmi(link):
# Custom function to apply to local links
return link+".gmi"
# Custom function to apply to links
if "://" not in link: # apply only on local links
return link+".gmi"
else:
return link
# Walk through markdown directories
for dirname, subdirlist, mdlist in os.walk('.'):
@ -49,9 +57,10 @@ for dirname, subdirlist, mdlist in os.walk('.'):
author = meta.get("author", None)
date = meta.get("date", 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
# TODO: make possible to list tags as a YAML list
for item in config.replace:
mdtext = mdtext.replace(item[0],item[1])
@ -66,7 +75,7 @@ for dirname, subdirlist, mdlist in os.walk('.'):
plain=config.plain,
strip_html=config.strip_html,
base_url=config.base_url,
rellink_func=add_ext_gmi,
link_func=add_ext_gmi,
table_tag=config.table_tag
)
@ -99,6 +108,25 @@ for dirname, subdirlist, mdlist in os.walk('.'):
gmifile = basename
if config.gmi_extension:
gmifile += ".gmi"
posts_meta.append({
"title": title,
"author": author,
"date": date,
"tags": tags,
"filename": gmifile
})
print(gmi_subpath+"/"+gmifile)
with open(gmi_subpath+"/"+gmifile, 'w') as gmi:
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)