Skip to content

Commit

Permalink
Remove posts from hidden category in feed and home
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallku committed Feb 14, 2024
1 parent 1ccf67e commit 1a059d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
33 changes: 18 additions & 15 deletions apps/blog/app/feed/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,25 @@ export async function GET() {
const categories = getCategories();
const host = "https://marshallku.com";
const formattedPosts = await Promise.all(
posts.slice(0, 10).map(async (post) => {
const url = `${host}${post.slug
.split("/")
.map((x) => encodeURIComponent(x))
.join("/")}`;
posts
.filter(({ category }) => !!categories.find(({ slug }) => slug === category))
.slice(0, 10)
.map(async (post) => {
const url = `${host}${post.slug
.split("/")
.map((x) => encodeURIComponent(x))
.join("/")}`;

return {
title: post.data.title,
link: url,
pubDate: post.data.date.posted.toUTCString(),
category: categories.find(({ slug }) => slug === post.category)?.name || post.category.slice(1),
tags: post.data.tags,
description: post.data.description,
content: marked.parse(post.content),
};
}),
return {
title: post.data.title,
link: url,
pubDate: post.data.date.posted.toUTCString(),
category: categories.find(({ slug }) => slug === post.category)?.name || post.category.slice(1),
tags: post.data.tags,
description: post.data.description,
content: marked.parse(post.content),
};
}),
);

return new Response(
Expand Down
8 changes: 6 additions & 2 deletions apps/blog/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ const cx = classNames(styles, "home");
export default async function Home() {
const posts = getPosts();
const mostRecentPost = posts[0];
const postsInPage = posts.slice(1, PAGE_SIZE);
const categories = getCategories();
const postsInPage = posts
.slice(1)
.filter(({ category }) => !!categories.find(({ slug }) => slug === category))
.slice(0, PAGE_SIZE);
const galleryPosts = posts.filter(({ category }) => category === "/gallery").slice(0, 6);

return (
Expand Down Expand Up @@ -44,7 +48,7 @@ export default async function Home() {
<PostList posts={postsInPage} />
</section>
<section className={cx("__container", "__container--padding", "__category")}>
{getCategories()
{categories
.filter(({ icon }) => !!icon)
.map(({ slug, name, icon, color }) => (
<Link href={slug} key={slug}>
Expand Down

0 comments on commit 1a059d0

Please sign in to comment.