Added source urls to pages

This commit is contained in:
DrMint 2024-08-16 15:24:29 +02:00
parent 4460397daf
commit d293565e6f
9 changed files with 66 additions and 31 deletions

View File

@ -30,6 +30,7 @@ const { getLocalizedMatch, getLocalizedUrl } = await getI18n(Astro.locals.curren
); );
}) })
} }
<slot />
</div> </div>
{/* ------------------------------------------- CSS -------------------------------------------- */} {/* ------------------------------------------- CSS -------------------------------------------- */}
@ -37,6 +38,6 @@ const { getLocalizedMatch, getLocalizedUrl } = await getI18n(Astro.locals.curren
<style> <style>
div { div {
display: grid; display: grid;
gap: 2em; gap: 1.5em;
} }
</style> </style>

View File

@ -23,6 +23,7 @@ const { getLocalizedMatch } = await getI18n(Astro.locals.currentLocale);
/> />
)) ))
} }
<slot />
</div> </div>
{/* ------------------------------------------- CSS -------------------------------------------- */} {/* ------------------------------------------- CSS -------------------------------------------- */}

View File

@ -1,6 +1,7 @@
--- ---
import type { Attribute } from "src/utils/attributes"; import type { Attribute } from "src/utils/attributes";
import TitleIcon from "./TitleIcon.astro"; import TitleIcon from "./TitleIcon.astro";
import { isExternalLink } from "src/utils/urls";
interface Props extends Attribute {} interface Props extends Attribute {}
@ -15,15 +16,23 @@ if (values.length === 0) return;
<TitleIcon title={title} icon={icon} lang={titleLang} /> <TitleIcon title={title} icon={icon} lang={titleLang} />
<div id="values" class:list={{ "with-border": withBorder }}> <div id="values" class:list={{ "with-border": withBorder }}>
{ {
values.map(({ name, href, lang }) => values.map(({ name, href, lang }) => {
href ? ( if (!href) {
<a class="pressable" href={href} lang={lang}> return <div lang={lang}>{name}</div>;
{name} } else {
</a> const newTab = isExternalLink(href);
) : ( return (
<div lang={lang}>{name}</div> <a
) class="pressable"
) href={href}
lang={lang}
target={newTab ? "_blank" : undefined}
rel={newTab ? "noopener noreferrer" : undefined}>
{name}
</a>
);
}
})
} }
</div> </div>
</div> </div>

View File

