From fe0e9c07f9a574a4892bf49b39fda3cb2b4c32ab Mon Sep 17 00:00:00 2001 From: James Ravenscroft Date: Sun, 26 Dec 2021 11:09:50 +0000 Subject: [PATCH] add photos to headers --- example.py | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/example.py b/example.py index 22977be..b7ca057 100644 --- a/example.py +++ b/example.py @@ -192,10 +192,11 @@ def req(): if len(categories) > 0: frontmatter['tags'] = categories - frontmatter_str = yaml.dump(frontmatter) if ('photo' in doc) or ('photo' in request.files) or ('photo[]' in request.files): + frontmatter['photo'] = [] + if 'photo[]' in request.files: photos = request.files.getlist('photo[]') @@ -204,7 +205,9 @@ def req(): for i, photo in enumerate(photos): photo_url = process_photo_upload(now, photo, suffix=i) - docstr += f"\n\n![image]({photo_url})" + frontmatter.photo.append(photo_url) + + docstr += f"\n\n" docstr += f"\n\n {doc['content']}" @@ -215,14 +218,23 @@ def req(): else: photo_url = process_photo_upload(now, request.files['photo']) + frontmatter['photo'] = [photo_url] - docstr = f"![image]({photo_url}) \n\n {doc['content']}" + + docstr = f" \n\n {doc['content']}" else: docstr = doc['content'] + if 'mp-syndicate-to' in doc: + for url in doc['mp-syndicate-to'].split(","): + docstr += f"\n" + + frontmatter_str = yaml.dump(frontmatter) content = base64.encodestring( f"---\n{frontmatter_str}\n---\n\n{docstr}".encode("utf8")).decode("utf8") + + api = get_api_client() body = giteapy.CreateFileOptions(content=content) @@ -250,16 +262,32 @@ def parse_categories(): return {"categories": [tag.text for tag in tags] } +def get_syndication_targets(): + + targets = os.environ.get("SYNDICATION_TARGETS", "").split(",") + + defs = [] + for target in targets: + + if os.environ.get(f"SYNDICATION_TARGET_{target}_URL") is None: + print(f"No url for SYNDICATION_TARGET_{target}_URL") + continue + + target_def = { + "uid": os.environ.get(f"SYNDICATION_TARGET_{target}_URL", target), + "name": os.environ.get(f"SYNDICATION_TARGET_{target}_NAME", target), + } + defs.append(target_def) + + return defs + + + def generate_config_json(): return { "media-endpoint": request.base_url + "media", - "syndicate-to": [ - { - "uid": "mastodon", - "name": "Mastodon" - } - ], + "syndicate-to": get_syndication_targets(), "post-types": [ { "type": "note", @@ -312,6 +340,7 @@ def authform(): +