forked from retoor/devplacepy
feat: add alt text extraction from URLs for images and improve CSS variable usage for progress bars
Add `_alt_from_url` helper in Python rendering and `altFromUrl` in JS ContentRenderer to generate descriptive alt attributes from image filenames, replacing empty alt strings. Update image embed templates and Avatar component to use derived alt text. Migrate inline `style.width` assignments to CSS custom properties (`--poll-pct`, `--hud-xp`, `--quest-pct`, `--bar-pct`, `--quota-pct`) across PollManager, GameFarm, and profile/quest CSS for better maintainability. Introduce new admin, docs, projects, services, and base CSS utility classes. Add "Code Farm" docs page entry.
This commit is contained in:
@@ -6,6 +6,7 @@ import re
|
||||
from functools import lru_cache
|
||||
from html.parser import HTMLParser
|
||||
from pathlib import Path
|
||||
from urllib.parse import unquote, urlparse
|
||||
|
||||
import emoji
|
||||
import mistune
|
||||
@@ -110,6 +111,11 @@ def _replace_shortcodes(text: str) -> str:
|
||||
)
|
||||
|
||||
|
||||
def _alt_from_url(url: str) -> str:
|
||||
name = Path(unquote(urlparse(url).path)).stem.replace("-", " ").replace("_", " ").strip()
|
||||
return name if name else "Embedded image"
|
||||
|
||||
|
||||
def _embed_url(url: str) -> str:
|
||||
youtube = _YOUTUBE_RE.search(url)
|
||||
if youtube:
|
||||
@@ -122,7 +128,8 @@ def _embed_url(url: str) -> str:
|
||||
)
|
||||
escaped = html.escape(url, quote=True)
|
||||
if _IMAGE_RE.search(url):
|
||||
return f'<img src="{escaped}" alt="" loading="lazy" data-lightbox>'
|
||||
alt = html.escape(_alt_from_url(url), quote=True)
|
||||
return f'<img src="{escaped}" alt="{alt}" loading="lazy" data-lightbox>'
|
||||
if _VIDEO_RE.search(url):
|
||||
return f'<video src="{escaped}" controls preload="metadata"></video>'
|
||||
if _AUDIO_RE.search(url):
|
||||
|
||||
Reference in New Issue
Block a user