Añadido posts relacionados

This commit is contained in:
2024-11-26 09:30:36 +01:00
parent 99035d8641
commit 32ea45eb26
19 changed files with 34 additions and 11 deletions

View File

@@ -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">