add support for categories

This commit is contained in:
James Ravenscroft 2021-12-23 21:53:21 +00:00
parent 107f16757a
commit efb4019c82
1 changed files with 20 additions and 5 deletions

View File

@ -64,7 +64,7 @@ def get_api_client():
@authed_endpoint
def req():
doc = request.form.to_dict()
doc = request.form.to_dict(flat=True)
if 'name' in doc:
entry_type = "posts"
@ -78,9 +78,24 @@ def req():
url = os.path.join("/",entry_type,now.strftime("%Y/%m/%d"), str(now_ts))
file_path = os.path.join(os.environ.get('CONTENT_PREFIX'), entry_type, now.strftime("%Y/%m/%d"), str(now_ts) + ".md")
frontmatter = yaml.dump({"url":url, "type": entry_type, "date": now.isoformat(sep='T')})
content = base64.encodestring(f"---\n{frontmatter}\n---\n\n{doc['content']}".encode("utf8")).decode("utf8")
frontmatter = {
"url":url,
"type": entry_type,
"date": now.isoformat(sep='T'),
}
categories = request.form.getlist('category[]')
if len(categories) > 0:
frontmatter['categories'] = categories
frontmatter_str = yaml.dump(frontmatter)
content = base64.encodestring(f"---\n{frontmatter_str}\n---\n\n{doc['content']}".encode("utf8")).decode("utf8")
api = get_api_client()
@ -94,9 +109,9 @@ def req():
except Exception as e:
return {"error": str(e)}, 500
print(r)
# print(r)
return {"hello": "world"}
# return {"hello": "world"}
@app.route('/', methods=['GET'])