add photos to headers
This commit is contained in:
parent
23be00ad8d
commit
fe0e9c07f9
47
example.py
47
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<img src=\"{photo_url}\" class=\"u-photo\" />"
|
||||
|
||||
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"<img src=\"{photo_url}\" class=\"u-photo\" /> \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<a href=\"{url}\"></a>"
|
||||
|
||||
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():
|
|||
<option>read</option>
|
||||
<option>post</option>
|
||||
<option>comment</option>
|
||||
<option>create draft update delete media read follow mute block create</option>
|
||||
</select>
|
||||
<button type="submit">Authorize</button>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue