erick.is/_unpublish.py
Erick Ruiz de Chavez 40121b1c49 Refactor site content and worflow
Since the site is now Gemini first, it doesn't make sense to use Markdown. In this commit I am refactoring the site generator to remove lowdown and frontmatter dependencies.
2025-01-08 05:38:01 -05:00

59 lines
1.2 KiB
Python

import glob
import os
import sys
from datetime import datetime
import _utils
articles = glob.glob("_posts/*.gmi")
articles.sort(reverse=True)
titles = []
if len(articles) == 0:
print("No articles found")
sys.exit(1)
for article in articles:
fm = _utils.load(article)
titles.append(fm.metadata["title"])
print("\nAvailable articles:\n")
for index, title in enumerate(titles):
print(f"\t[{index + 1}] {title}")
print("")
article = ""
selection = ""
index = -1
while index < 0 or index > len(articles):
try:
index = int(selection) - 1
if index == -1:
sys.exit(0)
article = articles[index]
except (ValueError, IndexError):
selection = input("Enter a number (0 to exit): ")
fm = _utils.load(article)
file_date = datetime.fromisoformat(fm.metadata["date"]).strftime("%Y-%m-%d")
del fm.metadata["date"]
with open(
article.replace(f"_posts/{file_date}-", "_drafts/"),
mode="w",
encoding="utf8",
) as file:
file.write(_utils.dumps(fm))
try:
os.remove(article)
except PermissionError:
print(f"Permission denied to delete '{article}'.")
except Exception as e:
print(f"An error occurred: {e}")