Improve custom emoji support

This commit is contained in:
Thomas Sileo 2022-07-16 07:48:24 +02:00
parent 883f87b6e4
commit 1197f132ce
4 changed files with 29 additions and 19 deletions

View file

@ -76,7 +76,6 @@ _RESIZED_CACHE: MutableMapping[tuple[str, int], tuple[bytes, str, Any]] = LFUCac
#
# Next:
# - fix stream (only content from follows + mention, and dedup shares)
# - custom emoji in data/
# - allow to undo follow requests
# - indieauth tweaks
# - API for posting notes
@ -171,6 +170,11 @@ class CustomMiddleware:
app = FastAPI(docs_url=None, redoc_url=None)
app.mount(
"/static/custom_emoji",
StaticFiles(directory="data/custom_emoji"),
name="static_custom_emoji",
)
app.mount("/static", StaticFiles(directory="app/static"), name="static")
app.include_router(admin.router, prefix="/admin")
app.include_router(admin.unauthenticated_router, prefix="/admin")

View file

@ -157,7 +157,7 @@
<div class="actor-box h-card p-author">
<div class="icon-box">
<img src="{{ actor.resized_icon_url }}" class="actor-icon u-photo">
<img src="{{ actor.resized_icon_url }}" alt="{{ actor.display_name }}'s avatar" class="actor-icon u-photo">
</div>
<a href="{{ actor.url }}" class="u-url" style="">
<div><strong>{{ actor.display_name | clean_html(actor) | safe }}</strong></div>

View file

@ -15,7 +15,11 @@ EMOJIS_BY_NAME: dict[str, "RawObject"] = {}
def _load_emojis(root_dir: Path, base_url: str) -> None:
if EMOJIS:
return
for emoji in (root_dir / "app" / "static" / "emoji").iterdir():
for dir_name, path in (
(root_dir / "app" / "static" / "emoji", "emoji"),
(root_dir / "data" / "custom_emoji", "custom_emoji"),
):
for emoji in dir_name.iterdir():
mt = mimetypes.guess_type(emoji.name)[0]
if mt and mt.startswith("image/"):
name = emoji.name.split(".")[0]
@ -27,7 +31,7 @@ def _load_emojis(root_dir: Path, base_url: str) -> None:
"icon": {
"mediaType": mt,
"type": "Image",
"url": f"{base_url}/static/emoji/{emoji.name}",
"url": f"{base_url}/static/{path}/{emoji.name}",
},
}
EMOJIS[emoji.name] = ap_emoji

2
data/custom_emoji/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*
!.gitignore