Skip to content

Commit

Permalink
feat: implement all-blog-post new source of posts
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcisioandrade committed Feb 20, 2024
1 parent 27b7069 commit c4fe1b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/app/(home)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PostCard } from "@/components/post-card";
import { allBlogPosts } from "@/utils/all-blog-posts";
import { getUniqueCategories } from "@/utils/get-unique-categories";
import { slugger } from "@/utils/slugger";
import { allPosts } from "contentlayer/generated";
import { compareDesc } from "date-fns";
import Link from "next/link";

const posts = allPosts
const posts = allBlogPosts
.filter(({ isPublished }) => isPublished)
.sort((a, b) =>
compareDesc(new Date(a.publishedAt), new Date(b.publishedAt)),
Expand Down
8 changes: 4 additions & 4 deletions src/app/(post-page)/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import ButtonScrollTop from "@/components/button-scroll-top";
import CategoryLink from "@/components/category-link";
import MDXRender from "@/components/mdx-render";
import MenuToc from "@/components/menu-toc";
import { allPosts } from "contentlayer/generated";
import { allBlogPosts } from "@/utils/all-blog-posts";
import { format, parseISO } from "date-fns";
import { ptBR } from "date-fns/locale";
import { Tags, Timer } from "lucide-react";
import { Metadata } from "next";
import { notFound } from "next/navigation";

export const generateStaticParams = async () =>
allPosts.map((post) => ({ slug: post._raw.flattenedPath }));
allBlogPosts.map((post) => ({ slug: post._raw.flattenedPath }));

export const generateMetadata = ({
params,
}: {
params: { slug: string };
}): Metadata => {
const post = allPosts.find((post) => post._raw.flattenedPath === params.slug);
const post = allBlogPosts.find((post) => post._raw.flattenedPath === params.slug);
if (!post) {
notFound();
}
Expand All @@ -39,7 +39,7 @@ export const generateMetadata = ({
};

const PostPage = ({ params }: { params: { slug: string } }) => {
const post = allPosts.find((post) => post._raw.flattenedPath === params.slug);
const post = allBlogPosts .find((post) => post._raw.flattenedPath === params.slug);

if (!post) {
notFound();
Expand Down
4 changes: 2 additions & 2 deletions src/app/category/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { PostCard } from "@/components/post-card";
import { allBlogPosts } from "@/utils/all-blog-posts";
import { capitalize } from "@/utils/capitalize";
import { allPosts } from "contentlayer/generated";
import { Metadata } from "next";

type Props = {
Expand All @@ -17,7 +17,7 @@ export const generateMetadata = ({ params }: Props): Metadata => {
};

const Page = ({ params }: Props) => {
const posts = allPosts.filter((post) =>
const posts = allBlogPosts.filter((post) =>
post.categories.some(
(categ) =>
categ.toLowerCase().replaceAll(/\s/g, "") ===
Expand Down
9 changes: 8 additions & 1 deletion src/utils/get-unique-categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { allPosts } from "contentlayer/generated";

export const getUniqueCategories = () => {
const allCategoriesPosts = allPosts
.filter(({ isPublished }) => isPublished)
.filter(({ isPublished, title }) => {
if (title === "Recursos disponiveis no blog") {
return false;
}
if (isPublished) {
return true;
}
})
.map(({ categories }) => categories);

const uniqueCategories = new Set<string>();
Expand Down

0 comments on commit c4fe1b4

Please sign in to comment.