Added a function to auto-fill globals
This commit is contained in:
parent
585bcbbb9a
commit
4a9ca0db99
@ -1,6 +1,6 @@
|
|||||||
# $DATE $TITLE
|
# $DATE $TITLE
|
||||||
$CONTENT
|
$CONTENT
|
||||||
|
|
||||||
----
|
----
|
||||||
CC0 - Take Care ❤
|
CC0 - Take Care ❤
|
||||||
|
=> gemini://$BASE_URL index
|
||||||
=> $HTMLLINK https version of this page
|
=> $HTMLLINK https version of this page
|
||||||
|
59
publish.py
59
publish.py
@ -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"
|
html_page_template = "page_template.html"
|
||||||
email_template = "email_template.html"
|
email_template = "email_template.html"
|
||||||
gemini_page_template = "page_template.gmi"
|
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
|
# Add the html version to the post dictionnary
|
||||||
# Also convert locals links that ends .gmi to .html
|
# Also convert locals links that ends .gmi to .html
|
||||||
# if index = true, a special style is applied before the first subtitle
|
# 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"
|
date = datetime.strptime(p["date"],"%Y-%m-%d").isoformat() + "Z"
|
||||||
content = html.escape(p["html_content"])
|
content = html.escape(p["html_content"])
|
||||||
title = html.escape(p["title"])
|
title = html.escape(p["title"])
|
||||||
final = template.replace("$DATE",date).replace("$TITLE",title).\
|
final = fill_globals(
|
||||||
replace("$URL",p["html_url"]).replace("$CONTENT",content).\
|
template
|
||||||
replace("$LANG",p["lang"]).replace("$AUTHOR", global_name).replace("$BASE_URL",base_url)
|
.replace("$DATE", date)
|
||||||
|
.replace("$TITLE", title)
|
||||||
|
.replace("$URL", p["html_url"])
|
||||||
|
.replace("$CONTENT", content)
|
||||||
|
.replace("$LANG", p["lang"])
|
||||||
|
)
|
||||||
return final
|
return final
|
||||||
|
|
||||||
def write_atom_index(allposts,folder,limit=10):
|
def write_atom_index(allposts,folder,limit=10):
|
||||||
@ -305,10 +319,14 @@ def write_atom_index(allposts,folder,limit=10):
|
|||||||
lang = "fr"
|
lang = "fr"
|
||||||
url = "https://"+base_url
|
url = "https://"+base_url
|
||||||
feedurl = url + atomname
|
feedurl = url + atomname
|
||||||
final = atom_template.replace("$CONTENT",atom_content).replace("$DATE",date).\
|
final = fill_globals(
|
||||||
replace("$GLOBAL_TITLE",global_title).replace("$URL",url).\
|
atom_template
|
||||||
replace("$SUBTITLE",global_subtitle).replace("$LANG",lang).\
|
.replace("$CONTENT", atom_content)
|
||||||
replace("$FEEDURL",feedurl)
|
.replace("$DATE", date)
|
||||||
|
.replace("$URL", url)
|
||||||
|
.replace("$LANG", lang)
|
||||||
|
.replace("$FEEDURL", feedurl)
|
||||||
|
)
|
||||||
with open(atompath,"w") as f:
|
with open(atompath,"w") as f:
|
||||||
f.write(final)
|
f.write(final)
|
||||||
f.close()
|
f.close()
|
||||||
@ -395,7 +413,7 @@ def build_index(allposts,folder,short=False):
|
|||||||
#content += p["gem_content"]
|
#content += p["gem_content"]
|
||||||
if short and stop:
|
if short and stop:
|
||||||
content += "\n=> index_all.gmi All posts"
|
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["html_content"] = gmi2html(content,index=True)
|
||||||
index["gem_url"] = "gemini://" + base_url + index["gmifilename"]
|
index["gem_url"] = "gemini://" + base_url + index["gmifilename"]
|
||||||
index["html_url"] = "https://" + base_url + index["htmlfilename"]
|
index["html_url"] = "https://" + base_url + index["htmlfilename"]
|
||||||
@ -424,11 +442,14 @@ def filltemplate(post,template):
|
|||||||
image = ""
|
image = ""
|
||||||
if "title" in post.keys():
|
if "title" in post.keys():
|
||||||
template = template.replace("$TITLE", post["title"])
|
template = template.replace("$TITLE", post["title"])
|
||||||
final_page = template.replace("$CONTENT", post["html_content"])\
|
final_page = fill_globals(
|
||||||
.replace("$SUBTITLE", subtitle).replace("$LANG", post["lang"])\
|
template
|
||||||
.replace("$GEMLINK", post["gem_url"]).replace("$HTMLLINK", post["html_url"])\
|
.replace("$CONTENT", post["html_content"])
|
||||||
.replace("$IMAGE_HEADER", image).replace("$GLOBAL_TITLE", global_title)\
|
.replace("$LANG", post["lang"])
|
||||||
.replace("$AUTHOR", global_name)
|
.replace("$GEMLINK", post["gem_url"])
|
||||||
|
.replace("$HTMLLINK", post["html_url"])
|
||||||
|
.replace("$IMAGE_HEADER", image)
|
||||||
|
)
|
||||||
return final_page
|
return final_page
|
||||||
|
|
||||||
|
|
||||||
@ -470,11 +491,13 @@ def writegmi(post):
|
|||||||
date = post["date"]
|
date = post["date"]
|
||||||
else:
|
else:
|
||||||
date = ""
|
date = ""
|
||||||
final_page = template.replace("$CONTENT", post["gem_content"])\
|
final_page = fill_globals(
|
||||||
.replace("$DATE", date)\
|
template
|
||||||
.replace("$GEMLINK", post["gem_url"])\
|
.replace("$CONTENT", post["gem_content"])
|
||||||
.replace("$HTMLLINK", post["html_url"])\
|
.replace("$DATE", date)
|
||||||
.replace("$GLOBAL_TITLE", global_title)
|
.replace("$GEMLINK", post["gem_url"])
|
||||||
|
.replace("$HTMLLINK", post["html_url"])
|
||||||
|
)
|
||||||
filename = geminidir + "/" + post["gmifilename"]
|
filename = geminidir + "/" + post["gmifilename"]
|
||||||
p = Path(filename)
|
p = Path(filename)
|
||||||
if not p.parent.exists():
|
if not p.parent.exists():
|
||||||
|
Loading…
Reference in New Issue
Block a user