add photos to headers

This commit is contained in:
James Ravenscroft 2021-12-26 11:09:50 +00:00
parent 23be00ad8d
commit fe0e9c07f9
1 changed files with 38 additions and 9 deletions

View File

@ -192,10 +192,11 @@ def req():
if len(categories) > 0: if len(categories) > 0:
frontmatter['tags'] = categories frontmatter['tags'] = categories
frontmatter_str = yaml.dump(frontmatter)
if ('photo' in doc) or ('photo' in request.files) or ('photo[]' in request.files): if ('photo' in doc) or ('photo' in request.files) or ('photo[]' in request.files):
frontmatter['photo'] = []
if 'photo[]' in request.files: if 'photo[]' in request.files:
photos = request.files.getlist('photo[]') photos = request.files.getlist('photo[]')
@ -204,7 +205,9 @@ def req():
for i, photo in enumerate(photos): for i, photo in enumerate(photos):
photo_url = process_photo_upload(now, photo, suffix=i) 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<img src=\"{photo_url}\" class=\"u-photo\" />"
docstr += f"\n\n {doc['content']}" docstr += f"\n\n {doc['content']}"
@ -215,14 +218,23 @@ def req():
else: else:
photo_url = process_photo_upload(now, request.files['photo']) photo_url = process_photo_upload(now, request.files['photo'])
frontmatter['photo'] = [photo_url]
docstr = f"![image]({photo_url}) \n\n {doc['content']}"
docstr = f"<img src=\"{photo_url}\" class=\"u-photo\" /> \n\n {doc['content']}"
else: else:
docstr = doc['content'] docstr = doc['content']
if 'mp-syndicate-to' in doc:
for url in doc['mp-syndicate-to'].split(","):
docstr += f"\n<a href=\"{url}\"></a>"
frontmatter_str = yaml.dump(frontmatter)
content = base64.encodestring( content = base64.encodestring(
f"---\n{frontmatter_str}\n---\n\n{docstr}".encode("utf8")).decode("utf8") f"---\n{frontmatter_str}\n---\n\n{docstr}".encode("utf8")).decode("utf8")
api = get_api_client() api = get_api_client()
body = giteapy.CreateFileOptions(content=content) body = giteapy.CreateFileOptions(content=content)
@ -250,16 +262,32 @@ def parse_categories():
return {"categories": [tag.text for tag in tags] } 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(): def generate_config_json():
return { return {
"media-endpoint": request.base_url + "media", "media-endpoint": request.base_url + "media",
"syndicate-to": [ "syndicate-to": get_syndication_targets(),
{
"uid": "mastodon",
"name": "Mastodon"
}
],
"post-types": [ "post-types": [
{ {
"type": "note", "type": "note",
@ -312,6 +340,7 @@ def authform():
<option>read</option> <option>read</option>
<option>post</option> <option>post</option>
<option>comment</option> <option>comment</option>
<option>create draft update delete media read follow mute block create</option>
</select> </select>
<button type="submit">Authorize</button> <button type="submit">Authorize</button>
</form> </form>