Skip to content

Commit e7ced68

Browse files
committed
reuse Tags and BlogPostCard comopnents
1 parent e961fc1 commit e7ced68

6 files changed

Lines changed: 30 additions & 219 deletions

File tree

app/posts/[slug]/page.tsx

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { formatDate } from "@/lib/utils";
66
// import { siteConfig } from "@/lib/site-config";
77
import { ProseContainer } from "@/components/prose-container";
88
import { FrontMatter, getPosts } from "../page";
9+
import { Tag } from "@/components/blog-post-tag";
10+
import { BlogPostCard } from "@/components/blog-post-card";
911

1012
export async function generateStaticParams() {
1113
const blogPosts = await getPosts();
@@ -91,12 +93,7 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug:
9193
<p className="text-xl text-zinc-700 dark:text-zinc-300 mb-6">{frontmatter.description}</p>
9294
<div className="flex flex-wrap gap-2">
9395
{frontmatter.tags.map((tag) => (
94-
<span
95-
key={tag}
96-
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-zinc-200 text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200"
97-
>
98-
{tag}
99-
</span>
96+
<Tag key={tag} tag={tag} />
10097
))}
10198
</div>
10299
</header>
@@ -105,46 +102,8 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug:
105102
</ProseContainer>
106103
<div className="mt-16 pt-8 border-t border-zinc-200 dark:border-zinc-800">
107104
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
108-
{prevPost && (
109-
<div className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-6">
110-
<span className="text-sm text-zinc-500 dark:text-zinc-400 block mb-2">Artículo anterior</span>
111-
<h3 className="text-lg font-mono font-semibold mb-2 text-zinc-900 dark:text-zinc-50">
112-
<Link href={`/posts/${prevPost.slug}`} className="hover:underline">
113-
{prevPost.frontmatter.title}
114-
</Link>
115-
</h3>
116-
<div className="flex flex-wrap gap-2">
117-
{prevPost.frontmatter.tags.slice(0, 2).map((tag) => (
118-
<span
119-
key={tag}
120-
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-zinc-200 text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200"
121-
>
122-
{tag}
123-
</span>
124-
))}
125-
</div>
126-
</div>
127-
)}
128-
{nextPost && (
129-
<div className="border border-zinc-200 dark:border-zinc-800 rounded-lg p-6">
130-
<span className="text-sm text-zinc-500 dark:text-zinc-400 block mb-2">Artículo siguiente</span>
131-
<h3 className="text-lg font-mono font-semibold mb-2 text-zinc-900 dark:text-zinc-50">
132-
<Link href={`/posts/${nextPost.slug}`} className="hover:underline">
133-
{nextPost.frontmatter.title}
134-
</Link>
135-
</h3>
136-
<div className="flex flex-wrap gap-2">
137-
{nextPost.frontmatter.tags.slice(0, 2).map((tag) => (
138-
<span
139-
key={tag}
140-
className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-zinc-200 text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200"
141-
>
142-
{tag}
143-
</span>
144-
))}
145-
</div>
146-
</div>
147-
)}
105+
{prevPost && <BlogPostCard key={prevPost.slug} slug={prevPost.slug} frontmatter={prevPost.frontmatter} />}
106+
{nextPost && <BlogPostCard key={nextPost.slug} slug={nextPost.slug} frontmatter={nextPost.frontmatter} />}
148107
</div>
149108
</div>
150109
</article>

components/blog-post-card.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import SimpleMarquee from "@/fancy/components/blocks/simple-marquee";
22
import { slugify } from "@/lib/utils";
33
import Link from "next/link";
4+
import { Tag } from "./blog-post-tag";
45

56
function formatDate(dateString: string): string {
67
const date = new Date(dateString);
@@ -48,13 +49,7 @@ export function BlogPostCard({ slug, frontmatter }: PostCardProps) {
4849
{frontmatter.tags
4950
.map((tag) => slugify(tag.toLowerCase()))
5051
.map((tag, index) => (
51-
<Link
52-
key={`${tag}-${index}`}
53-
href={`/posts?tag=${slugify(tag.toLowerCase())}`}
54-
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-zinc-200 text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200 whitespace-nowrap"
55-
>
56-
{tag}
57-
</Link>
52+
<Tag key={`${tag}-${index}`} tag={tag} />
5853
))}
5954
</SimpleMarquee>
6055
</div>

components/blog-post-tag.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { slugify } from "@/lib/utils";
2+
import Link from "next/link";
3+
4+
export function Tag({ tag }: { tag: string }) {
5+
tag = slugify(tag.toLowerCase());
6+
return (
7+
<Link
8+
href={`/posts?tag=${tag}`}
9+
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-zinc-100 text-zinc-800 dark:bg-zinc-800 dark:text-zinc-200 whitespace-nowrap hover:bg-zinc-200 dark:hover:bg-zinc-700"
10+
>
11+
{tag}
12+
</Link>
13+
);
14+
}

components/site-footer.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import Link from "next/link";
22
import { siteConfig } from "@/lib/site-config";
3+
import { getPosts } from "@/app/posts/page";
4+
import { Tag } from "./blog-post-tag";
35

4-
export function SiteFooter() {
6+
export async function SiteFooter() {
7+
const blogPosts = await getPosts();
8+
const uniqueTags = [...new Set(blogPosts.flatMap((post) => post.frontmatter.tags))];
59
return (
610
<footer className="border-t border-zinc-200 bg-background/50 backdrop-blur-[2px] dark:border-zinc-800 z-10">
711
<div className="container mx-auto px-4 py-8">
@@ -28,16 +32,10 @@ export function SiteFooter() {
2832
</ul>
2933
</div>
3034
<div>
31-
<h3 className="text-sm font-mono font-semibold text-zinc-900 dark:text-zinc-50">Temas</h3>
35+
<h3 className="text-sm font-mono font-semibold text-zinc-900 dark:text-zinc-50">Tags</h3>
3236
<div className="mt-4 flex flex-wrap gap-2">
33-
{siteConfig.footerNav.popularTags.map((tag) => (
34-
<Link
35-
key={tag.href}
36-
href={tag.href}
37-
className="inline-flex items-center rounded-full bg-zinc-100 px-2.5 py-0.5 text-xs font-medium text-zinc-800 hover:bg-zinc-200 dark:bg-zinc-800 dark:text-zinc-200 dark:hover:bg-zinc-700"
38-
>
39-
{tag.title}
40-
</Link>
37+
{uniqueTags.map((tag) => (
38+
<Tag key={tag} tag={tag} />
4139
))}
4240
</div>
4341
</div>

lib/blog-data.ts

Lines changed: 0 additions & 155 deletions
This file was deleted.

posts/ia-y-autopoiesis-neocibernetica/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "IA y Autopoiesis Neocibernética: Disrupción Tecnogenómica y Neofeudalismo Informático en la Periferia Latinoamericana"
33
date: 2021-10-01
44
description: "Un análisis crítico de la intersección entre la inteligencia artificial, la teoría de sistemas y la geopolítica en el contexto de la periferia latinoamericana."
5-
tags: [IA, autopoiesis, neofeudalismo, Latinoamérica, ciberpunk]
5+
tags: [IA, autopoiesis, neofeudalismo, Latinoamérica, cyberpunk]
66
---
77

88
## Resumen

0 commit comments

Comments
 (0)