From e8d60d0d26e678dbf849ab6ce01f4c92efe1d8ff Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 17:06:52 +0100 Subject: [PATCH 01/10] WIP: add meta pages --- config.py.example | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/config.py.example b/config.py.example index ad05373..74ed6d2 100644 --- a/config.py.example +++ b/config.py.example @@ -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" From cda71c374b60fb16ea2aff9127dd8a2bc2e67c90 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 18:36:35 +0100 Subject: [PATCH 02/10] change to adapt to link_func --- geminer.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geminer.py b/geminer.py index d0958bc..ea1d73c 100755 --- a/geminer.py +++ b/geminer.py @@ -18,8 +18,9 @@ tpl_path = os.path.expanduser(config.tpl_dir) 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" # Walk through markdown directories for dirname, subdirlist, mdlist in os.walk('.'): From 37465d721a60ae4b5dd6cdb8f99c989aecf01539 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 18:39:42 +0100 Subject: [PATCH 03/10] fix wrong parameter name --- geminer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geminer.py b/geminer.py index ea1d73c..5b06d6d 100755 --- a/geminer.py +++ b/geminer.py @@ -67,7 +67,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 ) From a7cd7a073ca634081936e46bc5b2626ed997d2bf Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 18:46:43 +0100 Subject: [PATCH 04/10] oups --- geminer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/geminer.py b/geminer.py index 5b06d6d..6a382c7 100755 --- a/geminer.py +++ b/geminer.py @@ -21,6 +21,8 @@ def add_ext_gmi(link): # 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('.'): From 5c8aadfb4afef9b7cba951b7ec0be198b5c659a0 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 20:24:20 +0100 Subject: [PATCH 05/10] WIP --- geminer.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/geminer.py b/geminer.py index 6a382c7..5c9eef0 100755 --- a/geminer.py +++ b/geminer.py @@ -5,6 +5,7 @@ import frontmatter from jinja2 import Template import os import locale +from datetime import datetime import config @@ -14,6 +15,10 @@ 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) @@ -52,9 +57,17 @@ 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 + + posts_meta.append({ + "title": title, + "author": author, + "date": date, + "tags": tags + }) + for item in config.replace: mdtext = mdtext.replace(item[0],item[1]) @@ -105,3 +118,10 @@ for dirname, subdirlist, mdlist in os.walk('.'): print(gmi_subpath+"/"+gmifile) with open(gmi_subpath+"/"+gmifile, 'w') as gmi: 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) From 662c46b0f0140c22406690ce8893d8e1e138cb82 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 20:44:02 +0100 Subject: [PATCH 06/10] normally that should work --- geminer.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/geminer.py b/geminer.py index 5c9eef0..63bf76c 100755 --- a/geminer.py +++ b/geminer.py @@ -125,3 +125,6 @@ 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) From 785e4c4cf2982bf93f396629e48520b48bc57833 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 20:50:37 +0100 Subject: [PATCH 07/10] not at all --- geminer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geminer.py b/geminer.py index 63bf76c..ec417c3 100755 --- a/geminer.py +++ b/geminer.py @@ -119,7 +119,7 @@ for dirname, subdirlist, mdlist in os.walk('.'): with open(gmi_subpath+"/"+gmifile, 'w') as gmi: gmi.write(gmitext) -posts_meta = sorted(posts_meta, key=lambda p: datetime.strptime(p["date"])) +posts_meta.sort(key=lambda p: datetime.strptime(p["date"], "%Y-%m-%d"), reverse=True) with open(tpl_path+"/index.tpl", 'r') as tpl: template = Template(tpl.read()) From 4490a7d5eda0b2296684fa0a766cc0d4db831912 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 20:52:30 +0100 Subject: [PATCH 08/10] how about that? --- geminer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geminer.py b/geminer.py index ec417c3..62c60a2 100755 --- a/geminer.py +++ b/geminer.py @@ -119,7 +119,7 @@ for dirname, subdirlist, mdlist in os.walk('.'): with open(gmi_subpath+"/"+gmifile, 'w') as gmi: gmi.write(gmitext) -posts_meta.sort(key=lambda p: datetime.strptime(p["date"], "%Y-%m-%d"), reverse=True) +posts_meta.sort(key=lambda p: p["date"], reverse=True) with open(tpl_path+"/index.tpl", 'r') as tpl: template = Template(tpl.read()) From 030b1c4cdb3baec6a28bf297a2e782961001159d Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 21:17:21 +0100 Subject: [PATCH 09/10] pass filename to template --- geminer.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/geminer.py b/geminer.py index 62c60a2..698feb6 100755 --- a/geminer.py +++ b/geminer.py @@ -61,13 +61,6 @@ for dirname, subdirlist, mdlist in os.walk('.'): # For now, tags list must be a comma-separated string # 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: mdtext = mdtext.replace(item[0],item[1]) @@ -115,7 +108,16 @@ for dirname, subdirlist, mdlist in os.walk('.'): gmifile = basename if config.gmi_extension: gmifile += ".gmi" - print(gmi_subpath+"/"+gmifile) + + 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) From 0381920b95531806ac3825d947c44772be85e5f5 Mon Sep 17 00:00:00 2001 From: Guy Godfroy Date: Thu, 3 Dec 2020 21:18:38 +0100 Subject: [PATCH 10/10] fix fucking indentation --- geminer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/geminer.py b/geminer.py index 698feb6..2a7201e 100755 --- a/geminer.py +++ b/geminer.py @@ -117,7 +117,7 @@ for dirname, subdirlist, mdlist in os.walk('.'): "filename": gmifile }) - print(gmi_subpath+"/"+gmifile) + print(gmi_subpath+"/"+gmifile) with open(gmi_subpath+"/"+gmifile, 'w') as gmi: gmi.write(gmitext)