implement alt text for photos
This commit is contained in:
parent
55265d86a1
commit
0882d5ce24
|
@ -44,9 +44,10 @@ def create_app():
|
||||||
from .indieauth import micropub, auth_bp
|
from .indieauth import micropub, auth_bp
|
||||||
from .webmentions import webhook_bp
|
from .webmentions import webhook_bp
|
||||||
|
|
||||||
|
|
||||||
print(app.config)
|
print(app.config)
|
||||||
|
|
||||||
micropub.init_app(app, app.config.get('INDIEAUTH_CLIENT_ID', 'test.com'))
|
micropub.init_app(app, os.environ.get('INDIEAUTH_CLIENT_ID', 'test.com'))
|
||||||
|
|
||||||
app.register_blueprint(auth_bp)
|
app.register_blueprint(auth_bp)
|
||||||
app.register_blueprint(core_bp)
|
app.register_blueprint(core_bp)
|
||||||
|
@ -96,20 +97,25 @@ def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: s
|
||||||
|
|
||||||
for i, photo in enumerate(doc['photo']):
|
for i, photo in enumerate(doc['photo']):
|
||||||
|
|
||||||
|
if(isinstance(photo, str)):
|
||||||
|
photo = {"value": photo, "alt": ""}
|
||||||
|
|
||||||
|
|
||||||
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
||||||
# download the photo
|
# download the photo
|
||||||
|
|
||||||
r = requests.get(photo)
|
r = requests.get(photo['value'])
|
||||||
|
|
||||||
ext = os.path.splitext(photo)[1]
|
ext = os.path.splitext(photo['value'])[1]
|
||||||
|
|
||||||
# generate local filename
|
# generate local filename
|
||||||
filename = os.path.join(os.environ.get(
|
filename = os.path.join(os.environ.get(
|
||||||
'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}")
|
'MICROPUB_MEDIA_PATH'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}")
|
||||||
|
|
||||||
photo_url = os.path.join(os.environ.get(
|
photo_url = os.path.join(os.environ.get(
|
||||||
'MICROPUB_MEDIA_URL_PREFIX'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}")
|
'MICROPUB_MEDIA_URL_PREFIX'), created_at.strftime("%Y/%m/%d"), str(now_ts) + f"{now_ts}_{suffix}_{i}_{ext}")
|
||||||
|
|
||||||
photo_urls.append(photo_url)
|
photo_urls.append((photo_url, photo['alt']))
|
||||||
|
|
||||||
# make directory if needed
|
# make directory if needed
|
||||||
if not os.path.exists(os.path.dirname(filename)):
|
if not os.path.exists(os.path.dirname(filename)):
|
||||||
|
@ -120,7 +126,7 @@ def process_photo_url(created_at: datetime, doc: Dict[str, List[str]], suffix: s
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
photo_urls.append(photo)
|
photo_urls.append((photo['value'], photo['alt']))
|
||||||
|
|
||||||
|
|
||||||
return photo_urls
|
return photo_urls
|
||||||
|
@ -285,14 +291,14 @@ def process_multipart_post():
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if 'photo' in doc:
|
if 'photo' in doc:
|
||||||
photo_urls = process_photo_url(now, doc)
|
photo_objects = process_photo_url(now, doc)
|
||||||
else:
|
else:
|
||||||
photo_urls = [process_photo_upload(now, request.files['photo'])]
|
photo_objects = [ (process_photo_upload(now, request.files['photo']), "") ]
|
||||||
|
|
||||||
frontmatter['photo'] = photo_urls
|
frontmatter['photo'] = [ {"value": photo[0], "alt": photo[1]} for photo in photo_objects]
|
||||||
docstr = ""
|
docstr = ""
|
||||||
for photo in photo_urls:
|
for photo in photo_objects:
|
||||||
docstr += f"<img src=\"{photo}\" class=\"u-photo\" /> \n\n {doc['content']}"
|
docstr += f"<img src=\"{photo[0]}\" alt=\"{photo[1]}\" class=\"u-photo\" /> \n\n {doc['content']}"
|
||||||
else:
|
else:
|
||||||
docstr = doc.get('content','') if 'content' in doc else ""
|
docstr = doc.get('content','') if 'content' in doc else ""
|
||||||
|
|
||||||
|
@ -342,12 +348,14 @@ def process_json_post():
|
||||||
|
|
||||||
if 'photo' in props:
|
if 'photo' in props:
|
||||||
|
|
||||||
photo_urls = process_photo_url(now, props)
|
photo_objects = process_photo_url(now, props)
|
||||||
|
|
||||||
frontmatter['photo'] = photo_urls
|
|
||||||
|
|
||||||
for photo in photo_urls:
|
frontmatter['photo'] = [ {"value": photo[0], "alt": photo[1]} for photo in photo_objects]
|
||||||
docstr += f"\n\n<img src=\"{photo}\" class=\"u-photo\" />"
|
docstr = ""
|
||||||
|
for photo in photo_objects:
|
||||||
|
docstr += f"<img src=\"{photo[0]}\" alt=\"{photo[1]}\" class=\"u-photo\" /> \n\n"
|
||||||
|
|
||||||
|
|
||||||
for content in props.get('content', []):
|
for content in props.get('content', []):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue