#! /usr/bin/python
from feedgen.feed import FeedGenerator
import argparse
import os
import sys
import time
from stat import S_ISREG, ST_CTIME, ST_MODE
import subprocess
from pathlib import Path
import markdown
from datetime import datetime
parser = argparse.ArgumentParser(prog="pog", description="python weblog", epilog="python weblog")
parser.add_argument("option", help="post [-n, --name] to make a post, title following -n with no spaces. init to initialize new blog in a directory. edit [-n, --name] to edit a post. update to rebuild site")
parser.add_argument("-n", "--name", help="name of post to edit/create")
args = parser.parse_args()
# settings:
author = "flat" # i think all options except maybe the last few are pretty self-explanatory
contact = "flat@fuckup.club"
website = "https://tilde.team/~flat/"
bloglink = "https://tilde.team/~flat/blog/"
description = 'infrequent rambles about whatever i really feel like thinking about at the moment.'
title = author + "'s blog"
header = f'
anything to say? email me! written by {author} - generated with pog!
'
dateformat = '%Y-%m-%d'
exceptions = {"index.html", # all pages to ignore when building blog
"pog.py",
"atom.xml",
"README.md",
"edit.py"
}
pages = ["../index.html", "atom.xml"] # other pages to show on the navbar
tildeMode = True # just a failsafe feature cause sometimes tilde.team bugs out with the editing, this forces nvim
def update():
with open("index.html", "w") as f:
f.write(f'{title}
')
update()
f.write("")
case "update":
update()
case "post":
with open(f'drafts/{args.name}.md', "w") as f:
date = datetime.today().strftime(dateformat)
f.write("")
f.write("\n" + f'## {args.name}')
f.write(f'\n_{date}_')
if tildeMode is False:
subprocess.call(("xdg-open", f'drafts/{args.name}.md'))
else:
subprocess.call(("nvim", f'drafts/{args.name}.md'))
opt = input("post written, what do you want to do now?\n(s) save draft (p) post (d) discard post\n> ")
match opt:
case "s":
print(f"saved draft in drafts/{args.name}.md")
case "p":
update()
print("post succesful")
case "d":
os.remove(f"drafts/{args.name}.md")
print("file removed")
case "edit":
if tildeMode is False:
subprocess.call(("xdg-open", f'drafts/{args.name}.md'))
else:
subprocess.call(("nvim", f'drafts/{args.name}.md'))
opt = input("post written, what do you want to do now?\n(s) save draft (p) post (d) discard post\n> ")
match opt:
case "s":
print(f"saved draft in drafts/{args.name}.md")
case "p":
update()
print("post succesful")
case "d":
os.remove(f"drafts/{args.name}.md")
print("file removed")
case other:
print("invalid command")