@@ -118,7 +122,7 @@ const Video = ({ langui, video, ...otherProps }: Props): JSX.Element => {
icon={Icon.Event}
className="mr-1 translate-y-[.15em] !text-base"
/>
- {prettyDate(video.published_date)}
+ {prettyDate(video.published_date, router.locale)}
{
[
isMobile,
langui,
+ router.locale,
video.channel?.data?.attributes,
video.description,
video.gone,
@@ -198,7 +203,6 @@ const Video = ({ langui, video, ...otherProps }: Props): JSX.Element => {
return (
{
: "",
});
if (!videos.videos?.data[0]?.attributes) return { notFound: true };
+ const appStaticProps = await getAppStaticProps(context);
const props: Props = {
- ...(await getAppStaticProps(context)),
+ ...appStaticProps,
video: videos.videos.data[0].attributes,
+ openGraph: getOpenGraph(
+ appStaticProps.langui,
+ videos.videos.data[0].attributes.title
+ ),
};
return {
props: props,
diff --git a/src/pages/chronicles/[slug]/index.tsx b/src/pages/chronicles/[slug]/index.tsx
index ed2fa36..b79a3f9 100644
--- a/src/pages/chronicles/[slug]/index.tsx
+++ b/src/pages/chronicles/[slug]/index.tsx
@@ -4,7 +4,7 @@ import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps";
import { getReadySdk } from "graphql/sdk";
import { isDefined, filterHasAttributes } from "helpers/others";
import { ChronicleWithTranslations } from "helpers/types";
-import { AppLayout } from "components/AppLayout";
+import { AppLayout, AppLayoutRequired } from "components/AppLayout";
import { useSmartLanguage } from "hooks/useSmartLanguage";
import { ContentPanel } from "components/Panels/ContentPanel";
import { Markdawn } from "components/Markdown/Markdawn";
@@ -12,20 +12,26 @@ import { SubPanel } from "components/Panels/SubPanel";
import { ThumbnailHeader } from "components/ThumbnailHeader";
import { HorizontalLine } from "components/HorizontalLine";
import { GetChroniclesChaptersQuery } from "graphql/generated";
-import { prettySlug } from "helpers/formatters";
+import { prettyInlineTitle, prettySlug } from "helpers/formatters";
import {
ReturnButton,
ReturnButtonType,
} from "components/PanelComponents/ReturnButton";
import { TranslatedChroniclesList } from "components/Translated";
import { Icon } from "components/Ico";
+import { getOpenGraph } from "helpers/openGraph";
+import {
+ getDefaultPreferredLanguages,
+ staticSmartLanguage,
+} from "helpers/locales";
+import { getDescription } from "helpers/description";
/*
* ╭────────╮
* ──────────────────────────────────────────╯ PAGE ╰─────────────────────────────────────────────
*/
-interface Props extends AppStaticProps {
+interface Props extends AppStaticProps, AppLayoutRequired {
chronicle: ChronicleWithTranslations;
chapters: NonNullable<
GetChroniclesChaptersQuery["chroniclesChapters"]
@@ -191,7 +197,6 @@ const Chronicle = ({
return (
{
});
const chronicles = await sdk.getChroniclesChapters();
if (
- !chronicle.chronicles?.data[0].attributes?.translations ||
+ !chronicle.chronicles?.data[0]?.attributes?.translations ||
!chronicles.chroniclesChapters?.data
)
return { notFound: true };
+ const appStaticProps = await getAppStaticProps(context);
+
+ const { title, description } = (() => {
+ if (context.locale && context.locales) {
+ if (
+ chronicle.chronicles.data[0].attributes.contents?.data[0]?.attributes
+ ?.translations
+ ) {
+ const selectedContentTranslation = staticSmartLanguage({
+ items:
+ chronicle.chronicles.data[0].attributes.contents.data[0].attributes
+ .translations,
+ languageExtractor: (item) => item.language?.data?.attributes?.code,
+ preferredLanguages: getDefaultPreferredLanguages(
+ context.locale,
+ context.locales
+ ),
+ });
+ if (selectedContentTranslation) {
+ return {
+ title: prettyInlineTitle(
+ selectedContentTranslation.pre_title,
+ selectedContentTranslation.title,
+ selectedContentTranslation.subtitle
+ ),
+ description: getDescription(
+ selectedContentTranslation.description,
+ {
+ [appStaticProps.langui.type ?? "Type"]: [
+ chronicle.chronicles.data[0].attributes.contents.data[0]
+ .attributes.type?.data?.attributes?.titles?.[0]?.title,
+ ],
+ [appStaticProps.langui.categories ?? "Categories"]:
+ filterHasAttributes(
+ chronicle.chronicles.data[0].attributes.contents.data[0]
+ .attributes.categories?.data,
+ ["attributes"] as const
+ ).map((category) => category.attributes.short),
+ }
+ ),
+ };
+ }
+ } else {
+ const selectedTranslation = staticSmartLanguage({
+ items: chronicle.chronicles.data[0].attributes.translations,
+ languageExtractor: (item) => item.language?.data?.attributes?.code,
+ preferredLanguages: getDefaultPreferredLanguages(
+ context.locale,
+ context.locales
+ ),
+ });
+ if (selectedTranslation) {
+ return {
+ title: selectedTranslation.title,
+ description: selectedTranslation.summary,
+ };
+ }
+ }
+ }
+ return {
+ title: prettySlug(chronicle.chronicles.data[0].attributes.slug),
+ description: undefined,
+ };
+ })();
+
+ const thumbnail =
+ chronicle.chronicles.data[0].attributes.translations.length === 0
+ ? chronicle.chronicles.data[0].attributes.contents?.data[0]?.attributes
+ ?.thumbnail?.data?.attributes
+ : undefined;
+
const props: Props = {
- ...(await getAppStaticProps(context)),
+ ...appStaticProps,
chronicle: chronicle.chronicles.data[0]
.attributes as ChronicleWithTranslations,
chapters: chronicles.chroniclesChapters.data,
+ openGraph: getOpenGraph(
+ appStaticProps.langui,
+ title,
+ description,
+ thumbnail
+ ),
};
return {
props: props,
diff --git a/src/pages/chronicles/index.tsx b/src/pages/chronicles/index.tsx
index afcc5f2..e3e3f3f 100644
--- a/src/pages/chronicles/index.tsx
+++ b/src/pages/chronicles/index.tsx
@@ -1,6 +1,6 @@
import { GetStaticProps } from "next";
import { useMemo } from "react";
-import { AppLayout } from "components/AppLayout";
+import { AppLayout, AppLayoutRequired } from "components/AppLayout";
import { PanelHeader } from "components/PanelComponents/PanelHeader";
import { SubPanel } from "components/Panels/SubPanel";
import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps";
@@ -10,13 +10,14 @@ import { GetChroniclesChaptersQuery } from "graphql/generated";
import { filterHasAttributes } from "helpers/others";
import { prettySlug } from "helpers/formatters";
import { TranslatedChroniclesList } from "components/Translated";
+import { getOpenGraph } from "helpers/openGraph";
/*
* ╭────────╮
* ──────────────────────────────────────────╯ PAGE ╰─────────────────────────────────────────────
*/
-interface Props extends AppStaticProps {
+interface Props extends AppStaticProps, AppLayoutRequired {
chapters: NonNullable<
GetChroniclesChaptersQuery["chroniclesChapters"]
>["data"];
@@ -58,14 +59,7 @@ const Chronicles = ({
[chapters, langui]
);
- return (
-
- );
+ return ;
};
export default Chronicles;
@@ -78,9 +72,14 @@ export const getStaticProps: GetStaticProps = async (context) => {
const sdk = getReadySdk();
const chronicles = await sdk.getChroniclesChapters();
if (!chronicles.chroniclesChapters?.data) return { notFound: true };
+ const appStaticProps = await getAppStaticProps(context);
const props: Props = {
- ...(await getAppStaticProps(context)),
+ ...appStaticProps,
chapters: chronicles.chroniclesChapters.data,
+ openGraph: getOpenGraph(
+ appStaticProps.langui,
+ appStaticProps.langui.chronicles ?? "Chronicles"
+ ),
};
return {
props: props,
diff --git a/src/pages/contents/[slug]/index.tsx b/src/pages/contents/[slug]/index.tsx
index f453511..9125275 100644
--- a/src/pages/contents/[slug]/index.tsx
+++ b/src/pages/contents/[slug]/index.tsx
@@ -1,6 +1,6 @@
import { GetStaticPaths, GetStaticPathsResult, GetStaticProps } from "next";
import { Fragment, useCallback, useMemo } from "react";
-import { AppLayout } from "components/AppLayout";
+import { AppLayout, AppLayoutRequired } from "components/AppLayout";
import { Chip } from "components/Chip";
import { HorizontalLine } from "components/HorizontalLine";
import { PreviewCardCTAs } from "components/Library/PreviewCardCTAs";
@@ -17,7 +17,6 @@ import { ThumbnailHeader } from "components/ThumbnailHeader";
import { ToolTip } from "components/ToolTip";
import { AppStaticProps, getAppStaticProps } from "graphql/getAppStaticProps";
import { getReadySdk } from "graphql/sdk";
-import { getDescription } from "helpers/description";
import {
prettyInlineTitle,
prettyLanguage,
@@ -35,13 +34,19 @@ import { useMediaMobile } from "hooks/useMediaQuery";
import { AnchorIds, useScrollTopOnChange } from "hooks/useScrollTopOnChange";
import { useSmartLanguage } from "hooks/useSmartLanguage";
import { TranslatedPreviewLine } from "components/Translated";
+import { getOpenGraph } from "helpers/openGraph";
+import {
+ getDefaultPreferredLanguages,
+ staticSmartLanguage,
+} from "helpers/locales";
+import { getDescription } from "helpers/description";
/*
* ╭────────╮
* ──────────────────────────────────────────╯ PAGE ╰─────────────────────────────────────────────
*/
-interface Props extends AppStaticProps {
+interface Props extends AppStaticProps, AppLayoutRequired {
content: ContentWithTranslations;
}
@@ -260,7 +265,7 @@ const Content = ({
).map((category) => category.attributes.short)}
metadata={{
currencies: currencies,
- release_date: libraryItem.attributes.release_date,
+ releaseDate: libraryItem.attributes.release_date,
price: libraryItem.attributes.price,
position: "Bottom",
}}
@@ -457,22 +462,6 @@ const Content = ({
return (
{
if (!content.contents?.data[0]?.attributes?.translations) {
return { notFound: true };
}
+ const appStaticProps = await getAppStaticProps(context);
+
+ const { title, description } = (() => {
+ if (context.locale && context.locales) {
+ const selectedTranslation = staticSmartLanguage({
+ items: content.contents.data[0].attributes.translations,
+ languageExtractor: (item) => item.language?.data?.attributes?.code,
+ preferredLanguages: getDefaultPreferredLanguages(
+ context.locale,
+ context.locales
+ ),
+ });
+ if (selectedTranslation) {
+ return {
+ title: prettyInlineTitle(
+ selectedTranslation.pre_title,
+ selectedTranslation.title,
+ selectedTranslation.subtitle
+ ),
+ description: getDescription(selectedTranslation.description, {
+ [appStaticProps.langui.type ?? "Type"]: [
+ content.contents.data[0].attributes.type?.data?.attributes
+ ?.titles?.[0]?.title,
+ ],
+ [appStaticProps.langui.categories ?? "Categories"]:
+ filterHasAttributes(
+ content.contents.data[0].attributes.categories?.data,
+ ["attributes"] as const
+ ).map((category) => category.attributes.short),
+ }),
+ };
+ }
+ }
+ return {
+ title: prettySlug(content.contents.data[0].attributes.slug),
+ description: undefined,
+ };
+ })();
+
+ const thumbnail =
+ content.contents.data[0].attributes.thumbnail?.data?.attributes;
+
const props: Props = {
- ...(await getAppStaticProps(context)),
+ ...appStaticProps,
content: content.contents.data[0].attributes as ContentWithTranslations,
+ openGraph: getOpenGraph(
+ appStaticProps.langui,
+ title,
+ description,
+ thumbnail
+ ),
};
return {
props: props,
diff --git a/src/pages/contents/index.tsx b/src/pages/contents/index.tsx
index fda27c7..9b4639d 100644
--- a/src/pages/contents/index.tsx
+++ b/src/pages/contents/index.tsx
@@ -1,6 +1,6 @@
import { GetStaticProps } from "next";
import { useState, useMemo, useCallback } from "react";
-import { AppLayout } from "components/AppLayout";
+import { AppLayout, AppLayoutRequired } from "components/AppLayout";
import { Select } from "components/Inputs/Select";
import { Switch } from "components/Inputs/Switch";
import { PanelHeader } from "components/PanelComponents/PanelHeader";
@@ -23,6 +23,7 @@ import { SmartList } from "components/SmartList";
import { SelectiveNonNullable } from "helpers/types/SelectiveNonNullable";
import { useBoolean } from "hooks/useBoolean";
import { TranslatedPreviewCard } from "components/Translated";
+import { getOpenGraph } from "helpers/openGraph";
/*
* ╭─────────────╮
@@ -41,7 +42,7 @@ const DEFAULT_FILTERS_STATE = {
* ──────────────────────────────────────────╯ PAGE ╰─────────────────────────────────────────────
*/
-interface Props extends AppStaticProps {
+interface Props extends AppStaticProps, AppLayoutRequired {
contents: NonNullable["data"];
}
@@ -164,7 +165,7 @@ const Contents = ({
@@ -174,7 +175,7 @@ const Contents = ({
input={