|
|
|
@ -25,6 +25,15 @@ old_post_url = ["2005-01-25","2013-05-17","2011-02-07","2012-03-19","2012-01-18"
|
|
|
|
|
html_page_template = "page_template.html"
|
|
|
|
|
email_template = "email_template.html"
|
|
|
|
|
gemini_page_template = "page_template.gmi"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def fill_globals(text):
|
|
|
|
|
return text.replace("$AUTHOR", global_name)\
|
|
|
|
|
.replace("$BASE_URL", base_url)\
|
|
|
|
|
.replace("$GLOBAL_TITLE", global_title)\
|
|
|
|
|
.replace("$SUBTITLE", global_subtitle)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Add the html version to the post dictionnary
|
|
|
|
|
# Also convert locals links that ends .gmi to .html
|
|
|
|
|
# if index = true, a special style is applied before the first subtitle
|
|
|
|
@ -273,9 +282,14 @@ def build_atom_post(p):
|
|
|
|
|
date = datetime.strptime(p["date"],"%Y-%m-%d").isoformat() + "Z"
|
|
|
|
|
content = html.escape(p["html_content"])
|
|
|
|
|
title = html.escape(p["title"])
|
|
|
|
|
final = template.replace("$DATE",date).replace("$TITLE",title).\
|
|
|
|
|
replace("$URL",p["html_url"]).replace("$CONTENT",content).\
|
|
|
|
|
replace("$LANG",p["lang"]).replace("$AUTHOR", global_name).replace("$BASE_URL",base_url)
|
|
|
|
|
final = fill_globals(
|
|
|
|
|
template
|
|
|
|
|
.replace("$DATE", date)
|
|
|
|
|
.replace("$TITLE", title)
|
|
|
|
|
.replace("$URL", p["html_url"])
|
|
|
|
|
.replace("$CONTENT", content)
|
|
|
|
|
.replace("$LANG", p["lang"])
|
|
|
|
|
)
|
|
|
|
|
return final
|
|
|
|
|
|
|
|
|
|
def write_atom_index(allposts,folder,limit=10):
|
|
|
|
@ -305,10 +319,14 @@ def write_atom_index(allposts,folder,limit=10):
|
|
|
|
|
lang = "fr"
|
|
|
|
|
url = "https://"+base_url
|
|
|
|
|
feedurl = url + atomname
|
|
|
|
|
final = atom_template.replace("$CONTENT",atom_content).replace("$DATE",date).\
|
|
|
|
|
replace("$GLOBAL_TITLE",global_title).replace("$URL",url).\
|
|
|
|
|
replace("$SUBTITLE",global_subtitle).replace("$LANG",lang).\
|
|
|
|
|
replace("$FEEDURL",feedurl)
|
|
|
|
|
final = fill_globals(
|
|
|
|
|
atom_template
|
|
|
|
|
.replace("$CONTENT", atom_content)
|
|
|
|
|
.replace("$DATE", date)
|
|
|
|
|
.replace("$URL", url)
|
|
|
|
|
.replace("$LANG", lang)
|
|
|
|
|
.replace("$FEEDURL", feedurl)
|
|
|
|
|
)
|
|
|
|
|
with open(atompath,"w") as f:
|
|
|
|
|
f.write(final)
|
|
|
|
|
f.close()
|
|
|
|
@ -395,7 +413,7 @@ def build_index(allposts,folder,short=False):
|
|
|
|
|
#content += p["gem_content"]
|
|
|
|
|
if short and stop:
|
|
|
|
|
content += "\n=> index_all.gmi All posts"
|
|
|
|
|
index["gem_content"] = content.replace("$GLOBAL_TITLE", global_title)
|
|
|
|
|
index["gem_content"] = fill_globals(content)
|
|
|
|
|
index["html_content"] = gmi2html(content,index=True)
|
|
|
|
|
index["gem_url"] = "gemini://" + base_url + index["gmifilename"]
|
|
|
|
|
index["html_url"] = "https://" + base_url + index["htmlfilename"]
|
|
|
|
@ -424,11 +442,14 @@ def filltemplate(post,template):
|
|
|
|
|
image = ""
|
|
|
|
|
if "title" in post.keys():
|
|
|
|
|
template = template.replace("$TITLE", post["title"])
|
|
|
|
|
final_page = template.replace("$CONTENT", post["html_content"])\
|
|
|
|
|
.replace("$SUBTITLE", subtitle).replace("$LANG", post["lang"])\
|
|
|
|
|
.replace("$GEMLINK", post["gem_url"]).replace("$HTMLLINK", post["html_url"])\
|
|
|
|
|
.replace("$IMAGE_HEADER", image).replace("$GLOBAL_TITLE", global_title)\
|
|
|
|
|
.replace("$AUTHOR", global_name)
|
|
|
|
|
final_page = fill_globals(
|
|
|
|
|
template
|
|
|
|
|
.replace("$CONTENT", post["html_content"])
|
|
|
|
|
.replace("$LANG", post["lang"])
|
|
|
|
|
.replace("$GEMLINK", post["gem_url"])
|
|
|
|
|
.replace("$HTMLLINK", post["html_url"])
|
|
|
|
|
.replace("$IMAGE_HEADER", image)
|
|
|
|
|
)
|
|
|
|
|
return final_page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -470,11 +491,13 @@ def writegmi(post):
|
|
|
|
|
date = post["date"]
|
|
|
|
|
else:
|
|
|
|
|
date = ""
|
|
|
|
|
final_page = template.replace("$CONTENT", post["gem_content"])\
|
|
|
|
|
.replace("$DATE", date)\
|
|
|
|
|
.replace("$GEMLINK", post["gem_url"])\
|
|
|
|
|
.replace("$HTMLLINK", post["html_url"])\
|
|
|
|
|
.replace("$GLOBAL_TITLE", global_title)
|
|
|
|
|
final_page = fill_globals(
|
|
|
|
|
template
|
|
|
|
|
.replace("$CONTENT", post["gem_content"])
|
|
|
|
|
.replace("$DATE", date)
|
|
|
|
|
.replace("$GEMLINK", post["gem_url"])
|
|
|
|
|
.replace("$HTMLLINK", post["html_url"])
|
|
|
|
|
)
|
|
|
|
|
filename = geminidir + "/" + post["gmifilename"]
|
|
|
|
|
p = Path(filename)
|
|
|
|
|
if not p.parent.exists():
|
|
|
|
@ -497,6 +520,10 @@ def copy_static_files(source, dest):
|
|
|
|
|
|
|
|
|
|
# Main call
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# Check for the destination folders
|
|
|
|
|
for dir in [htmldir, geminidir]:
|
|
|
|
|
if not os.path.isdir(dir):
|
|
|
|
|
os.mkdir(dir)
|
|
|
|
|
all_posts = []
|
|
|
|
|
local = False
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
|