wpheadless-lib 1.0.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.
- package/dist/api/categories.d.ts +29 -0
- package/dist/api/categories.js +91 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.js +6 -0
- package/dist/api/mappers.d.ts +5 -0
- package/dist/api/mappers.js +30 -0
- package/dist/api/posts.d.ts +44 -0
- package/dist/api/posts.js +104 -0
- package/dist/api/translations.d.ts +16 -0
- package/dist/api/translations.js +28 -0
- package/dist/api/types.d.ts +30 -0
- package/dist/api/types.js +1 -0
- package/dist/api/wpClient.d.ts +31 -0
- package/dist/api/wpClient.js +23 -0
- package/dist/app/config.d.ts +5 -0
- package/dist/app/config.js +28 -0
- package/dist/app/globals.css +326 -0
- package/dist/base/category/index.d.ts +38 -0
- package/dist/base/category/index.js +104 -0
- package/dist/base/category/pagination.d.ts +44 -0
- package/dist/base/category/pagination.js +114 -0
- package/dist/base/home/index.d.ts +13 -0
- package/dist/base/home/index.js +20 -0
- package/dist/base/home/pagination.d.ts +36 -0
- package/dist/base/home/pagination.js +83 -0
- package/dist/base/index.d.ts +7 -0
- package/dist/base/index.js +7 -0
- package/dist/base/layout/RootLayoutBase.d.ts +22 -0
- package/dist/base/layout/RootLayoutBase.js +15 -0
- package/dist/base/legal/index.d.ts +31 -0
- package/dist/base/legal/index.js +167 -0
- package/dist/base/post/index.d.ts +31 -0
- package/dist/base/post/index.js +97 -0
- package/dist/components/Breadcrumbs/index.d.ts +9 -0
- package/dist/components/Breadcrumbs/index.js +11 -0
- package/dist/components/Breadcrumbs/index.module.css +39 -0
- package/dist/components/Paginator/index.d.ts +10 -0
- package/dist/components/Paginator/index.js +16 -0
- package/dist/components/Paginator/index.module.css +13 -0
- package/dist/components/Paginator/index.utils.d.ts +7 -0
- package/dist/components/Paginator/index.utils.js +19 -0
- package/dist/components/PostCard/index.d.ts +10 -0
- package/dist/components/PostCard/index.js +22 -0
- package/dist/components/PostCard/index.module.css +56 -0
- package/dist/components/PostCard/index.types.d.ts +7 -0
- package/dist/components/PostCard/index.types.js +1 -0
- package/dist/components/PostCard/index.utils.d.ts +8 -0
- package/dist/components/PostCard/index.utils.js +23 -0
- package/dist/components/index.d.ts +5 -0
- package/dist/components/index.js +5 -0
- package/dist/components/layout/Footer/index.d.ts +12 -0
- package/dist/components/layout/Footer/index.js +36 -0
- package/dist/components/layout/Footer/index.module.css +61 -0
- package/dist/components/layout/Header/index.d.ts +13 -0
- package/dist/components/layout/Header/index.js +36 -0
- package/dist/components/layout/Header/index.module.css +48 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/yoast/index.d.ts +16 -0
- package/dist/plugins/yoast/index.js +44 -0
- package/dist/utils/hreflang.d.ts +37 -0
- package/dist/utils/hreflang.js +95 -0
- package/dist/utils/html.d.ts +4 -0
- package/dist/utils/html.js +8 -0
- package/dist/utils/i18n.d.ts +12 -0
- package/dist/utils/i18n.js +161 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/routing.d.ts +40 -0
- package/dist/utils/routing.js +84 -0
- package/dist/utils/seo.d.ts +75 -0
- package/dist/utils/seo.js +97 -0
- package/dist/utils/sitemap.d.ts +26 -0
- package/dist/utils/sitemap.js +327 -0
- package/dist/views/CategoryListView/index.d.ts +12 -0
- package/dist/views/CategoryListView/index.js +17 -0
- package/dist/views/CategoryListView/index.module.css +39 -0
- package/dist/views/CategoryListView/index.utils.d.ts +5 -0
- package/dist/views/CategoryListView/index.utils.js +14 -0
- package/dist/views/CategoryPaginationView/index.d.ts +13 -0
- package/dist/views/CategoryPaginationView/index.js +18 -0
- package/dist/views/CategoryPaginationView/index.module.css +39 -0
- package/dist/views/CategoryPaginationView/index.utils.d.ts +5 -0
- package/dist/views/CategoryPaginationView/index.utils.js +4 -0
- package/dist/views/HomePaginationView/index.d.ts +13 -0
- package/dist/views/HomePaginationView/index.js +9 -0
- package/dist/views/HomePaginationView/index.module.css +38 -0
- package/dist/views/HomePaginationView/index.utils.d.ts +7 -0
- package/dist/views/HomePaginationView/index.utils.js +10 -0
- package/dist/views/HomeView/index.d.ts +13 -0
- package/dist/views/HomeView/index.js +21 -0
- package/dist/views/HomeView/index.module.css +78 -0
- package/dist/views/HomeView/index.utils.d.ts +23 -0
- package/dist/views/HomeView/index.utils.js +44 -0
- package/dist/views/LegalPageView/index.d.ts +8 -0
- package/dist/views/LegalPageView/index.js +12 -0
- package/dist/views/LegalPageView/index.module.css +39 -0
- package/dist/views/LegalPageView/index.utils.d.ts +11 -0
- package/dist/views/LegalPageView/index.utils.js +16 -0
- package/dist/views/PostView/index.d.ts +10 -0
- package/dist/views/PostView/index.js +26 -0
- package/dist/views/PostView/index.module.css +80 -0
- package/dist/views/PostView/index.types.d.ts +2 -0
- package/dist/views/PostView/index.types.js +1 -0
- package/dist/views/PostView/index.utils.d.ts +15 -0
- package/dist/views/PostView/index.utils.js +22 -0
- package/dist/views/index.d.ts +6 -0
- package/dist/views/index.js +6 -0
- package/package.json +45 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
/* Spacing */
|
|
3
|
+
--container-width: 1200px;
|
|
4
|
+
--spacing-xs: 0.5rem;
|
|
5
|
+
--spacing-sm: 1rem;
|
|
6
|
+
--spacing-md: 1.5rem;
|
|
7
|
+
--spacing-lg: 2rem;
|
|
8
|
+
--spacing-xl: 3rem;
|
|
9
|
+
|
|
10
|
+
/* Typography */
|
|
11
|
+
--font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Roboto",
|
|
12
|
+
"Helvetica Neue", Arial, sans-serif;
|
|
13
|
+
--font-display: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
|
|
14
|
+
|
|
15
|
+
/* Transitions */
|
|
16
|
+
--transition: all 0.2s ease;
|
|
17
|
+
|
|
18
|
+
/* Colors - Light theme (default) */
|
|
19
|
+
--primary: #2563eb;
|
|
20
|
+
--primary-hover: #1d4ed8;
|
|
21
|
+
--secondary: #64748b;
|
|
22
|
+
--background: #ffffff;
|
|
23
|
+
--background-alt: #f8fafc;
|
|
24
|
+
--foreground: #0f172a;
|
|
25
|
+
--foreground-light: #475569;
|
|
26
|
+
--border: #e2e8f0;
|
|
27
|
+
--card-bg: #ffffff;
|
|
28
|
+
--shadow: rgba(0, 0, 0, 0.05);
|
|
29
|
+
--shadow-hover: rgba(0, 0, 0, 0.1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Dark theme via data attribute (higher priority) */
|
|
33
|
+
:root[data-theme="dark"] {
|
|
34
|
+
--background: #0f172a;
|
|
35
|
+
--background-alt: #1e293b;
|
|
36
|
+
--foreground: #f1f5f9;
|
|
37
|
+
--foreground-light: #cbd5e1;
|
|
38
|
+
--border: #334155;
|
|
39
|
+
--card-bg: #1e293b;
|
|
40
|
+
--shadow: rgba(0, 0, 0, 0.3);
|
|
41
|
+
--shadow-hover: rgba(0, 0, 0, 0.5);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Dark theme via system preference (lower priority) */
|
|
45
|
+
@media (prefers-color-scheme: dark) {
|
|
46
|
+
:root:not([data-theme]) {
|
|
47
|
+
--background: #0f172a;
|
|
48
|
+
--background-alt: #1e293b;
|
|
49
|
+
--foreground: #f1f5f9;
|
|
50
|
+
--foreground-light: #cbd5e1;
|
|
51
|
+
--border: #334155;
|
|
52
|
+
--card-bg: #1e293b;
|
|
53
|
+
--shadow: rgba(0, 0, 0, 0.3);
|
|
54
|
+
--shadow-hover: rgba(0, 0, 0, 0.5);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
* {
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
padding: 0;
|
|
61
|
+
margin: 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
html {
|
|
65
|
+
scroll-behavior: smooth;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
html,
|
|
69
|
+
body {
|
|
70
|
+
max-width: 100vw;
|
|
71
|
+
overflow-x: hidden;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
body {
|
|
75
|
+
color: var(--foreground);
|
|
76
|
+
background: var(--background);
|
|
77
|
+
font-family: var(--font-sans);
|
|
78
|
+
-webkit-font-smoothing: antialiased;
|
|
79
|
+
-moz-osx-font-smoothing: grayscale;
|
|
80
|
+
line-height: 1.6;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Typography */
|
|
84
|
+
h1,
|
|
85
|
+
h2,
|
|
86
|
+
h3,
|
|
87
|
+
h4,
|
|
88
|
+
h5,
|
|
89
|
+
h6 {
|
|
90
|
+
font-family: var(--font-display);
|
|
91
|
+
font-weight: 700;
|
|
92
|
+
line-height: 1.2;
|
|
93
|
+
color: var(--foreground);
|
|
94
|
+
margin-bottom: 0.75rem;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
h1 {
|
|
98
|
+
font-size: clamp(1.75rem, 4vw, 2.5rem);
|
|
99
|
+
margin-bottom: 1rem;
|
|
100
|
+
}
|
|
101
|
+
h2 {
|
|
102
|
+
font-size: clamp(1.5rem, 3vw, 2rem);
|
|
103
|
+
margin-top: 2rem;
|
|
104
|
+
}
|
|
105
|
+
h3 {
|
|
106
|
+
font-size: clamp(1.25rem, 2.5vw, 1.5rem);
|
|
107
|
+
margin-top: 1.5rem;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
p {
|
|
111
|
+
margin-bottom: 1rem;
|
|
112
|
+
line-height: 1.7;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
a {
|
|
116
|
+
color: var(--primary);
|
|
117
|
+
text-decoration: none;
|
|
118
|
+
transition: var(--transition);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
a:hover {
|
|
122
|
+
color: var(--primary-hover);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* Post content styling */
|
|
126
|
+
.post-content h2 {
|
|
127
|
+
margin-top: 2.5rem;
|
|
128
|
+
margin-bottom: 1rem;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.post-content h3 {
|
|
132
|
+
margin-top: 2rem;
|
|
133
|
+
margin-bottom: 0.875rem;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.post-content h4,
|
|
137
|
+
.post-content h5,
|
|
138
|
+
.post-content h6 {
|
|
139
|
+
margin-top: 1.5rem;
|
|
140
|
+
margin-bottom: 0.75rem;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.post-content p {
|
|
144
|
+
margin-bottom: 1.5rem;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.post-content ul,
|
|
148
|
+
.post-content ol {
|
|
149
|
+
margin-bottom: 1.5rem;
|
|
150
|
+
padding-left: 1.5rem;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.post-content li {
|
|
154
|
+
margin-bottom: 0.5rem;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.post-content blockquote {
|
|
158
|
+
margin: 2rem 0;
|
|
159
|
+
padding-left: 1.5rem;
|
|
160
|
+
border-left: 4px solid var(--primary);
|
|
161
|
+
color: var(--foreground-light);
|
|
162
|
+
font-style: italic;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.post-content img {
|
|
166
|
+
display: block;
|
|
167
|
+
margin: 2rem auto;
|
|
168
|
+
max-width: 100%;
|
|
169
|
+
height: auto;
|
|
170
|
+
border-radius: 8px;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.post-content figure {
|
|
174
|
+
max-width: 100% !important;
|
|
175
|
+
width: auto !important;
|
|
176
|
+
margin: 2rem auto;
|
|
177
|
+
text-align: center;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.post-content figure img {
|
|
181
|
+
margin: 0 auto;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.post-content figcaption {
|
|
185
|
+
margin-top: 0.75rem;
|
|
186
|
+
font-size: 0.875rem;
|
|
187
|
+
color: var(--foreground-light);
|
|
188
|
+
font-style: italic;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.post-content pre {
|
|
192
|
+
margin: 1.5rem 0;
|
|
193
|
+
padding: 1rem;
|
|
194
|
+
background: var(--background-alt);
|
|
195
|
+
border-radius: 8px;
|
|
196
|
+
overflow-x: auto;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* Container */
|
|
200
|
+
.container {
|
|
201
|
+
width: 100%;
|
|
202
|
+
max-width: var(--container-width);
|
|
203
|
+
margin: 0 auto;
|
|
204
|
+
padding: 0 var(--spacing-md);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/* Card styling */
|
|
208
|
+
.card {
|
|
209
|
+
background: var(--card-bg);
|
|
210
|
+
border-radius: 12px;
|
|
211
|
+
overflow: hidden;
|
|
212
|
+
box-shadow: 0 1px 3px var(--shadow);
|
|
213
|
+
transition: var(--transition);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.card:hover {
|
|
217
|
+
box-shadow: 0 10px 25px var(--shadow-hover);
|
|
218
|
+
transform: translateY(-2px);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* Badge */
|
|
222
|
+
.badge {
|
|
223
|
+
display: inline-block;
|
|
224
|
+
padding: 0.25rem 0.75rem;
|
|
225
|
+
background: var(--primary);
|
|
226
|
+
color: white;
|
|
227
|
+
font-size: 0.75rem;
|
|
228
|
+
font-weight: 600;
|
|
229
|
+
border-radius: 9999px;
|
|
230
|
+
text-transform: uppercase;
|
|
231
|
+
letter-spacing: 0.05em;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/* Utilities */
|
|
235
|
+
.text-muted {
|
|
236
|
+
color: var(--foreground-light);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
a {
|
|
240
|
+
text-decoration: none;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
a.header-link {
|
|
244
|
+
color: var(--foreground);
|
|
245
|
+
font-weight: 600;
|
|
246
|
+
font-size: 0.9375rem;
|
|
247
|
+
transition: var(--transition);
|
|
248
|
+
position: relative;
|
|
249
|
+
display: inline-block;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
a.header-link::after {
|
|
253
|
+
content: "";
|
|
254
|
+
position: absolute;
|
|
255
|
+
bottom: -4px;
|
|
256
|
+
left: 0;
|
|
257
|
+
width: 0;
|
|
258
|
+
height: 2px;
|
|
259
|
+
background: var(--primary);
|
|
260
|
+
transition: width 0.3s ease;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
a.header-link:hover {
|
|
264
|
+
color: var(--primary);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
a.header-link:hover::after {
|
|
268
|
+
width: 100%;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
a.footer-link {
|
|
272
|
+
color: var(--foreground-light);
|
|
273
|
+
font-size: 0.875rem;
|
|
274
|
+
transition: var(--transition);
|
|
275
|
+
display: inline-block;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
a.footer-link:hover {
|
|
279
|
+
color: var(--primary);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
@media (prefers-color-scheme: dark) {
|
|
283
|
+
:root:not([data-theme]) {
|
|
284
|
+
color-scheme: dark;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
:root[data-theme="dark"] {
|
|
289
|
+
color-scheme: dark;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/* Paginator styles */
|
|
293
|
+
.paginator-nav,
|
|
294
|
+
.paginator-page {
|
|
295
|
+
padding: 0.625rem 1.25rem;
|
|
296
|
+
border: 1px solid var(--border);
|
|
297
|
+
border-radius: 8px;
|
|
298
|
+
background: var(--card-bg);
|
|
299
|
+
color: var(--foreground);
|
|
300
|
+
font-weight: 500;
|
|
301
|
+
font-size: 0.9375rem;
|
|
302
|
+
transition: var(--transition);
|
|
303
|
+
display: inline-flex;
|
|
304
|
+
align-items: center;
|
|
305
|
+
justify-content: center;
|
|
306
|
+
min-width: 44px;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
.paginator-nav:hover,
|
|
310
|
+
.paginator-page:hover {
|
|
311
|
+
border-color: var(--primary);
|
|
312
|
+
background: var(--background-alt);
|
|
313
|
+
color: var(--primary);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.paginator-page.paginator-active {
|
|
317
|
+
background: var(--primary);
|
|
318
|
+
color: white;
|
|
319
|
+
border-color: var(--primary);
|
|
320
|
+
font-weight: 600;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.paginator-page.paginator-active:hover {
|
|
324
|
+
background: var(--primary-hover);
|
|
325
|
+
color: white;
|
|
326
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type WPCategory, type WPPost } from "wpjsapi-lib";
|
|
2
|
+
import type { Metadata } from "next";
|
|
3
|
+
type CategoryStaticParamsInput = {
|
|
4
|
+
baseApiUrl: string;
|
|
5
|
+
lang: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function getCategoryStaticParams({ baseApiUrl, lang, }: CategoryStaticParamsInput): Promise<Array<{
|
|
8
|
+
category: string;
|
|
9
|
+
}>>;
|
|
10
|
+
export declare function fetchCategory({ baseApiUrl, slug, lang, }: {
|
|
11
|
+
baseApiUrl: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
lang: string;
|
|
14
|
+
}): Promise<WPCategory | null>;
|
|
15
|
+
export declare function fetchCategoryPosts({ baseApiUrl, categoryId, perPage, langId, }: {
|
|
16
|
+
baseApiUrl: string;
|
|
17
|
+
categoryId: number;
|
|
18
|
+
perPage: number;
|
|
19
|
+
langId: string;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
posts: WPPost[];
|
|
22
|
+
totalPages: number;
|
|
23
|
+
}>;
|
|
24
|
+
export declare function fetchCategoryByTranslationKey({ baseApiUrl, translationKey, lang, }: {
|
|
25
|
+
baseApiUrl: string;
|
|
26
|
+
translationKey: string;
|
|
27
|
+
lang: string;
|
|
28
|
+
}): Promise<WPCategory | null>;
|
|
29
|
+
export declare function buildCategoryMetadata({ category, canonical, useYoast, siteName, languages, siteUrl, wpApiUrl, }: {
|
|
30
|
+
category: WPCategory;
|
|
31
|
+
canonical: string;
|
|
32
|
+
useYoast?: boolean;
|
|
33
|
+
siteName?: string;
|
|
34
|
+
languages?: Record<string, string>;
|
|
35
|
+
siteUrl?: string;
|
|
36
|
+
wpApiUrl?: string;
|
|
37
|
+
}): Metadata;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { getPlainTextExcerpt } from "../../utils";
|
|
2
|
+
import { withXDefault } from "../../utils/hreflang";
|
|
3
|
+
import { extractYoastMetadata } from "../../plugins/yoast";
|
|
4
|
+
import { getCategoryByTranslationKey, getCategoryBySlug, listCategoryPosts, listCategoryStaticParams, } from "../../api/categories";
|
|
5
|
+
export async function getCategoryStaticParams({ baseApiUrl, lang, }) {
|
|
6
|
+
const result = await listCategoryStaticParams({
|
|
7
|
+
baseApiUrl,
|
|
8
|
+
lang,
|
|
9
|
+
});
|
|
10
|
+
if (!result.ok || !result.data) {
|
|
11
|
+
if (result.error) {
|
|
12
|
+
console.error("Error generando rutas estáticas de categorías:", result.error);
|
|
13
|
+
}
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return result.data;
|
|
17
|
+
}
|
|
18
|
+
export async function fetchCategory({ baseApiUrl, slug, lang, }) {
|
|
19
|
+
const result = await getCategoryBySlug({
|
|
20
|
+
baseApiUrl,
|
|
21
|
+
slug,
|
|
22
|
+
lang,
|
|
23
|
+
});
|
|
24
|
+
if (!result.ok) {
|
|
25
|
+
if (result.error)
|
|
26
|
+
console.error("Error obteniendo categoría:", result.error);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return result.data;
|
|
30
|
+
}
|
|
31
|
+
export async function fetchCategoryPosts({ baseApiUrl, categoryId, perPage, langId, }) {
|
|
32
|
+
const result = await listCategoryPosts({
|
|
33
|
+
baseApiUrl,
|
|
34
|
+
categoryId,
|
|
35
|
+
perPage,
|
|
36
|
+
langId,
|
|
37
|
+
});
|
|
38
|
+
if (!result.ok || !result.data) {
|
|
39
|
+
if (result.error)
|
|
40
|
+
console.error("Error obteniendo posts de la categoría:", result.error);
|
|
41
|
+
return { posts: [], totalPages: 0 };
|
|
42
|
+
}
|
|
43
|
+
return result.data;
|
|
44
|
+
}
|
|
45
|
+
export async function fetchCategoryByTranslationKey({ baseApiUrl, translationKey, lang, }) {
|
|
46
|
+
const result = await getCategoryByTranslationKey({
|
|
47
|
+
baseApiUrl,
|
|
48
|
+
translationKey,
|
|
49
|
+
lang,
|
|
50
|
+
});
|
|
51
|
+
if (!result.ok) {
|
|
52
|
+
if (result.error)
|
|
53
|
+
console.error("Error obteniendo categoría por translation key:", result.error);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return result.data;
|
|
57
|
+
}
|
|
58
|
+
export function buildCategoryMetadata({ category, canonical, useYoast = true, siteName, languages, siteUrl, wpApiUrl, }) {
|
|
59
|
+
const fallbackDescription = getPlainTextExcerpt(category.description, 160);
|
|
60
|
+
const languageAlternates = withXDefault(languages);
|
|
61
|
+
const fallbackMetadata = {
|
|
62
|
+
title: category.name,
|
|
63
|
+
description: fallbackDescription,
|
|
64
|
+
alternates: {
|
|
65
|
+
canonical,
|
|
66
|
+
...(languageAlternates ? { languages: languageAlternates } : {}),
|
|
67
|
+
},
|
|
68
|
+
openGraph: {
|
|
69
|
+
title: category.name,
|
|
70
|
+
description: fallbackDescription,
|
|
71
|
+
url: canonical,
|
|
72
|
+
siteName,
|
|
73
|
+
type: "website",
|
|
74
|
+
},
|
|
75
|
+
twitter: {
|
|
76
|
+
card: "summary_large_image",
|
|
77
|
+
title: category.name,
|
|
78
|
+
description: fallbackDescription,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
if (!useYoast)
|
|
82
|
+
return fallbackMetadata;
|
|
83
|
+
const meta = extractYoastMetadata(category, {
|
|
84
|
+
url: canonical,
|
|
85
|
+
title: category.name,
|
|
86
|
+
description: fallbackDescription,
|
|
87
|
+
siteName,
|
|
88
|
+
}, { siteUrl, wpApiUrl });
|
|
89
|
+
if (!meta)
|
|
90
|
+
return fallbackMetadata;
|
|
91
|
+
return {
|
|
92
|
+
...meta,
|
|
93
|
+
alternates: {
|
|
94
|
+
...(meta.alternates || {}),
|
|
95
|
+
canonical,
|
|
96
|
+
...(languageAlternates ? { languages: languageAlternates } : {}),
|
|
97
|
+
},
|
|
98
|
+
openGraph: {
|
|
99
|
+
...meta.openGraph,
|
|
100
|
+
url: canonical,
|
|
101
|
+
siteName: meta.openGraph?.siteName || siteName,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type WPCategory, type WPPost } from "wpjsapi-lib";
|
|
2
|
+
import type { Metadata } from "next";
|
|
3
|
+
type CategoryStaticParamsInput = {
|
|
4
|
+
baseApiUrl: string;
|
|
5
|
+
perPage: number;
|
|
6
|
+
lang: string;
|
|
7
|
+
langId: string;
|
|
8
|
+
};
|
|
9
|
+
type CategoryStaticParam = {
|
|
10
|
+
category: string;
|
|
11
|
+
page: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function getCategoryPaginationStaticParams({ baseApiUrl, perPage, lang, langId, }: CategoryStaticParamsInput): Promise<CategoryStaticParam[]>;
|
|
14
|
+
export declare function fetchCategoryBySlug({ baseApiUrl, slug, lang, }: {
|
|
15
|
+
baseApiUrl: string;
|
|
16
|
+
slug: string;
|
|
17
|
+
lang: string;
|
|
18
|
+
}): Promise<WPCategory | null>;
|
|
19
|
+
export declare function fetchCategoryPaginatedPosts({ baseApiUrl, categoryId, page, perPage, langId, }: {
|
|
20
|
+
baseApiUrl: string;
|
|
21
|
+
categoryId: number;
|
|
22
|
+
page: number;
|
|
23
|
+
perPage: number;
|
|
24
|
+
langId: string;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
posts: WPPost[];
|
|
27
|
+
totalPages: number;
|
|
28
|
+
error: string | null;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function getCategoryTotalPages({ baseApiUrl, categoryId, perPage, langId, }: {
|
|
31
|
+
baseApiUrl: string;
|
|
32
|
+
categoryId: number;
|
|
33
|
+
perPage: number;
|
|
34
|
+
langId: string;
|
|
35
|
+
}): Promise<number>;
|
|
36
|
+
export declare function buildCategoryPaginationMetadata({ category, canonicalBaseUrl, currentPage, useYoast, siteName, languages, }: {
|
|
37
|
+
category: WPCategory;
|
|
38
|
+
canonicalBaseUrl: string;
|
|
39
|
+
currentPage: number;
|
|
40
|
+
useYoast?: boolean;
|
|
41
|
+
siteName?: string;
|
|
42
|
+
languages?: Record<string, string>;
|
|
43
|
+
}): Metadata;
|
|
44
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { buildCategoryMetadata } from "./index";
|
|
2
|
+
import { createWpClient } from "../../api/wpClient";
|
|
3
|
+
import { getPostsTotalPages, listPostsWithEmbeds } from "../../api/posts";
|
|
4
|
+
import { mapCategoryEntity } from "../../api/mappers";
|
|
5
|
+
import { getCategoryBySlug as getCategoryBySlugApi } from "../../api/categories";
|
|
6
|
+
import { ensureTrailingSlash } from "../../utils";
|
|
7
|
+
export async function getCategoryPaginationStaticParams({ baseApiUrl, perPage, lang, langId, }) {
|
|
8
|
+
const { categoriesApi } = createWpClient({
|
|
9
|
+
baseUrl: baseApiUrl,
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
const categories = await categoriesApi.listAll({ lang });
|
|
13
|
+
const paths = [];
|
|
14
|
+
for (const category of categories) {
|
|
15
|
+
const totalPagesResult = await getPostsTotalPages({
|
|
16
|
+
baseApiUrl,
|
|
17
|
+
perPage,
|
|
18
|
+
langId,
|
|
19
|
+
categories: [category.id],
|
|
20
|
+
});
|
|
21
|
+
if (!totalPagesResult.ok && totalPagesResult.error) {
|
|
22
|
+
console.error("Error obteniendo total de páginas de la categoría:", totalPagesResult.error);
|
|
23
|
+
}
|
|
24
|
+
const totalPages = totalPagesResult.ok && totalPagesResult.data
|
|
25
|
+
? totalPagesResult.data
|
|
26
|
+
: 0;
|
|
27
|
+
for (let page = 2; page <= totalPages; page++) {
|
|
28
|
+
paths.push({
|
|
29
|
+
category: category.slug,
|
|
30
|
+
page: String(page),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return paths;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error("Error generando rutas de paginación de categorías:", error);
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function fetchCategoryBySlug({ baseApiUrl, slug, lang, }) {
|
|
42
|
+
const result = await getCategoryBySlugApi({
|
|
43
|
+
baseApiUrl,
|
|
44
|
+
slug,
|
|
45
|
+
lang,
|
|
46
|
+
});
|
|
47
|
+
if (!result.ok) {
|
|
48
|
+
if (result.error)
|
|
49
|
+
console.error("Error obteniendo categoría:", result.error);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return result.data;
|
|
53
|
+
}
|
|
54
|
+
export async function fetchCategoryPaginatedPosts({ baseApiUrl, categoryId, page, perPage, langId, }) {
|
|
55
|
+
try {
|
|
56
|
+
const response = await listPostsWithEmbeds({
|
|
57
|
+
baseApiUrl,
|
|
58
|
+
categories: [categoryId],
|
|
59
|
+
perPage,
|
|
60
|
+
page,
|
|
61
|
+
orderby: "date",
|
|
62
|
+
order: "desc",
|
|
63
|
+
langId,
|
|
64
|
+
});
|
|
65
|
+
if (!response.ok || !response.data) {
|
|
66
|
+
const error = response.error || "Error obteniendo posts de la categoría";
|
|
67
|
+
console.error(error);
|
|
68
|
+
return { posts: [], totalPages: 0, error };
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
posts: response.data.items,
|
|
72
|
+
totalPages: response.data.pagination.totalPages,
|
|
73
|
+
error: null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
console.error("Error obteniendo posts de la categoría:", error);
|
|
78
|
+
return {
|
|
79
|
+
posts: [],
|
|
80
|
+
totalPages: 0,
|
|
81
|
+
error: error instanceof Error ? error.message : "Error desconocido",
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export async function getCategoryTotalPages({ baseApiUrl, categoryId, perPage, langId, }) {
|
|
86
|
+
const result = await getPostsTotalPages({
|
|
87
|
+
baseApiUrl,
|
|
88
|
+
perPage,
|
|
89
|
+
langId,
|
|
90
|
+
categories: [categoryId],
|
|
91
|
+
});
|
|
92
|
+
if (!result.ok || result.data === null) {
|
|
93
|
+
if (result.error) {
|
|
94
|
+
console.error("Error obteniendo total de páginas de la categoría:", result.error);
|
|
95
|
+
}
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
return result.data;
|
|
99
|
+
}
|
|
100
|
+
export function buildCategoryPaginationMetadata({ category, canonicalBaseUrl, currentPage, useYoast = true, siteName, languages, }) {
|
|
101
|
+
const canonical = currentPage === 1
|
|
102
|
+
? ensureTrailingSlash(canonicalBaseUrl)
|
|
103
|
+
: ensureTrailingSlash(`${canonicalBaseUrl.replace(/\/+$/, "")}/page/${currentPage}`);
|
|
104
|
+
const baseMeta = buildCategoryMetadata({
|
|
105
|
+
category: mapCategoryEntity(category).category,
|
|
106
|
+
canonical,
|
|
107
|
+
useYoast,
|
|
108
|
+
siteName,
|
|
109
|
+
languages,
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
...baseMeta,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type WPPost } from "wpjsapi-lib";
|
|
2
|
+
type FetchHomePostsParams = {
|
|
3
|
+
baseApiUrl: string;
|
|
4
|
+
perPage: number;
|
|
5
|
+
langId: string;
|
|
6
|
+
};
|
|
7
|
+
type FetchHomePostsResult = {
|
|
8
|
+
posts: WPPost[];
|
|
9
|
+
totalPages: number;
|
|
10
|
+
error: string | null;
|
|
11
|
+
};
|
|
12
|
+
export declare function fetchHomePosts({ baseApiUrl, perPage, langId, }: FetchHomePostsParams): Promise<FetchHomePostsResult>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { listPostsWithEmbeds } from "../../api/posts";
|
|
2
|
+
export async function fetchHomePosts({ baseApiUrl, perPage, langId, }) {
|
|
3
|
+
const postsResponse = await listPostsWithEmbeds({
|
|
4
|
+
perPage,
|
|
5
|
+
baseApiUrl,
|
|
6
|
+
orderby: "date",
|
|
7
|
+
order: "desc",
|
|
8
|
+
langId,
|
|
9
|
+
});
|
|
10
|
+
if (!postsResponse.ok || !postsResponse.data) {
|
|
11
|
+
const error = postsResponse.error || "Error desconocido";
|
|
12
|
+
console.error("Error obteniendo posts:", error);
|
|
13
|
+
return { posts: [], totalPages: 0, error };
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
posts: postsResponse.data.items,
|
|
17
|
+
totalPages: postsResponse.data.pagination.totalPages,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type WPPost } from "wpjsapi-lib";
|
|
2
|
+
import type { Metadata } from "next";
|
|
3
|
+
type StaticParamsInput = {
|
|
4
|
+
baseApiUrl: string;
|
|
5
|
+
perPage: number;
|
|
6
|
+
langId: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function getHomePaginationStaticParams({ baseApiUrl, perPage, langId, }: StaticParamsInput): Promise<Array<{
|
|
9
|
+
page: string;
|
|
10
|
+
}>>;
|
|
11
|
+
export declare function getHomeTotalPages({ baseApiUrl, perPage, langId, }: {
|
|
12
|
+
baseApiUrl: string;
|
|
13
|
+
perPage: number;
|
|
14
|
+
langId: string;
|
|
15
|
+
}): Promise<number>;
|
|
16
|
+
type FetchPaginatedPostsInput = {
|
|
17
|
+
baseApiUrl: string;
|
|
18
|
+
perPage: number;
|
|
19
|
+
page: number;
|
|
20
|
+
langId: string;
|
|
21
|
+
};
|
|
22
|
+
type FetchPaginatedPostsResult = {
|
|
23
|
+
posts: WPPost[];
|
|
24
|
+
totalPages: number;
|
|
25
|
+
error: string | null;
|
|
26
|
+
};
|
|
27
|
+
export declare function fetchHomePaginatedPosts({ baseApiUrl, perPage, page, langId, }: FetchPaginatedPostsInput): Promise<FetchPaginatedPostsResult>;
|
|
28
|
+
export declare function buildHomePaginationMetadata({ translator, currentPage, canonicalBase, posts, siteName, languages, }: {
|
|
29
|
+
translator: (key: string, vars?: Record<string, string | number>) => string;
|
|
30
|
+
currentPage: number;
|
|
31
|
+
canonicalBase: string;
|
|
32
|
+
posts: WPPost[];
|
|
33
|
+
siteName?: string;
|
|
34
|
+
languages?: Record<string, string>;
|
|
35
|
+
}): Metadata;
|
|
36
|
+
export {};
|