update behaviour for thumbnails and post types

This commit is contained in:
James Ravenscroft 2023-07-09 15:11:31 +01:00
parent f583942894
commit 0fb2380fd9
3 changed files with 19 additions and 4 deletions

View File

@ -161,6 +161,8 @@ def process_photo_upload(created_at: datetime, file: FileStorage, suffix: str=""
else:
return None
def init_frontmatter(created_at: datetime, post_type: str, name: Optional[str]=None):
@ -187,7 +189,7 @@ def init_frontmatter(created_at: datetime, post_type: str, name: Optional[str]=N
frontmatter = {
"url": url,
"type": post_type,
"type": ENTITY_TYPE_PLURAL_MAP.get(post_type, post_type + "s"),
"date": created_at.isoformat(sep='T'),
}
@ -297,6 +299,9 @@ def process_multipart_post():
for i, photo in enumerate(photos):
photo_url = process_photo_upload(now, photo, suffix=i)
if 'thumbnail' not in frontmatter:
frontmatter['thumbnail'] = photo_url
frontmatter['photo'].append(photo_url)
docstr += f"\n\n<img src=\"{photo_url}\" class=\"u-photo\" />"
@ -307,10 +312,15 @@ def process_multipart_post():
if 'photo' in doc:
photo_objects = process_photo_url(now, doc)
else:
photo_objects = [ (process_photo_upload(now, request.files['photo']), "") ]
frontmatter['photo'] = [ {"value": photo[0], "alt": photo[1]} for photo in photo_objects]
frontmatter['thumbnail'] = photo_objects[0][0]
docstr = ""
for photo in photo_objects:
docstr += f"<img src=\"{photo[0]}\" alt=\"{photo[1]}\" class=\"u-photo\" /> \n\n {doc['content']}"
@ -386,6 +396,7 @@ def process_json_post():
frontmatter['photo'] = [ {"value": photo[0], "alt": photo[1]} for photo in photo_objects]
frontmatter['thumbnail'] = frontmatter['photo'][0]['value']
docstr = ""
for photo in photo_objects:
docstr += f"<img src=\"{photo[0]}\" alt=\"{photo[1]}\" class=\"u-photo\" /> \n\n"
@ -424,7 +435,7 @@ def req():
docstr, frontmatter, file_path = process_multipart_post()
frontmatter_str = yaml.dump(frontmatter)
content = base64.encodestring(
content = base64.encodebytes(
f"---\n{frontmatter_str}\n---\n\n{docstr}".encode("utf8")).decode("utf8")
api = get_api_client()

View File

@ -37,13 +37,13 @@ def authform():
@auth_bp.route('/authenticate')
def authenticate():
return micropub.authenticate(
request.args.get('me'), next_url=url_for('index'))
request.args.get('me'), next_url=url_for('token.indieauth_callback'))
@auth_bp.route('/authorize')
def authorize():
return micropub.authorize(
request.args.get('me'), next_url=url_for('index'),
request.args.get('me'), next_url=url_for('token.indieauth_callback'),
scope=request.args.get('scope'))

4
src/microcosm/wsgi.py Normal file
View File

@ -0,0 +1,4 @@
from . import create_app
app = create_app()