add support for categories
This commit is contained in:
parent
107f16757a
commit
efb4019c82
25
example.py
25
example.py
|
@ -64,7 +64,7 @@ def get_api_client():
|
||||||
@authed_endpoint
|
@authed_endpoint
|
||||||
def req():
|
def req():
|
||||||
|
|
||||||
doc = request.form.to_dict()
|
doc = request.form.to_dict(flat=True)
|
||||||
|
|
||||||
if 'name' in doc:
|
if 'name' in doc:
|
||||||
entry_type = "posts"
|
entry_type = "posts"
|
||||||
|
@ -78,9 +78,24 @@ def req():
|
||||||
url = os.path.join("/",entry_type,now.strftime("%Y/%m/%d"), str(now_ts))
|
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")
|
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()
|
api = get_api_client()
|
||||||
|
|
||||||
|
@ -94,9 +109,9 @@ def req():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"error": str(e)}, 500
|
return {"error": str(e)}, 500
|
||||||
|
|
||||||
print(r)
|
# print(r)
|
||||||
|
|
||||||
return {"hello": "world"}
|
# return {"hello": "world"}
|
||||||
|
|
||||||
|
|
||||||
@app.route('/', methods=['GET'])
|
@app.route('/', methods=['GET'])
|
||||||
|
|
Loading…
Reference in New Issue