Improve custom emoji support

main
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: # Next:
# - fix stream (only content from follows + mention, and dedup shares) # - fix stream (only content from follows + mention, and dedup shares)
# - custom emoji in data/
# - allow to undo follow requests # - allow to undo follow requests
# - indieauth tweaks # - indieauth tweaks
# - API for posting notes # - API for posting notes
@ -171,6 +170,11 @@ class CustomMiddleware:
app = FastAPI(docs_url=None, redoc_url=None) 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.mount("/static", StaticFiles(directory="app/static"), name="static")
app.include_router(admin.router, prefix="/admin") app.include_router(admin.router, prefix="/admin")
app.include_router(admin.unauthenticated_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="actor-box h-card p-author">
<div class="icon-box"> <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> </div>
<a href="{{ actor.url }}" class="u-url" style=""> <a href="{{ actor.url }}" class="u-url" style="">
<div><strong>{{ actor.display_name | clean_html(actor) | safe }}</strong></div> <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: def _load_emojis(root_dir: Path, base_url: str) -> None:
if EMOJIS: if EMOJIS:
return 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] mt = mimetypes.guess_type(emoji.name)[0]
if mt and mt.startswith("image/"): if mt and mt.startswith("image/"):
name = emoji.name.split(".")[0] name = emoji.name.split(".")[0]
@ -27,7 +31,7 @@ def _load_emojis(root_dir: Path, base_url: str) -> None:
"icon": { "icon": {
"mediaType": mt, "mediaType": mt,
"type": "Image", "type": "Image",
"url": f"{base_url}/static/emoji/{emoji.name}", "url": f"{base_url}/static/{path}/{emoji.name}",
}, },
} }
EMOJIS[emoji.name] = ap_emoji EMOJIS[emoji.name] = ap_emoji

2
data/custom_emoji/.gitignore vendored 100644
View File

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