@ -255,9 +255,9 @@ export const getI18n = async (locale: string) => {
switch (relation.type) { switch (relation.type) {
case "url": case "url":
return { return {
href: relation.url, href: relation.value.url,
typeLabel: t("global.sources.typeLabel.url"), typeLabel: t("global.sources.typeLabel.url"),
label: relation.label, label: relation.value.label,
target: "_blank", target: "_blank",
rel: "noopener noreferrer", rel: "noopener noreferrer",
}; };

View File

@ -184,4 +184,6 @@ export type WordingKey =
| "global.relationPage.folders" | "global.relationPage.folders"
| "global.relationPage.collectibles" | "global.relationPage.collectibles"
| "global.relationPage.timelineEvents" | "global.relationPage.timelineEvents"
| "global.relationPage.title"; | "global.relationPage.title"
| "pages.credits.sources";

View File

@ -2,34 +2,34 @@
import Card from "components/Card.astro"; import Card from "components/Card.astro";
import Credits from "components/Credits.astro"; import Credits from "components/Credits.astro";
import InlineCredits from "components/InlineCredits.astro"; import InlineCredits from "components/InlineCredits.astro";
import InlineMetadata from "components/InlineMetadata.astro";
import MasoActor from "components/Maso/MasoActor.astro"; import MasoActor from "components/Maso/MasoActor.astro";
import Metadata from "components/Metadata.astro";
import { getI18n } from "src/i18n/i18n"; import { getI18n } from "src/i18n/i18n";
import type { EndpointCredit, EndpointPage } from "src/shared/payload/endpoint-types"; import type { EndpointPage } from "src/shared/payload/endpoint-types";
import { formatLocale } from "src/utils/format"; import { formatLocale } from "src/utils/format";
interface Props { interface Props {
slug: string; slug: string;
currentLocale: string; activeTranslation: EndpointPage["translations"][number];
sourceLanguage: string;
credits: EndpointCredit[];
otherTranslations: EndpointPage["translations"]; otherTranslations: EndpointPage["translations"];
} }
const { slug, currentLocale, sourceLanguage, credits, otherTranslations } = Astro.props; const { slug, activeTranslation, otherTranslations } = Astro.props;
const { t, getLocalizedUrl } = await getI18n(currentLocale); const { t, getLocalizedUrl } = await getI18n(activeTranslation.language);
--- ---
<div id="credits"> <div id="credits">
<Card class="partial_page-card"> <Card class="partial_page-card">
<p>{t("pages.credits.currentLocale")}</p> <p>{t("pages.credits.currentLocale")}</p>
<p class="font-2xl"> <p class="font-2xl">
{formatLocale(currentLocale)} {formatLocale(activeTranslation.language)}
{ {
sourceLanguage !== currentLocale && ( activeTranslation.sourceLanguage !== activeTranslation.language && (
<span class="font-m"> <span class="font-m">
{t("pages.credits.translationLabel", { {t("pages.credits.translationLabel", {
locale: formatLocale(sourceLanguage), locale: formatLocale(activeTranslation.sourceLanguage),
})} })}
</span> </span>
) )
@ -37,9 +37,18 @@ const { t, getLocalizedUrl } = await getI18n(currentLocale);
</p> </p>
{ {
credits.length > 0 && ( (activeTranslation.credits.length > 0 || activeTranslation.sourceUrls.length > 0) && (
<div> <div>
<Credits credits={credits} /> <Credits credits={activeTranslation.credits}>
<Metadata
icon="material-symbols:web-traffic"
title={t("pages.credits.sources", { count: activeTranslation.sourceUrls.length })}
values={activeTranslation.sourceUrls.map(({ label, url }) => ({
name: label,
href: url,
}))}
/>
</Credits>
</div> </div>
) )
} }
@ -65,7 +74,18 @@ const { t, getLocalizedUrl } = await getI18n(currentLocale);
)} )}
</p> </p>
{translation.credits.length > 0 && <InlineCredits credits={translation.credits} />} {(translation.credits.length > 0 || translation.sourceUrls.length > 0) && (
<InlineCredits credits={translation.credits}>
<InlineMetadata
icon="material-symbols:web-traffic"
title={t("pages.credits.sources", { count: translation.sourceUrls.length })}
values={translation.sourceUrls.map(({ label, url }) => ({
name: label,
href: url,
}))}
/>
</InlineCredits>
)}
</Card> </Card>
</MasoActor> </MasoActor>
))} ))}

View File

@ -38,8 +38,9 @@ const { translations, thumbnail, createdAt, updatedAt, updatedBy, attributes } =
const { getLocalizedUrl, t, formatDate } = await getI18n(Astro.locals.currentLocale); const { getLocalizedUrl, t, formatDate } = await getI18n(Astro.locals.currentLocale);
const { getLocalizedMatch } = await getI18n(lang); const { getLocalizedMatch } = await getI18n(lang);
const { pretitle, title, subtitle, summary, content, credits, toc, language, sourceLanguage } = const activeTranslation = getLocalizedMatch(translations);
getLocalizedMatch(translations);
const { pretitle, title, subtitle, summary, content, toc, language } = activeTranslation;
const metaAttributes: Attribute[] = [ const metaAttributes: Attribute[] = [
{ {
@ -107,9 +108,7 @@ if (updatedBy) {
<Fragment slot="aside"> <Fragment slot="aside">
<PageCredits <PageCredits
slug={slug} slug={slug}
currentLocale={language} activeTranslation={activeTranslation}
sourceLanguage={sourceLanguage}
credits={credits}
otherTranslations={translations.filter( otherTranslations={translations.filter(
(otherTranslation) => otherTranslation.language !== language (otherTranslation) => otherTranslation.language !== language
)} )}

@ -1 +1 @@
Subproject commit 63d17331a17a5ab7874599d1df4ecf6b45ac89f3 Subproject commit c2702ea508dde59264ee66100054bacc0834c029

3
src/utils/urls.ts Normal file
View File

@ -0,0 +1,3 @@
export const isExternalLink = (url: string): boolean => {
return url.startsWith("http");
};