add support for various reference type posts e.g. likes, bookmarks etc

This commit is contained in:
James Ravenscroft 2021-12-24 17:03:24 +00:00
parent dc2268e825
commit 23be00ad8d
1 changed files with 30 additions and 5 deletions

View File

@ -27,6 +27,14 @@ app.config['SECRET_KEY'] = 'my super secret key'
micropub = MicropubClient(app, client_id='https://brainsteam.co.uk') micropub = MicropubClient(app, client_id='https://brainsteam.co.uk')
ENTITY_TYPE_PLURAL_MAP = {
"post": "posts",
"note": "notes",
"reply": "replies",
"bookmark": "bookmarks"
}
def authed_endpoint(f): def authed_endpoint(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
@ -129,7 +137,22 @@ def req():
doc = request.form.to_dict(flat=True) doc = request.form.to_dict(flat=True)
if 'name' in doc:
if 'in-reply-to' in doc:
entry_type = "reply"
elif 'bookmark-of' in doc:
entry_type = "bookmark"
elif 'repost-of' in doc:
entry_type = "repost"
elif 'like-of' in doc:
entry_type = "like"
# elif ('photo' in doc) or ('photo' in request.files) or ('photo[]' in request.files):
# entry_type = "photo"
elif 'name' in doc:
entry_type = "post" entry_type = "post"
else: else:
entry_type = "note" entry_type = "note"
@ -137,7 +160,7 @@ def req():
now = datetime.now() now = datetime.now()
now_ts = int(time.mktime(now.timetuple())) now_ts = int(time.mktime(now.timetuple()))
url = os.path.join("/", entry_type + "s", url = os.path.join("/", ENTITY_TYPE_PLURAL_MAP.get(entry_type, entry_type + "s"),
now.strftime("%Y/%m/%d"), str(now_ts)) now.strftime("%Y/%m/%d"), str(now_ts))
if 'name' in doc: if 'name' in doc:
@ -146,7 +169,7 @@ def req():
slug = str(now_ts) slug = str(now_ts)
file_path = os.path.join(os.environ.get( file_path = os.path.join(os.environ.get(
'CONTENT_PREFIX'), entry_type + "s", now.strftime("%Y/%m/%d"), slug + ".md") 'CONTENT_PREFIX'), ENTITY_TYPE_PLURAL_MAP.get(entry_type, entry_type + "s"), now.strftime("%Y/%m/%d"), slug + ".md")
frontmatter = { frontmatter = {
"url": url, "url": url,
@ -154,6 +177,10 @@ def req():
"date": now.isoformat(sep='T'), "date": now.isoformat(sep='T'),
} }
for key in ['bookmark-of', 'in-reply-to', 'repost-of', 'like-of']:
if key in doc:
frontmatter[key] = doc[key]
if 'category' in doc: if 'category' in doc:
categories = [doc['category']] categories = [doc['category']]
else: else:
@ -225,8 +252,6 @@ def parse_categories():
def generate_config_json(): def generate_config_json():
return { return {
"media-endpoint": request.base_url + "media", "media-endpoint": request.base_url + "media",
"syndicate-to": [ "syndicate-to": [