Añadido posts relacionados
This commit is contained in:
@@ -3,16 +3,25 @@ const { currentPost } = Astro.props;
|
||||
|
||||
const posts = await Astro.glob('../pages/posts/*.mdx');
|
||||
|
||||
const relatedPosts = posts.filter(post =>
|
||||
currentPost.relacionados?.includes(post.file.split('/').pop().replace('.mdx', ''))
|
||||
).map(post => ({
|
||||
title: post.frontmatter.titulo,
|
||||
excerpt: post.frontmatter.descripcion,
|
||||
url: post.url,
|
||||
imagen: post.frontmatter.imagen
|
||||
const processedPosts = await Promise.all(posts.map(async (post) => {
|
||||
const { frontmatter, url, file } = await post;
|
||||
const fileName = file.split('/').pop().replace('.mdx', '').toLowerCase();
|
||||
return { fileName, frontmatter, url };
|
||||
}));
|
||||
|
||||
const relatedPosts = processedPosts
|
||||
.filter((post) =>
|
||||
currentPost.relacionados?.map(rel => rel.toLowerCase()).includes(post.fileName)
|
||||
)
|
||||
.map((post) => ({
|
||||
title: post.frontmatter?.titulo || 'Sin título',
|
||||
excerpt: post.frontmatter?.descripcion || '',
|
||||
url: post.url || '#',
|
||||
imagen: post.frontmatter?.imagen || '/default-image.jpg',
|
||||
}));
|
||||
---
|
||||
|
||||
|
||||
<section class="related-posts mt-5 col-lg-8">
|
||||
<h4 class="mb-3">Posts Relacionados</h4>
|
||||
<ul class="list-group">
|
||||
|
||||
Reference in New Issue
Block a user