add: profile and community opengraph tags

This commit is contained in:
trisua 2025-04-09 00:10:58 -04:00
parent 0ef6d0ddca
commit f49cc80886
6 changed files with 86 additions and 8 deletions

View file

@ -1,5 +1,35 @@
{% extends "root.html" %} {% block head %}
<title>{{ community.context.display_name }} - {{ config.name }}</title>
<meta name="og:title" content="{{ community.title }}" />
<meta
name="description"
content='View the "{{ community.title }}" community on {{ config.name }}!'
/>
<meta
name="og:description"
content='View the "{{ community.title }}" community on {{ config.name }}!'
/>
<meta property="og:type" content="profile" />
<meta property="profile:username" content="{{ community.title }}" />
<meta
name="og:image"
content="{{ config.host|safe }}/api/v1/communities/{{ community.id }}/avatar"
/>
<meta
name="twitter:image"
content="{{ config.host|safe }}/api/v1/communities/{{ community.id }}/avatar"
/>
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="{{ community.title }}" />
<meta
name="twitter:description"
content='View the "{{ community.title }}" community on {{ config.name }}!'
/>
{% endblock %} {% block body %} {{ macros::nav() }}
<article>
<div class="content_container flex flex-col gap-4">

View file

@ -1,5 +1,35 @@
{% extends "root.html" %} {% block head %}
<title>{{ profile.username }} - {{ config.name }}</title>
<meta name="og:title" content="{{ profile.username }}" />
<meta
name="description"
content="View @{{ profile.username }}'s profile on {{ config.name }}!"
/>
<meta
name="og:description"
content="View @{{ profile.username }}'s profile on {{ config.name }}!"
/>
<meta property="og:type" content="profile" />
<meta property="profile:username" content="{{ profile.username }}" />
<meta
name="og:image"
content="{{ config.host|safe }}/api/v1/auth/user/{{ profile.username }}/avatar?selector_type=username"
/>
<meta
name="twitter:image"
content="{{ config.host|safe }}/api/v1/auth/user/{{ profile.username }}/avatar?selector_type=username"
/>
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="{{ profile.username }}" />
<meta
name="twitter:description"
content="View @{{ profile.username }}'s profile on {{ config.name }}!"
/>
{% endblock %} {% block body %} {{ macros::nav() }}
<article>
<div class="content_container flex flex-col gap-4">

View file

@ -52,8 +52,20 @@ pub async fn avatar_request(
let data = &(data.read().await).0;
let user = match if req.selector_type == AvatarSelectorType::Id {
data.get_user_by_id(selector.parse::<usize>().unwrap())
.await
data.get_user_by_id(match selector.parse::<usize>() {
Ok(d) => d,
Err(_) => {
return (
[("Content-Type", "image/svg+xml")],
Body::from(read_image(PathBufD::current().extend(&[
data.0.dirs.media.as_str(),
"images",
"default-avatar.svg",
]))),
);
}
})
.await
} else {
data.get_user_by_username(&selector).await
} {