Skip to content

Commit

Permalink
Default image, Date Format, Publication mdx description.
Browse files Browse the repository at this point in the history
  • Loading branch information
funkydunc committed Jan 17, 2025
1 parent 5d264b4 commit d916336
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
date: "2020-07-20"
title: "The Spanish Flu in Delft"
title: "The Spanish Flu in Delft test"
author: "Abel Streefland"
image: https://dlc.services/thumbs/7/21/b65dbfcc-4daf-0b7d-86fc-74a126248b03/full/full/0/default.jpg
description: "Spanish Flu description test"
---

_TU Delft has closed before because of a pandemic_
Expand Down
1 change: 1 addition & 0 deletions apps/static-site/contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const Publication = defineDocumentType(() => ({
contentType: "mdx",
fields: {
title: { type: "string", required: true },
description: { type: "string", required: false },
date: { type: "string", required: false },
author: { type: "string", required: false },
image: { type: "string", required: false },
Expand Down
Binary file removed apps/static-site/public/logo/TUDelft_logo_rgb.png
Binary file not shown.
Binary file added apps/static-site/public/metadata/default.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 12 additions & 7 deletions apps/static-site/src/app/[locale]/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,25 @@ import { Metadata } from "next";
import { getTranslations } from "next-intl/server";
import { getSiteName, getBasicMetadata, makeTitle } from "@/helpers/metadata";

function getAboutPage({ params }: { params: { locale: string } }) {
const aboutPages = allPages.filter((page) => page.path === "/about");
const aboutPage = aboutPages.find((page) => page.lang === params.locale) || aboutPages[0];
if (!aboutPage) throw new Error(`No about page found for locale ${params.locale}`);
return aboutPage;
}

export async function generateMetadata({ params }: { params: { locale: string } }): Promise<Metadata> {
const t = await getTranslations();
const siteName = await getSiteName();
const title = makeTitle([t("About"), siteName]);
const description = t("aboutDesc");
const aboutPage = getAboutPage({ params: params });
const aboutTitle = aboutPage.title || t("About");
const title = makeTitle([aboutTitle, siteName]);
const description = aboutPage.description || t("aboutDesc");
return getBasicMetadata(params.locale, siteName, title, description);
}

export default async function AboutPage({ params }: { params: { locale: string } }) {
const aboutPages = allPages.filter((page) => page.path === "/about");
const aboutPage = aboutPages.find((page) => page.lang === params.locale) || aboutPages[0];

if (!aboutPage) throw new Error(`No about page found for locale ${params.locale}`);

const aboutPage = getAboutPage({ params: params });
const MDXContent = useMDXComponent(aboutPage.body.code);
const CustomSlot = (inner: any) => {
return <Slot context={{ page: "about", locale: params.locale }} {...inner} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,32 @@ export async function generateMetadata({
params: { publication: string; locale: string };
}): Promise<Metadata> {
const t = await getTranslations();
const getValueParams = { language: params.locale, fallbackLanguages: ["nl", "en"] };
const publicationInLanguage = allPublications.find(
(post) => post.id === params.publication && post.lang === params.locale
);
const publication = publicationInLanguage || allPublications.find((post) => post.id === params.publication);
const pubTitle =
publication && getValue(publication.title, { language: params.locale, fallbackLanguages: ["nl", "en"] });
const pubTitle = publication && getValue(publication.title, getValueParams);
const siteName = await getSiteName();
const title = makeTitle([pubTitle, siteName]);
const description = publication && getValue(publication.description, getValueParams);
const author = {
name:
(publication && getValue(publication.author, { language: params.locale, fallbackLanguages: ["nl", "en"] })) || "",
name: (publication && getValue(publication.author, getValueParams)) || "",
};
const pubDateStr =
publication && getValue(publication.date, { language: params.locale, fallbackLanguages: ["nl", "en"] });
const pubDate = pubDateStr && new Date(pubDateStr);
const pubDateFmt =
pubDate &&
pubDate.toLocaleString(params.locale, {
year: "numeric",
month: "long",
day: "numeric",
});
const pubDateStr = publication && getValue(publication.date, getValueParams);
const pubDate = pubDateStr && new Date(pubDateStr).toISOString();
const publicationsURL = `${siteURL}/${params.locale}/publications`;
const image =
publication && getValue(publication.image, { language: params.locale, fallbackLanguages: ["nl", "en"] });
return {
metadataBase: new URL(siteURL),
authors: author,
title: title,
description: null, // assume google will use the first paragraph
description: description,
openGraph: {
authors: [author.name],
locale: params.locale,
publishedTime: pubDateFmt,
publishedTime: pubDate,
siteName: siteName,
title: title,
type: "article",
Expand Down
6 changes: 3 additions & 3 deletions apps/static-site/src/helpers/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ export function getBasicMetadata(locale: string, siteName: string, title: string
description: description,
images: [
{
url: "/logo/TUDelft_logo_rgb.png",
width: 1080,
height: 665,
url: "/metadata/default.jpg",
width: 800,
height: 800,
},
],
locale: locale,
Expand Down

0 comments on commit d916336

Please sign in to comment.