2024-12-29 07:49:19 -05:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
from datetime import datetime
|
|
|
|
|
2025-01-08 05:38:01 -05:00
|
|
|
import _utils
|
2024-12-29 07:49:19 -05:00
|
|
|
|
|
|
|
if not os.path.exists("_capsule"):
|
|
|
|
os.makedirs("_capsule")
|
|
|
|
|
|
|
|
with open("_layouts/home.gmi", mode="r", encoding="utf8") as file:
|
|
|
|
home_body = file.read()
|
|
|
|
with open("_layouts/article.gmi", mode="r", encoding="utf8") as file:
|
|
|
|
article_body = file.read()
|
|
|
|
with open("_includes/header.gmi", mode="r", encoding="utf8") as file:
|
|
|
|
header_body = file.read()
|
|
|
|
with open("_includes/footer.gmi", mode="r", encoding="utf8") as file:
|
|
|
|
footer_body = file.read()
|
|
|
|
with open("_includes/links.gmi", mode="r", encoding="utf8") as file:
|
|
|
|
links_body = file.read()
|
|
|
|
|
2025-01-08 05:38:01 -05:00
|
|
|
articles = glob.glob("_posts/*.gmi")
|
2025-01-07 08:38:30 -05:00
|
|
|
articles.sort()
|
|
|
|
|
2024-12-29 07:49:19 -05:00
|
|
|
if os.getenv("GEMINI_ENV") != "production":
|
2025-01-08 05:38:01 -05:00
|
|
|
articles += glob.glob("_drafts/*.gmi")
|
2024-12-29 07:49:19 -05:00
|
|
|
|
2025-01-07 08:38:30 -05:00
|
|
|
today = datetime.today().strftime("%F")
|
2024-12-29 07:49:19 -05:00
|
|
|
year = datetime.today().strftime("%Y")
|
|
|
|
|
|
|
|
articles_list = []
|
|
|
|
|
|
|
|
for article in articles:
|
2025-01-08 05:38:01 -05:00
|
|
|
gmi = article.replace("_posts/", "").replace("_drafts/", "")
|
2024-12-29 07:49:19 -05:00
|
|
|
|
2025-01-08 05:38:01 -05:00
|
|
|
fm = _utils.load(article)
|
|
|
|
article_title = fm.metadata["title"]
|
|
|
|
article_date = fm.metadata.get("date")
|
|
|
|
article_content = fm.content
|
2024-12-29 07:49:19 -05:00
|
|
|
|
|
|
|
if article_date is None:
|
|
|
|
article_date = today
|
|
|
|
gmi = f"{article_date}-{gmi}"
|
|
|
|
elif isinstance(article_date, str):
|
|
|
|
article_date = datetime.fromisoformat(article_date).strftime("%Y-%m-%d")
|
|
|
|
|
|
|
|
body = (
|
|
|
|
article_body.replace("%%header%%", header_body)
|
|
|
|
.replace("%%links%%", links_body)
|
|
|
|
.replace("%%title%%", f"{article_title}\n{article_date}\n")
|
|
|
|
.replace("%%body%%", article_content)
|
|
|
|
.replace("%%footer%%", footer_body)
|
|
|
|
.replace("%%year%%", year)
|
|
|
|
)
|
|
|
|
|
|
|
|
articles_list.append(f"=> {gmi} {article_date} {article_title}")
|
|
|
|
with open(f"_capsule/{gmi}", mode="w", encoding="utf8") as file:
|
|
|
|
file.write(body)
|
|
|
|
|
|
|
|
articles_list.sort(reverse=True)
|
|
|
|
|
2025-01-08 05:38:01 -05:00
|
|
|
fm = _utils.load("index.gmi")
|
|
|
|
home_content = fm.content
|
2024-12-29 07:49:19 -05:00
|
|
|
|
|
|
|
body = (
|
|
|
|
home_body.replace("%%header%%", header_body)
|
|
|
|
.replace("%%links%%", links_body)
|
|
|
|
.replace("%%body%%", home_content)
|
|
|
|
.replace("%%articles%%", "\n".join(articles_list))
|
|
|
|
.replace("%%footer%%", footer_body)
|
|
|
|
.replace("%%year%%", year)
|
|
|
|
)
|
|
|
|
|
|
|
|
with open("_capsule/index.gmi", mode="w", encoding="utf8") as file:
|
|
|
|
file.write(body)
|