wpheadless-lib 1.1.12 → 1.1.15
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/base/legal/index.js +7 -6
- package/dist/components/LanguageLinks/index.d.ts +15 -0
- package/dist/components/LanguageLinks/index.js +12 -0
- package/dist/components/LanguageLinks/index.module.css +78 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +1 -0
- package/dist/utils/hreflang.d.ts +6 -0
- package/dist/utils/hreflang.js +27 -0
- package/dist/utils/html.d.ts +5 -3
- package/dist/utils/html.js +48 -0
- package/dist/utils/i18n.js +6 -0
- package/dist/utils/language.d.ts +2 -0
- package/dist/utils/sitemap.js +27 -17
- package/dist/views/CategoryListView/index.d.ts +3 -1
- package/dist/views/CategoryListView/index.js +3 -3
- package/dist/views/HomeView/index.d.ts +3 -1
- package/dist/views/HomeView/index.js +3 -2
- package/dist/views/LegalPageView/index.d.ts +5 -1
- package/dist/views/LegalPageView/index.js +3 -3
- package/dist/views/PostView/index.d.ts +5 -1
- package/dist/views/PostView/index.js +9 -4
- package/package.json +1 -1
package/dist/base/legal/index.js
CHANGED
|
@@ -8,13 +8,14 @@ async function getLegalParentId(baseApiUrl, lang, langId) {
|
|
|
8
8
|
return null;
|
|
9
9
|
const pagesApi = createPageEndpoints({ baseUrl: baseApiUrl });
|
|
10
10
|
try {
|
|
11
|
-
const parent = await pagesApi.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
_fields: ["id", "language", "taxonomies", "meta"],
|
|
11
|
+
const parent = await pagesApi.listAll({
|
|
12
|
+
parent: 0,
|
|
13
|
+
translation_key_v2: "legal",
|
|
14
|
+
_fields: ["id", "slug", "language", "taxonomies", "meta"],
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const parentItems = parent.filter((item) => getTranslationKey(item) === "legal");
|
|
17
|
+
const match = parentItems.find((p) => langId && getEntityLanguageId(p)?.toString() === langId.toString());
|
|
18
|
+
return (match ?? parentItems[0])?.id ?? null;
|
|
18
19
|
}
|
|
19
20
|
catch (error) {
|
|
20
21
|
console.error("Error obteniendo página padre legal:", error);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Locale } from "../../utils/index.js";
|
|
2
|
+
export type LanguageLink = {
|
|
3
|
+
code: string;
|
|
4
|
+
label: string;
|
|
5
|
+
href: string;
|
|
6
|
+
current?: boolean;
|
|
7
|
+
};
|
|
8
|
+
type LanguageLinksProps = {
|
|
9
|
+
links?: LanguageLink[];
|
|
10
|
+
label?: string;
|
|
11
|
+
locale?: Locale;
|
|
12
|
+
className?: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function LanguageLinks({ links, label, locale, className, }: LanguageLinksProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Link from "next/link";
|
|
3
|
+
import styles from "./index.module.css";
|
|
4
|
+
import { getTranslator } from "../../utils/index.js";
|
|
5
|
+
export function LanguageLinks({ links, label, locale, className, }) {
|
|
6
|
+
const visibleLinks = links?.filter((link) => link.href) ?? [];
|
|
7
|
+
if (visibleLinks.length < 2)
|
|
8
|
+
return null;
|
|
9
|
+
const t = getTranslator(locale);
|
|
10
|
+
const resolvedLabel = label ?? t("language.available");
|
|
11
|
+
return (_jsxs("nav", { "aria-label": resolvedLabel, className: [styles.languageLinks, className].filter(Boolean).join(" "), children: [_jsx("span", { className: styles.label, children: resolvedLabel }), _jsx("ul", { className: styles.list, children: visibleLinks.map((link) => (_jsx("li", { children: link.current ? (_jsx("span", { className: `${styles.link} ${styles.current}`, "aria-current": "page", lang: link.code, children: link.label })) : (_jsx(Link, { href: link.href, className: styles.link, hrefLang: link.code, children: link.label })) }, link.code))) })] }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
.languageLinks {
|
|
2
|
+
display: flex;
|
|
3
|
+
align-items: center;
|
|
4
|
+
gap: 0.6rem;
|
|
5
|
+
max-width: 100%;
|
|
6
|
+
margin: 1.25rem 0;
|
|
7
|
+
padding: 0.8rem 0.9rem;
|
|
8
|
+
border: 1px solid var(--border);
|
|
9
|
+
border-radius: 8px;
|
|
10
|
+
background: var(--background-alt);
|
|
11
|
+
color: var(--foreground-light);
|
|
12
|
+
font-size: 0.875rem;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.label {
|
|
16
|
+
flex: 0 0 auto;
|
|
17
|
+
font-weight: 650;
|
|
18
|
+
color: var(--foreground);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.list {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-wrap: wrap;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: 0.4rem;
|
|
26
|
+
min-width: 0;
|
|
27
|
+
margin: 0;
|
|
28
|
+
padding: 0;
|
|
29
|
+
list-style: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.link {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
min-height: 2rem;
|
|
36
|
+
padding: 0.34rem 0.7rem;
|
|
37
|
+
border: 1px solid var(--border);
|
|
38
|
+
border-radius: 999px;
|
|
39
|
+
background: var(--background);
|
|
40
|
+
color: var(--foreground);
|
|
41
|
+
font-size: 0.82rem;
|
|
42
|
+
font-weight: 650;
|
|
43
|
+
line-height: 1;
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.link:hover {
|
|
49
|
+
color: var(--primary);
|
|
50
|
+
border-color: var(--primary);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.link[aria-current="page"] {
|
|
54
|
+
background: var(--foreground);
|
|
55
|
+
border-color: var(--foreground);
|
|
56
|
+
color: var(--background);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.current {
|
|
60
|
+
cursor: default;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.current:hover {
|
|
64
|
+
color: var(--background);
|
|
65
|
+
border-color: var(--foreground);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@media (max-width: 640px) {
|
|
69
|
+
.languageLinks {
|
|
70
|
+
align-items: flex-start;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
gap: 0.45rem;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.list {
|
|
76
|
+
width: 100%;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -4,3 +4,5 @@ export { default as Paginator } from "./Paginator/index.js";
|
|
|
4
4
|
export { default as PostCard } from "./PostCard/index.js";
|
|
5
5
|
export { Breadcrumbs } from "./Breadcrumbs/index.js";
|
|
6
6
|
export { JsonLd } from "./JsonLd.js";
|
|
7
|
+
export { LanguageLinks } from "./LanguageLinks/index.js";
|
|
8
|
+
export type { LanguageLink } from "./LanguageLinks/index.js";
|
package/dist/components/index.js
CHANGED
|
@@ -4,3 +4,4 @@ export { default as Paginator } from "./Paginator/index.js";
|
|
|
4
4
|
export { default as PostCard } from "./PostCard/index.js";
|
|
5
5
|
export { Breadcrumbs } from "./Breadcrumbs/index.js";
|
|
6
6
|
export { JsonLd } from "./JsonLd.js";
|
|
7
|
+
export { LanguageLinks } from "./LanguageLinks/index.js";
|
package/dist/utils/hreflang.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type SiteLanguage, type SiteLanguageInput } from "./language.js";
|
|
2
|
+
import type { LanguageLink } from "../components/index.js";
|
|
2
3
|
export type LanguageConfig = SiteLanguageInput;
|
|
3
4
|
export declare function getHreflangCode(language: Pick<SiteLanguageInput, "code">): string;
|
|
4
5
|
export declare function getTranslationKey(entity: unknown): string | undefined;
|
|
@@ -32,4 +33,9 @@ export declare function buildAbsoluteLangUrl({ basePath, path, siteUrl, }: {
|
|
|
32
33
|
siteUrl?: string;
|
|
33
34
|
}): string;
|
|
34
35
|
export declare function withXDefault(languages?: Record<string, string>): Record<string, string> | undefined;
|
|
36
|
+
export declare function buildLanguageLinks({ languages, alternates, currentCode, }: {
|
|
37
|
+
languages: LanguageConfig[];
|
|
38
|
+
alternates?: Record<string, string>;
|
|
39
|
+
currentCode?: string;
|
|
40
|
+
}): LanguageLink[];
|
|
35
41
|
export {};
|
package/dist/utils/hreflang.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { getAbsoluteUrl } from "./routing.js";
|
|
2
2
|
import { normalizeLanguages, shouldRenderLanguageAlternates, } from "./language.js";
|
|
3
|
+
const languageLabels = {
|
|
4
|
+
en: "English",
|
|
5
|
+
es: "Español",
|
|
6
|
+
fr: "Français",
|
|
7
|
+
de: "Deutsch",
|
|
8
|
+
"pt-br": "Português",
|
|
9
|
+
};
|
|
3
10
|
const normalizeBasePath = (basePath) => basePath.endsWith("/") ? basePath : `${basePath}/`;
|
|
4
11
|
export function getHreflangCode(language) {
|
|
5
12
|
const [languageCode, regionCode] = language.code.split("-");
|
|
@@ -104,3 +111,23 @@ export function withXDefault(languages) {
|
|
|
104
111
|
: { ...languages };
|
|
105
112
|
return Object.keys(result).length > 1 ? result : undefined;
|
|
106
113
|
}
|
|
114
|
+
export function buildLanguageLinks({ languages, alternates, currentCode, }) {
|
|
115
|
+
if (!alternates)
|
|
116
|
+
return [];
|
|
117
|
+
return normalizeLanguages(languages)
|
|
118
|
+
.map((language) => {
|
|
119
|
+
const hreflang = getHreflangCode(language);
|
|
120
|
+
const href = alternates[hreflang];
|
|
121
|
+
if (!href)
|
|
122
|
+
return null;
|
|
123
|
+
return {
|
|
124
|
+
code: hreflang,
|
|
125
|
+
label: languageLabels[language.code] || language.locale || language.code,
|
|
126
|
+
href,
|
|
127
|
+
current: language.code === currentCode ||
|
|
128
|
+
language.locale === currentCode ||
|
|
129
|
+
hreflang === currentCode,
|
|
130
|
+
};
|
|
131
|
+
})
|
|
132
|
+
.filter((link) => Boolean(link));
|
|
133
|
+
}
|
package/dist/utils/html.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Remove HTML tags from a string.
|
|
3
|
-
*/
|
|
4
1
|
export declare function stripTags(html?: string): string | undefined;
|
|
5
2
|
export declare function decodeHtmlEntities(value?: string): string | undefined;
|
|
6
3
|
export declare function toPlainText(html?: string): string | undefined;
|
|
4
|
+
export declare function rewritePostContentLinks(html: string, opts?: {
|
|
5
|
+
siteUrl?: string;
|
|
6
|
+
wpApiUrl?: string;
|
|
7
|
+
basePath?: string;
|
|
8
|
+
}): string;
|
package/dist/utils/html.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Remove HTML tags from a string.
|
|
3
3
|
*/
|
|
4
|
+
import { ensureTrailingSlash, getSiteUrl } from "./routing.js";
|
|
4
5
|
export function stripTags(html) {
|
|
5
6
|
if (!html)
|
|
6
7
|
return undefined;
|
|
@@ -31,3 +32,50 @@ export function toPlainText(html) {
|
|
|
31
32
|
const decoded = decodeHtmlEntities(stripped);
|
|
32
33
|
return decoded?.replace(/\s+/g, " ").trim() || undefined;
|
|
33
34
|
}
|
|
35
|
+
const getOrigin = (url) => {
|
|
36
|
+
if (!url)
|
|
37
|
+
return null;
|
|
38
|
+
try {
|
|
39
|
+
return new URL(url).origin;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const getWpOrigin = (wpApiUrl) => {
|
|
46
|
+
if (!wpApiUrl)
|
|
47
|
+
return null;
|
|
48
|
+
return getOrigin(wpApiUrl.replace(/\/wp-json\/?$/, ""));
|
|
49
|
+
};
|
|
50
|
+
const escapeHtmlAttribute = (value) => value
|
|
51
|
+
.replace(/&/g, "&")
|
|
52
|
+
.replace(/"/g, """)
|
|
53
|
+
.replace(/</g, "<")
|
|
54
|
+
.replace(/>/g, ">");
|
|
55
|
+
const normalizePathWithBase = (basePath, pathname) => {
|
|
56
|
+
const normalizedBase = ensureTrailingSlash(basePath || "/");
|
|
57
|
+
const normalizedPath = pathname.startsWith("/") ? pathname.slice(1) : pathname;
|
|
58
|
+
return ensureTrailingSlash(`${normalizedBase}${normalizedPath}`.replace(/\/+/g, "/"));
|
|
59
|
+
};
|
|
60
|
+
export function rewritePostContentLinks(html, opts = {}) {
|
|
61
|
+
const sourceOrigin = getWpOrigin(opts.wpApiUrl);
|
|
62
|
+
const targetOrigin = getOrigin(getSiteUrl(opts.siteUrl));
|
|
63
|
+
if (!sourceOrigin || !targetOrigin || sourceOrigin === targetOrigin) {
|
|
64
|
+
return html;
|
|
65
|
+
}
|
|
66
|
+
return html.replace(/\bhref\s*=\s*(["'])(.*?)\1/gi, (match, quote, rawHref) => {
|
|
67
|
+
const decodedHref = decodeHtmlEntities(rawHref) || rawHref;
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = new URL(decodedHref);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return match;
|
|
74
|
+
}
|
|
75
|
+
if (parsed.origin !== sourceOrigin)
|
|
76
|
+
return match;
|
|
77
|
+
const path = normalizePathWithBase(opts.basePath || "/", parsed.pathname);
|
|
78
|
+
const rewritten = `${targetOrigin}${path}${parsed.search}${parsed.hash}`;
|
|
79
|
+
return `href=${quote}${escapeHtmlAttribute(rewritten)}${quote}`;
|
|
80
|
+
});
|
|
81
|
+
}
|
package/dist/utils/i18n.js
CHANGED
|
@@ -10,6 +10,9 @@ const defaultMessages = {
|
|
|
10
10
|
openMenu: "Open menu",
|
|
11
11
|
closeMenu: "Close menu",
|
|
12
12
|
},
|
|
13
|
+
language: {
|
|
14
|
+
available: "Available languages",
|
|
15
|
+
},
|
|
13
16
|
site: {
|
|
14
17
|
title: "Site title",
|
|
15
18
|
description: "Site description",
|
|
@@ -66,6 +69,9 @@ const defaultMessages = {
|
|
|
66
69
|
openMenu: "Abrir menú",
|
|
67
70
|
closeMenu: "Cerrar menú",
|
|
68
71
|
},
|
|
72
|
+
language: {
|
|
73
|
+
available: "Idiomas disponibles",
|
|
74
|
+
},
|
|
69
75
|
site: {
|
|
70
76
|
title: "Título del sitio",
|
|
71
77
|
description: "Descripción del sitio",
|
package/dist/utils/language.d.ts
CHANGED
package/dist/utils/sitemap.js
CHANGED
|
@@ -44,6 +44,9 @@ const escapeXml = (value) => value
|
|
|
44
44
|
.replace(/"/g, """)
|
|
45
45
|
.replace(/'/g, "'");
|
|
46
46
|
const renderAlternates = (alternates) => {
|
|
47
|
+
const languageKeys = Object.keys(alternates ?? {}).filter((key) => key !== "x-default");
|
|
48
|
+
if (languageKeys.length < 2)
|
|
49
|
+
return undefined;
|
|
47
50
|
const normalizedAlternates = withXDefault(alternates);
|
|
48
51
|
if (!normalizedAlternates)
|
|
49
52
|
return undefined;
|
|
@@ -160,7 +163,6 @@ export async function getHomePaginationEntries(cfg) {
|
|
|
160
163
|
}
|
|
161
164
|
export async function getCategoryEntries(cfg) {
|
|
162
165
|
const entries = [];
|
|
163
|
-
const { runtimeConfig } = cfg;
|
|
164
166
|
const languages = normalizeLanguages(cfg.languages);
|
|
165
167
|
const wpApiUrl = resolveWpApiUrl(cfg);
|
|
166
168
|
const siteUrl = resolveSiteUrl(cfg);
|
|
@@ -176,9 +178,29 @@ export async function getCategoryEntries(cfg) {
|
|
|
176
178
|
_fields: ["id", "slug", "name", "description", "meta", "yoast_head_json"],
|
|
177
179
|
});
|
|
178
180
|
const indexableCategories = categories.filter((cat) => !isNoindexEntity(cat));
|
|
179
|
-
|
|
181
|
+
const categoriesWithPosts = await mapConcurrent(indexableCategories, async (cat) => {
|
|
182
|
+
const catPosts = await listPostsWithEmbeds({
|
|
183
|
+
baseApiUrl: wpApiUrl,
|
|
184
|
+
categories: [cat.id],
|
|
185
|
+
perPage: 1,
|
|
186
|
+
page: 1,
|
|
187
|
+
langId: langCfg.langId,
|
|
188
|
+
orderby: "date",
|
|
189
|
+
order: "desc",
|
|
190
|
+
});
|
|
191
|
+
const latest = catPosts.ok ? catPosts.data?.items[0] : undefined;
|
|
192
|
+
if (!latest)
|
|
193
|
+
return null;
|
|
194
|
+
const lastmod = latest?.modified ||
|
|
195
|
+
latest?.date;
|
|
196
|
+
return {
|
|
197
|
+
category: cat,
|
|
198
|
+
lastmod: lastmod ? new Date(lastmod).toISOString() : undefined,
|
|
199
|
+
};
|
|
200
|
+
});
|
|
201
|
+
categoriesPerLang[langCfg.code] = categoriesWithPosts.filter((item) => Boolean(item));
|
|
180
202
|
const basePath = ensureTrailingSlash(langCfg.basePath || "/");
|
|
181
|
-
for (const cat of
|
|
203
|
+
for (const { category: cat } of categoriesPerLang[langCfg.code]) {
|
|
182
204
|
if (!renderAlternatesForLanguages)
|
|
183
205
|
continue;
|
|
184
206
|
const translationKey = getTranslationKey(cat);
|
|
@@ -194,20 +216,8 @@ export async function getCategoryEntries(cfg) {
|
|
|
194
216
|
for (const langCfg of languages) {
|
|
195
217
|
const basePath = ensureTrailingSlash(langCfg.basePath || "/");
|
|
196
218
|
const categories = categoriesPerLang[langCfg.code] ?? [];
|
|
197
|
-
const categoryEntries =
|
|
219
|
+
const categoryEntries = categories.map(({ category: cat, lastmod }) => {
|
|
198
220
|
const url = getAbsoluteUrl(`${basePath}${cat.slug}/`, siteUrl);
|
|
199
|
-
const catPosts = await listPostsWithEmbeds({
|
|
200
|
-
baseApiUrl: wpApiUrl,
|
|
201
|
-
categories: [cat.id],
|
|
202
|
-
perPage: runtimeConfig.postsPerPagePagination,
|
|
203
|
-
page: 1,
|
|
204
|
-
langId: langCfg.langId,
|
|
205
|
-
orderby: "date",
|
|
206
|
-
order: "desc",
|
|
207
|
-
});
|
|
208
|
-
const latest = catPosts.ok ? catPosts.data?.items[0] : undefined;
|
|
209
|
-
const lastmod = latest?.modified ||
|
|
210
|
-
latest?.date;
|
|
211
221
|
const alt = (() => {
|
|
212
222
|
if (!renderAlternatesForLanguages)
|
|
213
223
|
return undefined;
|
|
@@ -219,7 +229,7 @@ export async function getCategoryEntries(cfg) {
|
|
|
219
229
|
})();
|
|
220
230
|
return {
|
|
221
231
|
url,
|
|
222
|
-
lastmod
|
|
232
|
+
lastmod,
|
|
223
233
|
alternates: alt,
|
|
224
234
|
};
|
|
225
235
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type WPCategory, type WPPost } from "wpjsapi-lib";
|
|
2
2
|
import { type Locale } from "../../utils/index.js";
|
|
3
|
+
import { type LanguageLink } from "../../components/index.js";
|
|
3
4
|
type CategoryListViewProps = {
|
|
4
5
|
category: WPCategory;
|
|
5
6
|
posts: WPPost[];
|
|
@@ -9,6 +10,7 @@ type CategoryListViewProps = {
|
|
|
9
10
|
linkBasePath?: string;
|
|
10
11
|
locale?: Locale;
|
|
11
12
|
dateLocale?: string;
|
|
13
|
+
languageLinks?: LanguageLink[];
|
|
12
14
|
};
|
|
13
|
-
export declare function CategoryListView({ category, posts, totalPages, baseUrl, homeHref, linkBasePath, locale, dateLocale, }: CategoryListViewProps): import("react").JSX.Element;
|
|
15
|
+
export declare function CategoryListView({ category, posts, totalPages, baseUrl, homeHref, linkBasePath, locale, dateLocale, languageLinks, }: CategoryListViewProps): import("react").JSX.Element;
|
|
14
16
|
export {};
|
|
@@ -3,9 +3,9 @@ import Paginator from "../../components/Paginator/index.js";
|
|
|
3
3
|
import PostCard from "../../components/PostCard/index.js";
|
|
4
4
|
import styles from "./index.module.css";
|
|
5
5
|
import { getCountLabel, getEmptyLabel, getPaginatorBase } from "./index.utils.js";
|
|
6
|
-
import { Breadcrumbs, JsonLd } from "../../components/index.js";
|
|
6
|
+
import { Breadcrumbs, JsonLd, LanguageLinks } from "../../components/index.js";
|
|
7
7
|
import { getTranslator, getYoastSchema } from "../../utils/index.js";
|
|
8
|
-
export function CategoryListView({ category, posts, totalPages, baseUrl, homeHref = "/", linkBasePath, locale, dateLocale = "en-US", }) {
|
|
8
|
+
export function CategoryListView({ category, posts, totalPages, baseUrl, homeHref = "/", linkBasePath, locale, dateLocale = "en-US", languageLinks, }) {
|
|
9
9
|
const paginatorBase = getPaginatorBase(category, baseUrl);
|
|
10
10
|
const countLabel = getCountLabel(category, locale);
|
|
11
11
|
const emptyLabel = getEmptyLabel(locale);
|
|
@@ -13,5 +13,5 @@ export function CategoryListView({ category, posts, totalPages, baseUrl, homeHre
|
|
|
13
13
|
return (_jsxs("div", { className: styles.container, children: [_jsx(JsonLd, { data: getYoastSchema(category) }), _jsxs("header", { className: styles.header, children: [_jsx(Breadcrumbs, { items: [
|
|
14
14
|
{ label: "Home", href: homeHref },
|
|
15
15
|
{ label: category.name },
|
|
16
|
-
] }), _jsx("h1", { className: styles.title, children: category.name }), category.description && (_jsx("div", { className: styles.description, dangerouslySetInnerHTML: { __html: category.description } })), countLabel && _jsx("p", { className: styles.count, children: countLabel })] }), posts.length === 0 ? (_jsx("p", { className: styles.empty, children: emptyLabel })) : (_jsxs("section", { "aria-label": t("home.title"), className: styles.gridSection, children: [_jsx("div", { className: styles.grid, children: posts.map((post) => (_jsx(PostCard, { post: post, categorySlug: category.slug, basePath: linkBasePath, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: 1, totalPages: totalPages, baseUrl: paginatorBase, locale: locale })] }))] }));
|
|
16
|
+
] }), _jsx("h1", { className: styles.title, children: category.name }), category.description && (_jsx("div", { className: styles.description, dangerouslySetInnerHTML: { __html: category.description } })), countLabel && _jsx("p", { className: styles.count, children: countLabel })] }), posts.length === 0 ? (_jsx("p", { className: styles.empty, children: emptyLabel })) : (_jsxs("section", { "aria-label": t("home.title"), className: styles.gridSection, children: [_jsx("div", { className: styles.grid, children: posts.map((post) => (_jsx(PostCard, { post: post, categorySlug: category.slug, basePath: linkBasePath, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: 1, totalPages: totalPages, baseUrl: paginatorBase, locale: locale }), _jsx(LanguageLinks, { links: languageLinks, locale: locale })] }))] }));
|
|
17
17
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type WPPost } from "wpjsapi-lib";
|
|
2
2
|
import { type Locale } from "../../utils/index.js";
|
|
3
|
+
import { type LanguageLink } from "../../components/index.js";
|
|
3
4
|
type HomeViewProps = {
|
|
4
5
|
featuredPost?: WPPost;
|
|
5
6
|
regularPosts: WPPost[];
|
|
@@ -9,6 +10,7 @@ type HomeViewProps = {
|
|
|
9
10
|
linkBasePath?: string;
|
|
10
11
|
locale?: Locale;
|
|
11
12
|
dateLocale?: string;
|
|
13
|
+
languageLinks?: LanguageLink[];
|
|
12
14
|
};
|
|
13
|
-
export declare function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl, linkBasePath, locale, dateLocale, }: HomeViewProps): import("react").JSX.Element;
|
|
15
|
+
export declare function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl, linkBasePath, locale, dateLocale, languageLinks, }: HomeViewProps): import("react").JSX.Element;
|
|
14
16
|
export {};
|
|
@@ -6,11 +6,12 @@ import PostCard from "../../components/PostCard/index.js";
|
|
|
6
6
|
import styles from "./index.module.css";
|
|
7
7
|
import { buildFeaturedViewModel, getHomeCopy } from "./index.utils.js";
|
|
8
8
|
import { Alert, AlertDescription, AlertTitle, badgeClassName, } from "../../components/ui/index.js";
|
|
9
|
+
import { LanguageLinks } from "../../components/index.js";
|
|
9
10
|
function truncateLabel(label, max = 20) {
|
|
10
11
|
const trimmed = label.trim();
|
|
11
12
|
return trimmed.length > max ? `${trimmed.slice(0, max)}…` : trimmed;
|
|
12
13
|
}
|
|
13
|
-
export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl = "", linkBasePath, locale, dateLocale = "en-US", }) {
|
|
14
|
+
export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl = "", linkBasePath, locale, dateLocale = "en-US", languageLinks, }) {
|
|
14
15
|
const copy = getHomeCopy(locale);
|
|
15
16
|
const featuredModel = featuredPost
|
|
16
17
|
? buildFeaturedViewModel(featuredPost, locale, dateLocale, linkBasePath)
|
|
@@ -22,5 +23,5 @@ export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUr
|
|
|
22
23
|
__html: featuredModel.titleHtml,
|
|
23
24
|
}, className: styles.featuredTitle }) }), _jsx("div", { dangerouslySetInnerHTML: {
|
|
24
25
|
__html: featuredModel.excerptHtml,
|
|
25
|
-
}, className: `text-muted ${styles.featuredExcerpt}` }), _jsx("time", { dateTime: featuredModel.dateTime, className: `text-muted ${styles.featuredDate}`, children: featuredModel.dateLabel })] })] })) }), _jsx("section", { className: styles.postsGrid, "aria-label": copy.title, role: "region", children: regularPosts.map((post) => (_jsx(PostCard, { post: post, basePath: linkBasePath, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: 1, totalPages: totalPages, baseUrl: baseUrl, locale: locale })] })) }));
|
|
26
|
+
}, className: `text-muted ${styles.featuredExcerpt}` }), _jsx("time", { dateTime: featuredModel.dateTime, className: `text-muted ${styles.featuredDate}`, children: featuredModel.dateLabel })] })] })) }), _jsx("section", { className: styles.postsGrid, "aria-label": copy.title, role: "region", children: regularPosts.map((post) => (_jsx(PostCard, { post: post, basePath: linkBasePath, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: 1, totalPages: totalPages, baseUrl: baseUrl, locale: locale }), _jsx(LanguageLinks, { links: languageLinks, locale: locale })] })) }));
|
|
26
27
|
}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { type WPPage } from "wpjsapi-lib";
|
|
2
|
+
import { type LanguageLink } from "../../components/index.js";
|
|
3
|
+
import { type Locale } from "../../utils/index.js";
|
|
2
4
|
type LegalPageViewProps = {
|
|
3
5
|
page: WPPage;
|
|
4
6
|
dateLocale?: string;
|
|
5
7
|
homeHref: string;
|
|
8
|
+
locale?: Locale;
|
|
6
9
|
priorityImage?: boolean;
|
|
10
|
+
languageLinks?: LanguageLink[];
|
|
7
11
|
};
|
|
8
|
-
export declare function LegalPageView({ page, homeHref, priorityImage, }: LegalPageViewProps): import("react").JSX.Element;
|
|
12
|
+
export declare function LegalPageView({ page, homeHref, locale, priorityImage, languageLinks, }: LegalPageViewProps): import("react").JSX.Element;
|
|
9
13
|
export {};
|
|
@@ -2,11 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import Image from "next/image";
|
|
3
3
|
import styles from "./index.module.css";
|
|
4
4
|
import { getLegalContent, getLegalImage } from "./index.utils.js";
|
|
5
|
-
import { Breadcrumbs, JsonLd } from "../../components/index.js";
|
|
5
|
+
import { Breadcrumbs, JsonLd, LanguageLinks } from "../../components/index.js";
|
|
6
6
|
import { getYoastSchema, stripTags } from "../../utils/index.js";
|
|
7
|
-
export function LegalPageView({ page, homeHref, priorityImage = true, }) {
|
|
7
|
+
export function LegalPageView({ page, homeHref, locale, priorityImage = true, languageLinks, }) {
|
|
8
8
|
const featuredImage = getLegalImage(page);
|
|
9
9
|
const { titleHtml, contentHtml } = getLegalContent(page);
|
|
10
10
|
const titleText = stripTags(titleHtml) || titleHtml;
|
|
11
|
-
return (_jsxs("article", { className: styles.article, children: [_jsx(JsonLd, { data: getYoastSchema(page) }), _jsx(Breadcrumbs, { items: [{ label: "Home", href: homeHref }, { label: titleText }] }), featuredImage && (_jsx("div", { className: styles.imageWrapper, children: _jsx(Image, { src: featuredImage.src, alt: featuredImage.alt, width: featuredImage.width, height: featuredImage.height, className: styles.image, priority: priorityImage }) })), _jsx("h1", { dangerouslySetInnerHTML: { __html: titleHtml }, className: styles.title }), _jsx("div", { dangerouslySetInnerHTML: { __html: contentHtml }, className: `post-content ${styles.content}` })] }));
|
|
11
|
+
return (_jsxs("article", { className: styles.article, children: [_jsx(JsonLd, { data: getYoastSchema(page) }), _jsx(Breadcrumbs, { items: [{ label: "Home", href: homeHref }, { label: titleText }] }), featuredImage && (_jsx("div", { className: styles.imageWrapper, children: _jsx(Image, { src: featuredImage.src, alt: featuredImage.alt, width: featuredImage.width, height: featuredImage.height, className: styles.image, priority: priorityImage }) })), _jsx("h1", { dangerouslySetInnerHTML: { __html: titleHtml }, className: styles.title }), _jsx(LanguageLinks, { links: languageLinks, locale: locale }), _jsx("div", { dangerouslySetInnerHTML: { __html: contentHtml }, className: `post-content ${styles.content}` })] }));
|
|
12
12
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type WPPost } from "wpjsapi-lib";
|
|
2
2
|
import { type Locale } from "../../utils/index.js";
|
|
3
|
+
import { type LanguageLink } from "../../components/index.js";
|
|
3
4
|
type PostViewProps = {
|
|
4
5
|
post: WPPost;
|
|
5
6
|
dateLocale?: string;
|
|
@@ -8,6 +9,9 @@ type PostViewProps = {
|
|
|
8
9
|
authorDescription?: string | null;
|
|
9
10
|
disclaimer?: string;
|
|
10
11
|
priorityImage?: boolean;
|
|
12
|
+
siteUrl?: string;
|
|
13
|
+
wpApiUrl?: string;
|
|
14
|
+
languageLinks?: LanguageLink[];
|
|
11
15
|
};
|
|
12
|
-
export declare function PostView({ post, dateLocale, categoryBasePath, locale, authorDescription, disclaimer, priorityImage, }: PostViewProps): import("react").JSX.Element;
|
|
16
|
+
export declare function PostView({ post, dateLocale, categoryBasePath, locale, authorDescription, disclaimer, priorityImage, siteUrl, wpApiUrl, languageLinks, }: PostViewProps): import("react").JSX.Element;
|
|
13
17
|
export {};
|
|
@@ -2,8 +2,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import Image from "next/image";
|
|
3
3
|
import Link from "next/link";
|
|
4
4
|
import styles from "./index.module.css";
|
|
5
|
-
import { getTranslator, getYoastSchema } from "../../utils/index.js";
|
|
6
|
-
import { Breadcrumbs, JsonLd } from "../../components/index.js";
|
|
5
|
+
import { getTranslator, getYoastSchema, rewritePostContentLinks, } from "../../utils/index.js";
|
|
6
|
+
import { Breadcrumbs, JsonLd, LanguageLinks } from "../../components/index.js";
|
|
7
7
|
import { buildCategoryUrl, formatPublishedDate, getAuthor, getFeaturedImage, getPrimaryCategory, } from "./index.utils.js";
|
|
8
8
|
import { stripTags } from "../../utils/index.js";
|
|
9
9
|
import { Alert, badgeClassName, Card, CardContent } from "../../components/ui/index.js";
|
|
@@ -11,7 +11,7 @@ function truncateLabel(label, max = 20) {
|
|
|
11
11
|
const trimmed = label.trim();
|
|
12
12
|
return trimmed.length > max ? `${trimmed.slice(0, max)}…` : trimmed;
|
|
13
13
|
}
|
|
14
|
-
export function PostView({ post, dateLocale = "en-US", categoryBasePath = "/", locale, authorDescription, disclaimer, priorityImage = true, }) {
|
|
14
|
+
export function PostView({ post, dateLocale = "en-US", categoryBasePath = "/", locale, authorDescription, disclaimer, priorityImage = true, siteUrl, wpApiUrl, languageLinks, }) {
|
|
15
15
|
const t = getTranslator(locale);
|
|
16
16
|
const author = getAuthor(post);
|
|
17
17
|
const authorBio = authorDescription ?? author?.description;
|
|
@@ -19,6 +19,11 @@ export function PostView({ post, dateLocale = "en-US", categoryBasePath = "/", l
|
|
|
19
19
|
const categoryUrl = buildCategoryUrl(categoryBasePath, primaryCategory?.slug);
|
|
20
20
|
const featuredImage = getFeaturedImage(post, locale);
|
|
21
21
|
const publishedDate = formatPublishedDate(post.date, dateLocale);
|
|
22
|
+
const contentHtml = rewritePostContentLinks(post.content.rendered, {
|
|
23
|
+
siteUrl,
|
|
24
|
+
wpApiUrl,
|
|
25
|
+
basePath: categoryBasePath,
|
|
26
|
+
});
|
|
22
27
|
const breadcrumbs = primaryCategory && categoryUrl
|
|
23
28
|
? [
|
|
24
29
|
{ label: "Home", href: categoryBasePath },
|
|
@@ -29,5 +34,5 @@ export function PostView({ post, dateLocale = "en-US", categoryBasePath = "/", l
|
|
|
29
34
|
{ label: "Home", href: categoryBasePath },
|
|
30
35
|
{ label: stripTags(post.title.rendered) || post.title.rendered },
|
|
31
36
|
];
|
|
32
|
-
return (_jsxs("div", { className: styles.container, children: [_jsx(JsonLd, { data: getYoastSchema(post) }), _jsxs("article", { className: styles.article, children: [_jsx(Breadcrumbs, { items: breadcrumbs }), featuredImage && (_jsxs("figure", { className: styles.figure, children: [_jsx(Image, { src: featuredImage.src, alt: featuredImage.alt, fill: true, className: styles.image, priority: priorityImage, sizes: "(max-width: 1200px) 100vw, 1200px" }), _jsx("div", { className: styles.heroOverlay, "aria-hidden": "true" }), primaryCategory && (_jsx("div", { className: styles.badgeOverlay, children: categoryUrl ? (_jsx(Link, { href: categoryUrl, className: badgeClassName(), title: primaryCategory.name, children: truncateLabel(primaryCategory.name, 20) })) : (_jsx("span", { className: badgeClassName(), title: primaryCategory.name, children: truncateLabel(primaryCategory.name, 20) })) })), _jsx("h1", { dangerouslySetInnerHTML: { __html: post.title.rendered }, className: `${styles.title} ${styles.heroTitle}` })] })), !featuredImage && (_jsx("header", { className: styles.postHeader, children: _jsx("h1", { dangerouslySetInnerHTML: { __html: post.title.rendered }, className: styles.title }) })), _jsxs("div", { className: styles.meta, children: [author && (_jsx("span", { className: styles.authorLabel, children: t("post.authorPrefix", { name: author.name }) })), _jsx("span", { children: "\u2022" }), _jsx("time", { dateTime: post.date, children: publishedDate })] }), _jsx("div", { dangerouslySetInnerHTML: { __html:
|
|
37
|
+
return (_jsxs("div", { className: styles.container, children: [_jsx(JsonLd, { data: getYoastSchema(post) }), _jsxs("article", { className: styles.article, children: [_jsx(Breadcrumbs, { items: breadcrumbs }), featuredImage && (_jsxs("figure", { className: styles.figure, children: [_jsx(Image, { src: featuredImage.src, alt: featuredImage.alt, fill: true, className: styles.image, priority: priorityImage, sizes: "(max-width: 1200px) 100vw, 1200px" }), _jsx("div", { className: styles.heroOverlay, "aria-hidden": "true" }), primaryCategory && (_jsx("div", { className: styles.badgeOverlay, children: categoryUrl ? (_jsx(Link, { href: categoryUrl, className: badgeClassName(), title: primaryCategory.name, children: truncateLabel(primaryCategory.name, 20) })) : (_jsx("span", { className: badgeClassName(), title: primaryCategory.name, children: truncateLabel(primaryCategory.name, 20) })) })), _jsx("h1", { dangerouslySetInnerHTML: { __html: post.title.rendered }, className: `${styles.title} ${styles.heroTitle}` })] })), !featuredImage && (_jsx("header", { className: styles.postHeader, children: _jsx("h1", { dangerouslySetInnerHTML: { __html: post.title.rendered }, className: styles.title }) })), _jsxs("div", { className: styles.meta, children: [author && (_jsx("span", { className: styles.authorLabel, children: t("post.authorPrefix", { name: author.name }) })), _jsx("span", { children: "\u2022" }), _jsx("time", { dateTime: post.date, children: publishedDate })] }), _jsx("div", { dangerouslySetInnerHTML: { __html: contentHtml }, className: `post-content ${styles.content}` }), disclaimer && (_jsx(Alert, { className: styles.disclaimer, role: "note", children: disclaimer })), _jsx(LanguageLinks, { links: languageLinks, locale: locale }), author && (_jsx(Card, { as: "aside", className: styles.authorCard, size: "sm", children: _jsx(CardContent, { children: _jsxs("address", { className: styles.authorAddress, children: [_jsx("strong", { className: styles.authorName, children: author.name }), authorBio && _jsx("p", { className: styles.authorBio, children: authorBio })] }) }) }))] })] }));
|
|
33
38
|
}
|