Skip to content

Commit

Permalink
allow show page to only have title field (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
antiantivirus authored Sep 25, 2024
1 parent 8f2f2c3 commit c1a1f26
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions lib/contentful/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function getPastShows(
if (filter.length == 0) {
const { items } = await client.getEntries<TypeShowFields>({
"fields.mixcloudLink[exists]": true,
"fields.coverImage[exists]": true,
"fields.date[lte]": now,
order: "-fields.date,fields.title",
content_type: "show",
Expand Down
17 changes: 16 additions & 1 deletion lib/contentful/pages/radio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import {
sort,
} from "../../../util";

const placeholderImage = {
sys: { id: "4njwdSvfwFLNoSZ6j1jE2G" },
title: "",
description: "",
url: "/images/placeholder.jpg",
width: 2000,
height: 1340,
};

export const RADIO_SHOWS_PAGE_SIZE = 20;

export async function getRadioPageSingle(slug: string, preview: boolean) {
Expand Down Expand Up @@ -83,6 +92,10 @@ export async function getRadioPageSingle(slug: string, preview: boolean) {
throw new Error(`No Show found for slug '${slug}'`);
}

if (!entry.coverImage) {
entry.coverImage = placeholderImage;
}

console.log(entry.genresCollection);

const genres = entry.genresCollection.items.map((genre) => genre?.name);
Expand Down Expand Up @@ -247,7 +260,9 @@ export async function getRelatedShows(
date: show.date,
slug: show.slug,
mixcloudLink: show.mixcloudLink,
coverImage: show.coverImage.url,
coverImage: show.coverImage?.url
? show.coverImage.url
: placeholderImage.url,
genres: show.genresCollection.items
.map((genre) => genre?.name)
.filter(Boolean),
Expand Down
2 changes: 1 addition & 1 deletion pages/radio/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Show({
);
}

export async function getStaticProps({ params, preview = false }) {
export async function getStaticProps({ params, preview = true }) {
return {
props: { preview, ...(await getRadioPageSingle(params.slug, preview)) },
};
Expand Down
34 changes: 19 additions & 15 deletions views/radio/showBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function ShowBody({
<div className="h-3 block md:hidden" />

<p className="text-small text-center">
<Date dateString={date} />
{date && <Date dateString={date} />}
</p>

<div className="h-6" />
Expand All @@ -80,22 +80,26 @@ export default function ShowBody({

<div className="h-6" />

<ul className="w-full flex flex-wrap justify-center gap-2">
{genres.map((genre, i) => (
<li className="cursor-pointer" key={i}>
<Link
href={`/radio?genre=${encodeURIComponent(genre)}#shows`}
legacyBehavior
>
<Badge as="a" text={genre} />
</Link>
</li>
))}
</ul>
{genres.length > 0 && (
<ul className="w-full flex flex-wrap justify-center gap-2">
{genres.map((genre, i) => (
<li className="cursor-pointer" key={i}>
<Link
href={`/radio?genre=${encodeURIComponent(genre)}#shows`}
legacyBehavior
>
<Badge as="a" text={genre} />
</Link>
</li>
))}
</ul>
)}

<div className="h-6" />

<p className="font-medium text-center">With {persons}</p>
{artists.length > 0 && (
<p className="font-medium text-center">With {persons}</p>
)}
</div>

<div className="flex">
Expand All @@ -110,7 +114,7 @@ export default function ShowBody({

<div className="h-6" />

<Prose>{documentToReactComponents(content?.json)}</Prose>
{content && <Prose>{documentToReactComponents(content?.json)}</Prose>}
</div>
</section>
</Fragment>
Expand Down

0 comments on commit c1a1f26

Please sign in to comment.