Skip to content

Commit ad7877a

Browse files
author
Daveed
committed
draft for /blog
1 parent e7f2029 commit ad7877a

File tree

5 files changed

+282
-347
lines changed

5 files changed

+282
-347
lines changed

src/pages/blog.astro

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

src/pages/blog/[slug].astro

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
---
2+
import Layout from "../../layouts/BasicLayout.astro";
3+
import BlocksContent from "../../components/blocks.content.astro";
4+
import { getCollection } from "astro:content";
5+
6+
export async function getStaticPaths() {
7+
const posts = await getCollection("posts");
8+
9+
return posts.map((p) => ({ params: { slug: p.data?.slug || p.id } }));
10+
}
11+
12+
const pages = await getCollection("pages");
13+
14+
const { slug } = Astro.params;
15+
const posts = await getCollection("posts");
16+
const current = posts.find((p) => p.data?.slug === slug || p.id === slug)?.data;
17+
if (!current) throw new Error(`Page not found: ${slug}`);
18+
19+
const relatedPosts = pages.filter(
20+
(p) => ![slug,].includes(p.data?.slug)
21+
).splice(0,3)
22+
---
23+
24+
<Layout
25+
title={current?.SEO?.metaTit || current.Title }
26+
description={current?.SEO?.metaDescription || undefined}
27+
keywords={current?.SEO?.metaKeywords || undefined}
28+
author={current?.SEO?.metaAuthor || undefined}
29+
ogImage={current?.SEO?.socialImage?.url || undefined}
30+
>
31+
<main>
32+
<section
33+
class="py-6 bg-gradient"
34+
style="background: linear-gradient(135deg,#f8fafc 0%, #eef2ff 100%);"
35+
>
36+
<div class="container">
37+
<div class="row justify-content-center">
38+
<div class="col-lg-10 text-center">
39+
<h1 class="display-4 fw-bold mb-3">{current?.Title }</h1>
40+
<p class="lead text-muted mb-0">{current.SEO.metaDescription}</p>
41+
</div>
42+
</div>
43+
</div>
44+
</section>
45+
46+
<section class="py-5">
47+
<div class="container">
48+
<div class="row justify-content-center">
49+
<div class="col-lg-10">
50+
<BlocksContent content={current?.Content || []} />
51+
</div>
52+
</div>
53+
</div>
54+
</section>
55+
56+
<section class="container my-5">
57+
<div class="row">
58+
<div class="col-12 text-center mb-4">
59+
<h2 class="display-6 fw-bold">Articulos relacionados</h2>
60+
</div>
61+
</div>
62+
<div class="row">
63+
<div class="row">
64+
{
65+
relatedPosts.slice(1).map((post) => (
66+
<div class="col-md-6 col-lg-4 mb-4">
67+
<article class="card border-0 shadow-sm h-100">
68+
<img
69+
src={post?.data?.SEO?.socialImage?.url}
70+
alt={post?.data?.Title}
71+
class="card-img-top"
72+
style="height: 200px; object-fit: cover;"
73+
/>
74+
<div class="card-body d-flex flex-column">
75+
<div class="mb-3">
76+
<span class="badge bg-primary">{'x'}</span>
77+
</div>
78+
<h5 class="card-title fw-bold">{post.data.Title}</h5>
79+
<p class="card-text text-muted flex-grow-1">
80+
{post.data.SEO?.metaDescription}
81+
</p>
82+
<div class="d-flex align-items-center text-muted small mb-3">
83+
<i class="bi bi-person-circle me-2"></i>
84+
<span class="me-3">{'x'}</span>
85+
<i class="bi bi-clock me-2"></i>
86+
<span>{'x'}</span>
87+
</div>
88+
<a href={`/blog/${post.data.slug}`} class="btn btn-outline-primary">
89+
Leer Más
90+
</a>
91+
</div>
92+
</article>
93+
</div>
94+
))
95+
}
96+
</div>
97+
</div>
98+
</section>
99+
</main>
100+
</Layout>

0 commit comments

Comments
 (0)