feature: alt-text for photos
This commit is contained in:
@@ -206,18 +206,19 @@ class FiftyOhmHtmlRenderer(HtmlRenderer):
|
|||||||
return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text)
|
return self.render_picture_helper(token.id, token.ref, token.text, token.number, alt_text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_photo_helper(id, ref, text, number):
|
def render_photo_helper(id, ref, text, number, alt_text):
|
||||||
return f"""
|
return f"""
|
||||||
<figure class="photo" id="ref_{ref}" name="{ref}">
|
<figure class="photo" id="ref_{ref}" name="{ref}">
|
||||||
<img src="photos/{id}.jpg">
|
<img src="photos/{id}.jpg" alt="{alt_text}">
|
||||||
<figcaption>Abbildung {number}: {text}</figcaption>
|
<figcaption>Abbildung {number}: {text}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def render_photo(self, token):
|
def render_photo(self, token):
|
||||||
|
alt_text = "Alt-Text noch nicht verfügbar"
|
||||||
if self.photo_handler is not None:
|
if self.photo_handler is not None:
|
||||||
self.photo_handler(token.id)
|
alt_text = self.photo_handler(token.id) or alt_text
|
||||||
return self.render_photo_helper(token.id, token.ref, token.text, token.number)
|
return self.render_photo_helper(token.id, token.ref, token.text, token.number, alt_text)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_cell_helper(cell, alignment, type):
|
def render_cell_helper(cell, alignment, type):
|
||||||
|
|||||||
@@ -144,6 +144,8 @@ class Build:
|
|||||||
file = f"{id}.jpg"
|
file = f"{id}.jpg"
|
||||||
try:
|
try:
|
||||||
shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file)
|
shutil.copyfile(self.config.p_data_photos / file, self.config.p_build_photos / file)
|
||||||
|
if (self.config.p_data_photos / f"{id}.txt").exists():
|
||||||
|
return (self.config.p_data_photos / f"{id}.txt").read_text()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
tqdm.write(f"\033[31mPhoto #{id} not found\033[0m")
|
tqdm.write(f"\033[31mPhoto #{id} not found\033[0m")
|
||||||
|
|
||||||
|
|||||||
@@ -92,10 +92,19 @@ class Download:
|
|||||||
photos = self.api.get("items/Fotos", params={"limit": -1})
|
photos = self.api.get("items/Fotos", params={"limit": -1})
|
||||||
|
|
||||||
for photo in tqdm(photos, desc="Downloading photos"):
|
for photo in tqdm(photos, desc="Downloading photos"):
|
||||||
|
# Save Photo to file
|
||||||
data = self.api.get_file("assets/" + photo["photo"])
|
data = self.api.get_file("assets/" + photo["photo"])
|
||||||
with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file:
|
with (self.config.p_data_photos / f"{photo['id']}.jpg").open("wb") as file:
|
||||||
file.write(data)
|
file.write(data)
|
||||||
|
|
||||||
|
# Save Alt-Text to file
|
||||||
|
prefix = ""
|
||||||
|
if photo["alt_text"] is not None:
|
||||||
|
if photo["alt_text_reviewed"] is None:
|
||||||
|
prefix = "Der folgende Alt-Text wurde noch nicht geprüft: "
|
||||||
|
with (self.config.p_data_photos / f"{photo['id']}.txt").open("w") as file:
|
||||||
|
file.write(prefix + photo["alt_text"])
|
||||||
|
|
||||||
def download_pictures(self):
|
def download_pictures(self):
|
||||||
self.config.p_data_pictures.mkdir(parents=True, exist_ok=True)
|
self.config.p_data_pictures.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -9,7 +9,9 @@ from test.util import paragraph
|
|||||||
@pytest.mark.html
|
@pytest.mark.html
|
||||||
def test_photo_html():
|
def test_photo_html():
|
||||||
assertions = {
|
assertions = {
|
||||||
"[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper("123", "abc", "Text", "TODO"),
|
"[photo:123:abc:Text]": FiftyOhmHtmlRenderer.render_photo_helper(
|
||||||
|
"123", "abc", "Text", "TODO", "Alt-Text noch nicht verfügbar"
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
for assertion in assertions:
|
for assertion in assertions:
|
||||||
|
|||||||
Reference in New Issue
Block a user