astro-blog-kit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,248 @@
1
+ ---
2
+ import type { BlogPost } from "../types";
3
+ import { getFeaturedImageUrl } from "../utils/slug";
4
+
5
+ interface Props {
6
+ post: BlogPost;
7
+ blogBase: string;
8
+ dateLocale: string;
9
+ ctaText: string;
10
+ variant?: "featured" | "small" | "grid" | "list";
11
+ }
12
+
13
+ const { post, blogBase, dateLocale, ctaText, variant = "grid" } = Astro.props;
14
+
15
+ const imgUrl = getFeaturedImageUrl(post);
16
+ const isFeatured = variant === "featured";
17
+ const isSmall = variant === "small";
18
+ const isList = variant === "list";
19
+ ---
20
+
21
+ <article class={`blog-card blog-card--${variant}`}>
22
+
23
+ <a href={`${blogBase}${post.slug}/`}
24
+ class={`blog-card__link ${isSmall || isList ? "blog-card__link--horizontal" : ""}`}
25
+ >
26
+
27
+ <!-- Imagen -->
28
+ <div class={`blog-card__thumb ${isSmall ? "blog-card__thumb--small" : ""}`}>
29
+ {imgUrl ? (
30
+ <img
31
+ src={imgUrl}
32
+ alt={post.title.rendered}
33
+ class="blog-card__img"
34
+ loading="lazy"
35
+ />
36
+ ) : (
37
+ <div class="blog-card__placeholder">
38
+ <svg
39
+ width={isFeatured ? 48 : 28}
40
+ height={isFeatured ? 48 : 28}
41
+ viewBox="0 0 24 24"
42
+ fill="none"
43
+ stroke="currentColor"
44
+ stroke-width="1.5"
45
+ >
46
+ <rect x="3" y="3" width="18" height="18" rx="2"/>
47
+ <circle cx="8.5" cy="8.5" r="1.5"/>
48
+ <path d="M21 15l-5-5L5 21"/>
49
+ </svg>
50
+ </div>
51
+ )}
52
+ <div class="blog-card__overlay" aria-hidden="true"></div>
53
+ {isFeatured && (
54
+ <div class="blog-card__featured-badge">Featured</div>
55
+ )}
56
+ </div>
57
+
58
+ <!-- Contenido -->
59
+ <div class={`blog-card__body ${isSmall ? "blog-card__body--small" : ""}`}>
60
+ <time class="blog-card__date">
61
+ {new Date(post.date).toLocaleDateString(dateLocale, {
62
+ year: "numeric",
63
+ month: "long",
64
+ day: "numeric",
65
+ })}
66
+ </time>
67
+
68
+ <h2
69
+ class={`blog-card__title ${isSmall ? "blog-card__title--small" : ""}`}
70
+ set:html={post.title.rendered}
71
+ />
72
+
73
+ {(isFeatured || variant === "grid" || isList) && (
74
+ <div class="blog-card__excerpt" set:html={post.excerpt.rendered} />
75
+ )}
76
+
77
+ <span class="blog-card__cta">{ctaText} →</span>
78
+ </div>
79
+
80
+ </a>
81
+ </article>
82
+
83
+ <style>
84
+ .blog-card {
85
+ border: 2px solid var(--color-gray-200);
86
+ background-color: var(--color-white);
87
+ overflow: hidden;
88
+ transition: transform 0.3s ease, border-color 0.3s ease;
89
+ }
90
+
91
+ .blog-card:hover {
92
+ transform: translateY(-4px);
93
+ border-color: var(--color-yellow);
94
+ border-bottom-width: 4px;
95
+ }
96
+
97
+ .blog-card__link {
98
+ display: flex;
99
+ flex-direction: column;
100
+ height: 100%;
101
+ text-decoration: none;
102
+ color: inherit;
103
+ }
104
+
105
+ .blog-card__link--horizontal {
106
+ flex-direction: row;
107
+ }
108
+
109
+ /* Thumb */
110
+ .blog-card__thumb {
111
+ position: relative;
112
+ width: 100%;
113
+ aspect-ratio: 16 / 9;
114
+ background-color: var(--color-gray-100);
115
+ overflow: hidden;
116
+ flex-shrink: 0;
117
+ }
118
+
119
+ .blog-card__thumb--small {
120
+ width: 140px;
121
+ aspect-ratio: auto;
122
+ min-height: 100%;
123
+ }
124
+
125
+ @media (max-width: 480px) {
126
+ .blog-card__thumb--small {
127
+ width: 100px;
128
+ }
129
+ }
130
+
131
+ .blog-card__img {
132
+ width: 100%;
133
+ height: 100%;
134
+ object-fit: cover;
135
+ display: block;
136
+ transition: transform 0.4s ease;
137
+ }
138
+
139
+ .blog-card:hover .blog-card__img {
140
+ transform: scale(1.05);
141
+ }
142
+
143
+ .blog-card__placeholder {
144
+ width: 100%;
145
+ height: 100%;
146
+ min-height: 80px;
147
+ display: flex;
148
+ align-items: center;
149
+ justify-content: center;
150
+ color: var(--color-gray-300);
151
+ background-color: var(--color-gray-100);
152
+ }
153
+
154
+ .blog-card__overlay {
155
+ position: absolute;
156
+ inset: 0;
157
+ background: linear-gradient(to bottom, transparent 50%, rgba(26,26,26,0.45) 100%);
158
+ pointer-events: none;
159
+ }
160
+
161
+ .blog-card__featured-badge {
162
+ position: absolute;
163
+ top: 1rem;
164
+ left: 1rem;
165
+ background-color: var(--color-yellow);
166
+ color: var(--color-black);
167
+ font-size: 0.65rem;
168
+ font-weight: 700;
169
+ text-transform: uppercase;
170
+ letter-spacing: 0.15em;
171
+ padding: 0.25rem 0.75rem;
172
+ }
173
+
174
+ /* Body */
175
+ .blog-card__body {
176
+ padding: 1.75rem;
177
+ display: flex;
178
+ flex-direction: column;
179
+ gap: 0.75rem;
180
+ flex: 1;
181
+ }
182
+
183
+ .blog-card__body--small {
184
+ padding: 1rem 1.25rem;
185
+ gap: 0.4rem;
186
+ }
187
+
188
+ .blog-card__date {
189
+ font-size: 0.7rem;
190
+ font-weight: 700;
191
+ text-transform: uppercase;
192
+ letter-spacing: 0.12em;
193
+ color: var(--color-gray-400);
194
+ }
195
+
196
+ .blog-card__title {
197
+ font-family: var(--font-heading);
198
+ font-size: 1.5rem;
199
+ font-weight: 700;
200
+ color: var(--color-black);
201
+ line-height: 1.05;
202
+ text-transform: uppercase;
203
+ margin: 0;
204
+ }
205
+
206
+ .blog-card__title--small {
207
+ font-size: 1rem;
208
+ line-height: 1.2;
209
+ display: -webkit-box;
210
+ -webkit-line-clamp: 2;
211
+ -webkit-box-orient: vertical;
212
+ overflow: hidden;
213
+ }
214
+
215
+ .blog-card__excerpt {
216
+ font-size: 0.9rem;
217
+ color: var(--color-gray-600);
218
+ line-height: 1.65;
219
+ display: -webkit-box;
220
+ -webkit-line-clamp: 3;
221
+ -webkit-box-orient: vertical;
222
+ overflow: hidden;
223
+ margin: 0;
224
+ }
225
+
226
+ .blog-card__excerpt :global(p) {
227
+ margin: 0;
228
+ }
229
+
230
+ .blog-card__cta {
231
+ margin-top: auto;
232
+ padding-top: 0.75rem;
233
+ font-size: 0.875rem;
234
+ font-weight: 700;
235
+ color: var(--color-black);
236
+ display: inline-block;
237
+ transition: transform 0.2s ease;
238
+ }
239
+
240
+ .blog-card--small .blog-card__cta {
241
+ padding-top: 0.25rem;
242
+ font-size: 0.8rem;
243
+ }
244
+
245
+ .blog-card:hover .blog-card__cta {
246
+ transform: translateX(4px);
247
+ }
248
+ </style>
@@ -0,0 +1,42 @@
1
+ ---
2
+ import type { BlogListProps } from "../../types";
3
+ import type { BlogPost } from "../../types";
4
+ import BlogCard from "../BlogCard.astro";
5
+
6
+ interface Props extends BlogListProps {}
7
+
8
+ const { posts, blogBase, dateLocale, t } = Astro.props;
9
+ ---
10
+
11
+ <div class="grid">
12
+ {posts.map((post: BlogPost) => (
13
+ <BlogCard
14
+ post={post}
15
+ blogBase={blogBase}
16
+ dateLocale={dateLocale}
17
+ ctaText={t.blog.btncta}
18
+ variant="grid"
19
+ />
20
+ ))}
21
+ </div>
22
+
23
+ <style>
24
+ .grid {
25
+ display: grid;
26
+ grid-template-columns: 1fr;
27
+ gap: 1.5rem;
28
+ margin-bottom: 4rem;
29
+ }
30
+
31
+ @media (min-width: 640px) {
32
+ .grid {
33
+ grid-template-columns: repeat(2, 1fr);
34
+ }
35
+ }
36
+
37
+ @media (min-width: 1024px) {
38
+ .grid {
39
+ grid-template-columns: repeat(3, 1fr);
40
+ }
41
+ }
42
+ </style>
@@ -0,0 +1,30 @@
1
+ ---
2
+ import type { BlogListProps } from "../../types";
3
+ import type { BlogPost } from "../../types";
4
+ import BlogCard from "../BlogCard.astro";
5
+
6
+ interface Props extends BlogListProps {}
7
+
8
+ const { posts, blogBase, dateLocale, t } = Astro.props;
9
+ ---
10
+
11
+ <div class="list">
12
+ {posts.map((post: BlogPost) => (
13
+ <BlogCard
14
+ post={post}
15
+ blogBase={blogBase}
16
+ dateLocale={dateLocale}
17
+ ctaText={t.blog.btncta}
18
+ variant="list"
19
+ />
20
+ ))}
21
+ </div>
22
+
23
+ <style>
24
+ .list {
25
+ display: flex;
26
+ flex-direction: column;
27
+ gap: 1.25rem;
28
+ margin-bottom: 4rem;
29
+ }
30
+ </style>
@@ -0,0 +1,60 @@
1
+ ---
2
+ import type { BlogListProps } from "../../types";
3
+ import type { BlogPost } from "../../types";
4
+ import BlogCard from "../BlogCard.astro";
5
+
6
+ interface Props extends BlogListProps {}
7
+
8
+ const { posts, blogBase, dateLocale, t } = Astro.props;
9
+
10
+ const featured = posts[0] as BlogPost | undefined;
11
+ const rest = posts.slice(1) as BlogPost[];
12
+ ---
13
+
14
+ <div class="magazine">
15
+
16
+ {featured && (
17
+ <BlogCard
18
+ post={featured}
19
+ blogBase={blogBase}
20
+ dateLocale={dateLocale}
21
+ ctaText={t.blog.btncta}
22
+ variant="featured"
23
+ />
24
+ )}
25
+
26
+ <div class="magazine__right">
27
+ {rest.map((post: BlogPost) => (
28
+ <BlogCard
29
+ post={post}
30
+ blogBase={blogBase}
31
+ dateLocale={dateLocale}
32
+ ctaText={t.blog.btncta}
33
+ variant="small"
34
+ />
35
+ ))}
36
+ </div>
37
+
38
+ </div>
39
+
40
+ <style>
41
+ .magazine {
42
+ display: grid;
43
+ grid-template-columns: 1fr;
44
+ gap: 1.5rem;
45
+ margin-bottom: 4rem;
46
+ }
47
+
48
+ @media (min-width: 1024px) {
49
+ .magazine {
50
+ grid-template-columns: 1.2fr 1fr;
51
+ align-items: start;
52
+ }
53
+ }
54
+
55
+ .magazine__right {
56
+ display: flex;
57
+ flex-direction: column;
58
+ gap: 1rem;
59
+ }
60
+ </style>
@@ -0,0 +1,7 @@
1
+ // ─────────────────────────────────────────────────────────────
2
+ // astro-blog-kit · components/BlogList/index.ts
3
+ // ─────────────────────────────────────────────────────────────
4
+
5
+ export { default as MagazineLayout } from "./MagazineLayout.astro";
6
+ export { default as GridLayout } from "./GridLayout.astro";
7
+ export { default as ListLayout } from "./ListLayout.astro";
@@ -0,0 +1,136 @@
1
+ ---
2
+ import type { BlogListProps } from "../types";
3
+ import { getDateLocale, getBlogBase } from "../utils/i18n";
4
+ import MagazineLayout from "./BlogList/MagazineLayout.astro";
5
+ import GridLayout from "./BlogList/GridLayout.astro";
6
+ import ListLayout from "./BlogList/ListLayout.astro";
7
+ import Pagination from "./Pagination.astro";
8
+
9
+ interface Props extends BlogListProps {}
10
+
11
+ const {
12
+ posts,
13
+ currentPage,
14
+ totalPages,
15
+ basePath,
16
+ t,
17
+ locale,
18
+ layout = "magazine",
19
+ } = Astro.props;
20
+
21
+ const dateLocale = getDateLocale(locale);
22
+ const base = (import.meta as any).env?.BASE_URL ?? "/";
23
+ const blogBase = getBlogBase(locale, base);
24
+ ---
25
+
26
+ <section class="blog">
27
+ <div class="blog__container">
28
+
29
+ <div class="blog__header">
30
+ <div class="blog__badge">{t.blog.tagline}</div>
31
+ <h1 class="blog__title">
32
+ {t.blog.title_line1}
33
+ <span class="blog__title-highlight">{t.blog.title_line2}</span>
34
+ </h1>
35
+ <p class="blog__desc">{t.blog.description}</p>
36
+ </div>
37
+
38
+ {layout === "magazine" && (
39
+ <MagazineLayout
40
+ posts={posts}
41
+ currentPage={currentPage}
42
+ totalPages={totalPages}
43
+ basePath={basePath}
44
+ blogBase={blogBase}
45
+ dateLocale={dateLocale}
46
+ t={t}
47
+ locale={locale}
48
+ />
49
+ )}
50
+
51
+ {layout === "grid" && (
52
+ <GridLayout
53
+ posts={posts}
54
+ currentPage={currentPage}
55
+ totalPages={totalPages}
56
+ basePath={basePath}
57
+ blogBase={blogBase}
58
+ dateLocale={dateLocale}
59
+ t={t}
60
+ locale={locale}
61
+ />
62
+ )}
63
+
64
+ {layout === "list" && (
65
+ <ListLayout
66
+ posts={posts}
67
+ currentPage={currentPage}
68
+ totalPages={totalPages}
69
+ basePath={basePath}
70
+ blogBase={blogBase}
71
+ dateLocale={dateLocale}
72
+ t={t}
73
+ locale={locale}
74
+ />
75
+ )}
76
+
77
+ <Pagination
78
+ currentPage={currentPage}
79
+ totalPages={totalPages}
80
+ basePath={basePath}
81
+ blogBase={blogBase}
82
+ t={t}
83
+ />
84
+
85
+ </div>
86
+ </section>
87
+
88
+ <style>
89
+ .blog {
90
+ background-color: var(--color-white);
91
+ padding: 6rem 1rem;
92
+ min-height: 100vh;
93
+ }
94
+
95
+ .blog__container {
96
+ max-width: var(--container-max);
97
+ margin-inline: auto;
98
+ }
99
+
100
+ .blog__header {
101
+ margin-bottom: 4rem;
102
+ max-width: 48rem;
103
+ }
104
+
105
+ .blog__badge {
106
+ display: inline-block;
107
+ background-color: var(--color-yellow);
108
+ color: var(--color-black);
109
+ font-size: 0.7rem;
110
+ font-weight: 700;
111
+ text-transform: uppercase;
112
+ letter-spacing: 0.2em;
113
+ padding: 0.35rem 1rem;
114
+ margin-bottom: 1.5rem;
115
+ }
116
+
117
+ .blog__title {
118
+ font-size: clamp(3rem, 8vw, 5rem);
119
+ font-weight: 700;
120
+ color: var(--color-black);
121
+ line-height: 1;
122
+ margin-bottom: 1rem;
123
+ }
124
+
125
+ .blog__title-highlight {
126
+ background-color: var(--color-black);
127
+ color: var(--color-yellow);
128
+ padding: 0 0.3rem;
129
+ }
130
+
131
+ .blog__desc {
132
+ color: var(--color-gray-600);
133
+ font-size: 1.1rem;
134
+ line-height: 1.7;
135
+ }
136
+ </style>