diff --git a/example.py b/example.py index 32af9cc..357b28d 100644 --- a/example.py +++ b/example.py @@ -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'])