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 .webmentions import webhook_bp
|
||||
|
||||
|
||||
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(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']):
|
||||
|
||||
if(isinstance(photo, str)):
|
||||
photo = {"value": photo, "alt": ""}
|
||||
|
||||
|
||||
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
||||
# 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
|
||||
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}")
|
||||
|
||||
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}")
|
||||
|
||||
photo_urls.append(photo_url)
|
||||
photo_urls.append((photo_url, photo['alt']))
|
||||
|
||||
# make directory if needed
|
||||
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:
|
||||
photo_urls.append(photo)
|
||||
photo_urls.append((photo['value'], photo['alt']))
|
||||
|
||||
|
||||
return photo_urls
|
||||
|
@ -285,14 +291,14 @@ def process_multipart_post():
|
|||
else:
|
||||
|
||||
if 'photo' in doc:
|
||||
photo_urls = process_photo_url(now, doc)
|
||||
photo_objects = process_photo_url(now, doc)
|
||||
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 = ""
|
||||
for photo in photo_urls:
|
||||
docstr += f"<img src=\"{photo}\" class=\"u-photo\" /> \n\n {doc['content']}"
|
||||
for photo in photo_objects:
|
||||
docstr += f"<img src=\"{photo[0]}\" alt=\"{photo[1]}\" class=\"u-photo\" /> \n\n {doc['content']}"
|
||||
else:
|
||||
docstr = doc.get('content','') if 'content' in doc else ""
|
||||
|
||||
|
@ -342,12 +348,14 @@ def process_json_post():
|
|||
|
||||
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:
|
||||
docstr += f"\n\n<img src=\"{photo}\" class=\"u-photo\" />"
|
||||
frontmatter['photo'] = [ {"value": photo[0], "alt": photo[1]} for photo in photo_objects]
|
||||
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', []):
|
||||
|
||||
|
|
Loading…
Reference in New Issue