pronounscc/frontend/src/routes/@[username]/[memberName]/+page.svelte

137 lines
4.4 KiB
Svelte
Raw Normal View History

2023-03-11 16:52:48 +01:00
<script lang="ts">
import { marked } from "marked";
import sanitizeHtml from "sanitize-html";
import FieldCard from "$lib/components/FieldCard.svelte";
import type { PageData } from "./$types";
import StatusIcon from "$lib/components/StatusIcon.svelte";
import PronounLink from "$lib/components/PronounLink.svelte";
import FallbackImage from "$lib/components/FallbackImage.svelte";
2023-03-14 17:06:35 +01:00
import { Alert, Button, Icon } from "sveltestrap";
2023-03-14 03:01:26 +01:00
import { memberAvatars, pronounDisplay, WordStatus } from "$lib/api/entities";
import { PUBLIC_BASE_URL } from "$env/static/public";
2023-03-14 17:06:35 +01:00
import { userStore } from "$lib/store";
2023-03-11 16:52:48 +01:00
export let data: PageData;
let bio: string | null;
$: bio = data.bio ? sanitizeHtml(marked.parse(data.bio, { breaks: true })) : null;
2023-03-14 03:01:26 +01:00
const favNames = data.names.filter((entry) => entry.status === WordStatus.Favourite);
const favPronouns = data.pronouns.filter((entry) => entry.status === WordStatus.Favourite);
2023-03-11 16:52:48 +01:00
</script>
<div class="container">
2023-03-14 17:06:35 +01:00
{#if $userStore && $userStore.id === data.user.id}
<Alert color="secondary" fade={false}>
You are currently viewing the <strong>public</strong> profile of {data.display_name ??
data.name}.
2023-03-14 17:06:35 +01:00
<br /><a href="/edit/member/{data.id}">Edit profile</a>
</Alert>
{/if}
<div class="m-3">
2023-03-11 16:52:48 +01:00
<Button color="secondary" href="/@{data.user.name}">
<Icon name="arrow-left" /> Back to {data.user.display_name ?? data.user.name}
</Button>
</div>
<div class="grid">
<div class="row">
<div class="col-md-4 text-center">
<FallbackImage width={200} urls={memberAvatars(data)} alt="Avatar for @{data.name}" />
2023-03-11 16:52:48 +01:00
</div>
<div class="col-md">
2023-03-11 16:52:48 +01:00
<h2>{data.display_name ?? data.name}</h2>
<h5 class="text-body-secondary">{data.name} (@{data.user.name})</h5>
{#if bio}
<hr />
2023-03-11 16:52:48 +01:00
<p>{@html bio}</p>
{/if}
</div>
{#if data.links.length > 0}
<div class="col-md d-flex align-items-center">
<ul class="list-unstyled">
2023-03-11 16:52:48 +01:00
{#each data.links as link}
<li><Icon name="globe" /> <a href={link}>{link}</a></li>
2023-03-11 16:52:48 +01:00
{/each}
</ul>
</div>
{/if}
2023-03-11 16:52:48 +01:00
</div>
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3">
{#if data.names.length > 0}
2023-03-11 16:52:48 +01:00
<div class="col-md">
<h3>Names</h3>
<ul class="list-unstyled fs-5">
2023-03-11 16:52:48 +01:00
{#each data.names as name}
<li><StatusIcon status={name.status} /> {name.value}</li>
{/each}
</ul>
</div>
{/if}
{#if data.pronouns.length > 0}
2023-03-11 16:52:48 +01:00
<div class="col-md">
<h3>Pronouns</h3>
<ul class="list-unstyled fs-5">
2023-03-11 16:52:48 +01:00
{#each data.pronouns as pronouns}
<li>
<StatusIcon status={pronouns.status} />
<PronounLink {pronouns} />
</li>
{/each}
</ul>
</div>
{/if}
{#each data.fields as field}
<div class="col">
<FieldCard {field} />
</div>
{/each}
</div>
</div>
2023-03-11 16:52:48 +01:00
</div>
<svelte:head>
<title>{data.display_name ?? data.name} - @{data.user.name} - pronouns.cc</title>
<meta
property="og:title"
content={data.display_name
? `${data.display_name} (${data.name})`
: `${data.name} (@${data.user.name})`}
/>
<meta property="og:url" content="{PUBLIC_BASE_URL}/@{data.user.name}/{data.name}" />
{#if data.avatar}
<meta property="og:image" content={memberAvatars(data)[0]} />
{/if}
{#if favNames.length !== 0 && favPronouns.length !== 0}
<meta
property="og:description"
2023-03-14 22:26:21 +01:00
content="{data.display_name ?? data.name} goes by {favNames
.map((x) => x.value)
.join(', ')} and uses {favPronouns.map((x) => pronounDisplay(x)).join(', ')} pronouns."
/>
{:else if favNames.length !== 0}
<meta
property="og:description"
2023-03-14 22:26:21 +01:00
content="{data.display_name ?? data.name} goes by {favNames.map((x) => x.value).join(', ')}."
/>
{:else if favPronouns.length !== 0}
<meta
property="og:description"
2023-03-14 22:26:21 +01:00
content="{data.display_name ?? data.name} uses {favPronouns
.map((x) => pronounDisplay(x))
.join(', ')} pronouns."
/>
{:else if data.bio && data.bio !== ""}
<meta
property="og:description"
2023-03-14 22:26:21 +01:00
content="{data.bio.slice(0, 500)}{data.bio.length > 500 ? '…' : ''}"
/>
{:else}
<meta property="og:description" content="{data.name} (@{data.user.name}) on pronouns.cc" />
{/if}
</svelte:head>