Skip to content

Commit

Permalink
only show one berlin stories and icymi article in homepage latest art…
Browse files Browse the repository at this point in the history
…icles section. (#124)
  • Loading branch information
antiantivirus authored Apr 30, 2024
1 parent 45a8395 commit ec4015b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
32 changes: 30 additions & 2 deletions lib/contentful/pages/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function getHomePage() {
latestArticles: articleCollection(
order: date_DESC
where: { isFeatured: false }
limit: 6
limit: 20
) {
items {
...ArticlePreviewFragment
Expand All @@ -56,14 +56,42 @@ export async function getHomePage() {

const data = await graphql(HomePageQuery);

let latestArticles = extractCollection<ArticleInterface>(
data,
"latestArticles"
);
let icymi = false;
let bs = false;

const filteredArticles = latestArticles.filter((article) => {
if (article.title.includes("ICYMI")) {
if (!icymi) {
icymi = true;
return true;
}
return false;
} else if (article.title.includes("Berlin Stories")) {
if (!bs) {
bs = true;
return true;
}
return false;
}
return true;
});

// latestArticles.filter(article => {
// return article.title.includes("Berlin Stories") && !icymi
// })

return {
featuredArticles: extractCollection<ArticleInterface>(
data,
"featuredArticles"
),
featuredShows: extractPage<HomePageData>(data, "pageHome")
.featuredShowsCollection.items,
latestArticles: extractCollection<ArticleInterface>(data, "latestArticles"),
latestArticles: filteredArticles.slice(0, 6),
nextUp: extractPage<NextUpSection>(data, "nextUp"),
};
}
4 changes: 4 additions & 0 deletions views/home/latestNews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import ArticlePreview from "../../components/articlePreview";
import Pill from "../../components/pill";
import { Arrow } from "../../icons/arrow";
import { ArticleInterface } from "../../types/shared";
import { useState } from "react";

export default function LatestNews({
articles,
}: {
articles: ArticleInterface[];
}) {
const [icymi, setIcymi] = useState(false);
const [bs, setBs] = useState(false);

return (
<section>
<div className="p-4 sm:p-8">
Expand Down

0 comments on commit ec4015b

Please sign in to comment.