Add description exports and collapse characters from same user
This commit is contained in:
parent
2990644f87
commit
d4a9dc9dbc
78 changed files with 693 additions and 247 deletions
|
|
@ -1,9 +1,10 @@
|
|||
---
|
||||
import { type Lang, type User } from "../content/config";
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type Lang } from "../content/config";
|
||||
import UserComponent from "./UserComponent.astro";
|
||||
|
||||
type Props = {
|
||||
authors: User | User[];
|
||||
authors: CollectionEntry<"users"> | CollectionEntry<"users">[];
|
||||
lang: Lang;
|
||||
};
|
||||
|
||||
|
|
@ -20,18 +21,19 @@ const authorsArray = [authors].flat();
|
|||
by{" "}
|
||||
{authorsArray.slice(0, authorsArray.length - 1).map((author) => (
|
||||
<Fragment>
|
||||
<UserComponent user={author} />,
|
||||
<UserComponent lang="eng" user={author} />,
|
||||
</Fragment>
|
||||
))}
|
||||
and <UserComponent user={authorsArray[authorsArray.length - 1]} />
|
||||
and <UserComponent lang="eng" user={authorsArray[authorsArray.length - 1]} />
|
||||
</span>
|
||||
) : authorsArray.length > 1 ? (
|
||||
<span>
|
||||
by <UserComponent user={authorsArray[0]} /> and <UserComponent user={authorsArray[1]} />
|
||||
by <UserComponent lang="eng" user={authorsArray[0]} /> and{" "}
|
||||
<UserComponent lang="eng" user={authorsArray[1]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
by <UserComponent user={authorsArray[0]} />
|
||||
by <UserComponent lang="eng" user={authorsArray[0]} />
|
||||
</span>
|
||||
))}
|
||||
{lang === "tok" &&
|
||||
|
|
@ -40,15 +42,15 @@ const authorsArray = [authors].flat();
|
|||
lipu ni li tan ni:{" "}
|
||||
{authorsArray.slice(0, authorsArray.length - 1).map((author) => (
|
||||
<Fragment>
|
||||
<UserComponent user={author} />
|
||||
<UserComponent lang="tok" user={author} />
|
||||
{" en "}
|
||||
</Fragment>
|
||||
))}
|
||||
<UserComponent user={authorsArray[authorsArray.length - 1]} />
|
||||
<UserComponent lang="tok" user={authorsArray[authorsArray.length - 1]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
lipu ni li tan <UserComponent user={authorsArray[0]} />
|
||||
lipu ni li tan <UserComponent lang="tok" user={authorsArray[0]} />
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
|
|
|
|||
|
|
@ -1,27 +1,67 @@
|
|||
---
|
||||
import { type Lang, type User } from "../content/config";
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type Lang } from "../content/config";
|
||||
import UserComponent from "./UserComponent.astro";
|
||||
|
||||
type Props = {
|
||||
copyrightedCharacters?: Record<string, User>;
|
||||
copyrightedCharacters?: Record<string, CollectionEntry<"users">>;
|
||||
lang: Lang;
|
||||
};
|
||||
|
||||
const { copyrightedCharacters, lang } = Astro.props;
|
||||
if (copyrightedCharacters && "" in copyrightedCharacters && Object.keys(copyrightedCharacters).length > 1) {
|
||||
throw new Error("copyrightedCharacter cannot use empty key (catch-all) with other keys");
|
||||
}
|
||||
const charactersPerUser =
|
||||
copyrightedCharacters &&
|
||||
Object.keys(copyrightedCharacters).reduce(
|
||||
(acc, character) => {
|
||||
const key = copyrightedCharacters[character].id;
|
||||
if (!(key in acc)) {
|
||||
acc[key] = [];
|
||||
}
|
||||
acc[key].push(character);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<
|
||||
CollectionEntry<"users">["id"],
|
||||
(typeof copyrightedCharacters extends Record<infer K, any> ? K : never)[]
|
||||
>,
|
||||
);
|
||||
---
|
||||
|
||||
{
|
||||
copyrightedCharacters ? (
|
||||
charactersPerUser ? (
|
||||
<section id="copyrighted-characters">
|
||||
{lang === "eng" && (
|
||||
{lang === "eng" ? (
|
||||
<ul>
|
||||
{Object.entries(copyrightedCharacters).map(([character, user]) => (
|
||||
{Object.values(charactersPerUser).map((characterList) => (
|
||||
<li>
|
||||
{character} is © <UserComponent user={user} />
|
||||
{characterList[0] === "" ? (
|
||||
<span>
|
||||
All characters are © <UserComponent lang={lang} user={copyrightedCharacters[""]} />
|
||||
</span>
|
||||
) : characterList.length > 2 ? (
|
||||
<span>
|
||||
{characterList.slice(0, characterList.length - 1).join(", ")}, and{" "}
|
||||
{characterList[characterList.length - 1]} are ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
) : characterList.length > 1 ? (
|
||||
<span>
|
||||
{characterList[0]} and {characterList[1]} are ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
) : (
|
||||
<span>
|
||||
{characterList[0]} is ©{" "}
|
||||
<UserComponent lang={lang} user={copyrightedCharacters[characterList[0]]} />
|
||||
</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
) : null}
|
||||
</section>
|
||||
) : null
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,35 @@
|
|||
---
|
||||
import { type User } from "../content/config";
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
import { type Lang } from "../content/config";
|
||||
|
||||
type Props = {
|
||||
user: User;
|
||||
lang: Lang;
|
||||
user: CollectionEntry<"users">;
|
||||
};
|
||||
|
||||
const { user } = Astro.props;
|
||||
const { user, lang } = Astro.props;
|
||||
const username = user.data.nameLang[lang] || user.data.name;
|
||||
let link: string | null = null;
|
||||
if (user.data.preferredLink) {
|
||||
if (user.data.preferredLink in user.data.links) {
|
||||
const preferredLink = user.data.links[user.data.preferredLink] as string | [string, string];
|
||||
if (typeof preferredLink === "string") {
|
||||
link = preferredLink;
|
||||
} else {
|
||||
link = preferredLink[0];
|
||||
}
|
||||
} else {
|
||||
throw new Error(`No preferredLink "${user.data.preferredLink}" for user ${user.id}`);
|
||||
}
|
||||
}
|
||||
---
|
||||
|
||||
{
|
||||
typeof user === "string" ? (
|
||||
<span>{user}</span>
|
||||
user.data.preferredLink == null ? (
|
||||
<span>{username}</span>
|
||||
) : (
|
||||
Object.entries(user).map(([k, v]) => (
|
||||
<a href={v} class="text-link underline" target="_blank">
|
||||
<span>{k}</span>
|
||||
</a>
|
||||
))[0]
|
||||
<a href={link} class="text-link underline" target="_blank">
|
||||
{username}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue