Skip to content

Commit

Permalink
scripts update
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed Dec 27, 2023
1 parent 99cb2f8 commit acff01f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
1 change: 0 additions & 1 deletion scripts/generators/atom_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
for f in sorted(files, key=lambda x: x, reverse=True):
with open(f) as file:
post = frontmatter.load(file)

try:
post["date"] = datetime.strptime(post["date"], "%Y-%m-%dT%H:%M:%S%z").isoformat()
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion scripts/hooks/fs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jinja2, os, json, yaml
import json, os, yaml

def path_exists(path):
if isinstance(path, str):
Expand Down
39 changes: 39 additions & 0 deletions scripts/hooks/new_post.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import argparse, re
from datetime import datetime, timezone

"""
Creates a new blog post to edit manually or with content if specified.
"""
def new_post(title, author, content=None):
dt = datetime.now(timezone.utc).replace(microsecond=0)
date = dt.strftime("%Y-%m-%d")
path = "docs/news/posts"
name = title.lower()
name = name.replace(' ', '-')
name = re.sub("[^0-9a-z\-\.-]*", '', name)
path = "{}/{}-{}.md".format(path, date, name)
date = dt.strftime("%Y-%m-%dT%T%z") # without comma in tz
post = "\
---\n\
title: \"{}\"\n\
author: \"{}\"\n\
date: \"{}\"\n\
---\n".format(title, author, date)
if content is not None:
post += content

with open(path, "w") as file:
file.write(post)

print("File created at \"{}\".".format(path))
return path

def main():
parser = argparse.ArgumentParser(description="creates a new blog post to edit manually or with content if specified.")
parser.add_argument("title", type=str, help="post title")
parser.add_argument("author", type=str, help="post author")
parser.add_argument('-c', '--content', help="post content (optional)", type=str)
args = parser.parse_args()

if __name__ == "__main__":
main()

0 comments on commit acff01f

Please sign in to comment.