wpheadless-lib 1.1.14 → 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.
@@ -1,3 +1,4 @@
1
+ import { type Locale } from "../../utils/index.js";
1
2
  export type LanguageLink = {
2
3
  code: string;
3
4
  label: string;
@@ -7,7 +8,8 @@ export type LanguageLink = {
7
8
  type LanguageLinksProps = {
8
9
  links?: LanguageLink[];
9
10
  label?: string;
11
+ locale?: Locale;
10
12
  className?: string;
11
13
  };
12
- export declare function LanguageLinks({ links, label, className, }: LanguageLinksProps): import("react").JSX.Element;
14
+ export declare function LanguageLinks({ links, label, locale, className, }: LanguageLinksProps): import("react").JSX.Element;
13
15
  export {};
@@ -1,9 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import Link from "next/link";
3
3
  import styles from "./index.module.css";
4
- export function LanguageLinks({ links, label = "Available languages", className, }) {
4
+ import { getTranslator } from "../../utils/index.js";
5
+ export function LanguageLinks({ links, label, locale, className, }) {
5
6
  const visibleLinks = links?.filter((link) => link.href) ?? [];
6
7
  if (visibleLinks.length < 2)
7
8
  return null;
8
- return (_jsxs("nav", { "aria-label": label, className: [styles.languageLinks, className].filter(Boolean).join(" "), children: [_jsx("span", { className: styles.label, children: label }), _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))) })] }));
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))) })] }));
9
12
  }
@@ -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",
@@ -163,7 +163,6 @@ export async function getHomePaginationEntries(cfg) {
163
163
  }
164
164
  export async function getCategoryEntries(cfg) {
165
165
  const entries = [];
166
- const { runtimeConfig } = cfg;
167
166
  const languages = normalizeLanguages(cfg.languages);
168
167
  const wpApiUrl = resolveWpApiUrl(cfg);
169
168
  const siteUrl = resolveSiteUrl(cfg);
@@ -179,9 +178,29 @@ export async function getCategoryEntries(cfg) {
179
178
  _fields: ["id", "slug", "name", "description", "meta", "yoast_head_json"],
180
179
  });
181
180
  const indexableCategories = categories.filter((cat) => !isNoindexEntity(cat));
182
- categoriesPerLang[langCfg.code] = indexableCategories;
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));
183
202
  const basePath = ensureTrailingSlash(langCfg.basePath || "/");
184
- for (const cat of indexableCategories) {
203
+ for (const { category: cat } of categoriesPerLang[langCfg.code]) {
185
204
  if (!renderAlternatesForLanguages)
186
205
  continue;
187
206
  const translationKey = getTranslationKey(cat);
@@ -197,20 +216,8 @@ export async function getCategoryEntries(cfg) {
197
216
  for (const langCfg of languages) {
198
217
  const basePath = ensureTrailingSlash(langCfg.basePath || "/");
199
218
  const categories = categoriesPerLang[langCfg.code] ?? [];
200
- const categoryEntries = await mapConcurrent(categories, async (cat) => {
219
+ const categoryEntries = categories.map(({ category: cat, lastmod }) => {
201
220
  const url = getAbsoluteUrl(`${basePath}${cat.slug}/`, siteUrl);
202
- const catPosts = await listPostsWithEmbeds({
203
- baseApiUrl: wpApiUrl,
204
- categories: [cat.id],
205
- perPage: runtimeConfig.postsPerPagePagination,
206
- page: 1,
207
- langId: langCfg.langId,
208
- orderby: "date",
209
- order: "desc",
210
- });
211
- const latest = catPosts.ok ? catPosts.data?.items[0] : undefined;
212
- const lastmod = latest?.modified ||
213
- latest?.date;
214
221
  const alt = (() => {
215
222
  if (!renderAlternatesForLanguages)
216
223
  return undefined;
@@ -222,7 +229,7 @@ export async function getCategoryEntries(cfg) {
222
229
  })();
223
230
  return {
224
231
  url,
225
- lastmod: lastmod ? new Date(lastmod).toISOString() : undefined,
232
+ lastmod,
226
233
  alternates: alt,
227
234
  };
228
235
  });
@@ -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 }), _jsx(LanguageLinks, { links: languageLinks })] }))] }));
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
  }
@@ -23,5 +23,5 @@ export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUr
23
23
  __html: featuredModel.titleHtml,
24
24
  }, className: styles.featuredTitle }) }), _jsx("div", { dangerouslySetInnerHTML: {
25
25
  __html: featuredModel.excerptHtml,
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 })] })) }));
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 })] })) }));
27
27
  }
@@ -1,11 +1,13 @@
1
1
  import { type WPPage } from "wpjsapi-lib";
2
2
  import { type LanguageLink } from "../../components/index.js";
3
+ import { type Locale } from "../../utils/index.js";
3
4
  type LegalPageViewProps = {
4
5
  page: WPPage;
5
6
  dateLocale?: string;
6
7
  homeHref: string;
8
+ locale?: Locale;
7
9
  priorityImage?: boolean;
8
10
  languageLinks?: LanguageLink[];
9
11
  };
10
- export declare function LegalPageView({ page, homeHref, priorityImage, languageLinks, }: LegalPageViewProps): import("react").JSX.Element;
12
+ export declare function LegalPageView({ page, homeHref, locale, priorityImage, languageLinks, }: LegalPageViewProps): import("react").JSX.Element;
11
13
  export {};
@@ -4,9 +4,9 @@ import styles from "./index.module.css";
4
4
  import { getLegalContent, getLegalImage } from "./index.utils.js";
5
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, languageLinks, }) {
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(LanguageLinks, { links: languageLinks }), _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
  }
@@ -34,5 +34,5 @@ export function PostView({ post, dateLocale = "en-US", categoryBasePath = "/", l
34
34
  { label: "Home", href: categoryBasePath },
35
35
  { label: stripTags(post.title.rendered) || post.title.rendered },
36
36
  ];
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 }), 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 })] }) }) }))] })] }));
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 })] }) }) }))] })] }));
38
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wpheadless-lib",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "dist/index.js",