wpheadless-lib 1.1.4 → 1.1.6
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 +4 -4
- package/dist/api/categories.js +6 -3
- package/dist/api/posts.d.ts +5 -5
- package/dist/api/posts.js +13 -4
- package/dist/api/translations.js +1 -1
- package/dist/base/category/index.d.ts +1 -1
- package/dist/base/category/pagination.d.ts +3 -3
- package/dist/base/home/index.d.ts +1 -1
- package/dist/base/home/pagination.d.ts +3 -3
- package/dist/base/post/index.d.ts +2 -2
- package/dist/components/PostCard/index.d.ts +2 -1
- package/dist/components/PostCard/index.js +3 -2
- package/dist/components/PostCard/index.types.d.ts +1 -0
- package/dist/components/PostCard/index.utils.d.ts +2 -2
- package/dist/components/PostCard/index.utils.js +13 -3
- package/dist/utils/sitemap.js +9 -6
- package/dist/views/CategoryListView/index.d.ts +2 -1
- package/dist/views/CategoryListView/index.js +2 -2
- package/dist/views/CategoryPaginationView/index.d.ts +2 -1
- package/dist/views/CategoryPaginationView/index.js +2 -2
- package/dist/views/HomePaginationView/index.d.ts +2 -1
- package/dist/views/HomePaginationView/index.js +2 -2
- package/dist/views/HomeView/index.d.ts +2 -1
- package/dist/views/HomeView/index.js +3 -3
- package/dist/views/HomeView/index.utils.d.ts +1 -1
- package/dist/views/HomeView/index.utils.js +3 -2
- package/package.json +1 -1
package/dist/api/categories.d.ts
CHANGED
|
@@ -6,24 +6,24 @@ export type CategoryClientConfig = {
|
|
|
6
6
|
appPassword?: string;
|
|
7
7
|
};
|
|
8
8
|
export declare function listCategoryStaticParams({ baseApiUrl, lang, }: CategoryClientConfig & {
|
|
9
|
-
lang
|
|
9
|
+
lang?: string;
|
|
10
10
|
}): Promise<ApiResult<Array<{
|
|
11
11
|
category: string;
|
|
12
12
|
}>>>;
|
|
13
13
|
export declare function getCategoryBySlug({ baseApiUrl, slug, lang, }: CategoryClientConfig & {
|
|
14
14
|
slug: string;
|
|
15
|
-
lang
|
|
15
|
+
lang?: string;
|
|
16
16
|
}): Promise<ApiResult<WPCategory | null>>;
|
|
17
17
|
export declare function listCategoryPosts({ baseApiUrl, categoryId, perPage, langId, }: CategoryClientConfig & {
|
|
18
18
|
categoryId: number;
|
|
19
19
|
perPage: number;
|
|
20
|
-
langId
|
|
20
|
+
langId?: string;
|
|
21
21
|
}): Promise<ApiResult<{
|
|
22
22
|
posts: WPPost[];
|
|
23
23
|
totalPages: number;
|
|
24
24
|
}>>;
|
|
25
25
|
export declare function getCategoryByTranslationKey({ baseApiUrl, translationKey, lang, perPage, }: CategoryClientConfig & {
|
|
26
26
|
translationKey: string;
|
|
27
|
-
lang
|
|
27
|
+
lang?: string;
|
|
28
28
|
perPage?: number;
|
|
29
29
|
}): Promise<ApiResult<WPCategory | null>>;
|
package/dist/api/categories.js
CHANGED
|
@@ -5,7 +5,7 @@ export async function listCategoryStaticParams({ baseApiUrl, lang, }) {
|
|
|
5
5
|
const { categoriesApi } = createWpClient({
|
|
6
6
|
baseUrl: baseApiUrl,
|
|
7
7
|
});
|
|
8
|
-
const categories = await categoriesApi.listAll({ lang });
|
|
8
|
+
const categories = await categoriesApi.listAll(lang ? { lang } : undefined);
|
|
9
9
|
return {
|
|
10
10
|
ok: true,
|
|
11
11
|
data: categories.map((category) => ({ category: category.slug })),
|
|
@@ -28,7 +28,7 @@ export async function getCategoryBySlug({ baseApiUrl, slug, lang, }) {
|
|
|
28
28
|
const response = await categoriesApi.list({
|
|
29
29
|
slug,
|
|
30
30
|
per_page: 1,
|
|
31
|
-
lang,
|
|
31
|
+
...(lang ? { lang } : {}),
|
|
32
32
|
_fields: ["id", "slug", "name", "description", "yoast_head_json", "meta"],
|
|
33
33
|
});
|
|
34
34
|
return { ok: true, data: response.items[0] ?? null, error: null };
|
|
@@ -46,13 +46,16 @@ export async function listCategoryPosts({ baseApiUrl, categoryId, perPage, langI
|
|
|
46
46
|
const { postsApi } = createWpClient({
|
|
47
47
|
baseUrl: baseApiUrl,
|
|
48
48
|
});
|
|
49
|
+
const languageFilter = langId
|
|
50
|
+
? { taxonomies: { language: [langId] } }
|
|
51
|
+
: {};
|
|
49
52
|
const response = await postsApi.list({
|
|
50
53
|
categories: [categoryId],
|
|
51
54
|
per_page: perPage,
|
|
52
55
|
orderby: "date",
|
|
53
56
|
order: "desc",
|
|
54
57
|
_embed: true,
|
|
55
|
-
|
|
58
|
+
...languageFilter,
|
|
56
59
|
});
|
|
57
60
|
return {
|
|
58
61
|
ok: true,
|
package/dist/api/posts.d.ts
CHANGED
|
@@ -11,11 +11,11 @@ export type ClientConfig = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare function getPostBySlug({ baseApiUrl, slug, langId, username, appPassword, }: ClientConfig & {
|
|
13
13
|
slug: string;
|
|
14
|
-
langId
|
|
14
|
+
langId?: string;
|
|
15
15
|
}): Promise<ApiResult<WPPost | null>>;
|
|
16
16
|
export declare function listPostStaticParams({ baseApiUrl, lang, langId, }: ClientConfig & {
|
|
17
|
-
lang
|
|
18
|
-
langId
|
|
17
|
+
lang?: string;
|
|
18
|
+
langId?: string;
|
|
19
19
|
}): Promise<ApiResult<Array<{
|
|
20
20
|
category: string;
|
|
21
21
|
post: string;
|
|
@@ -27,7 +27,7 @@ export declare function listPostsByTranslationKey({ baseApiUrl, translationKey,
|
|
|
27
27
|
type ListPostsParams = ClientConfig & {
|
|
28
28
|
perPage: number;
|
|
29
29
|
page?: number;
|
|
30
|
-
langId
|
|
30
|
+
langId?: string;
|
|
31
31
|
categories?: number[];
|
|
32
32
|
embed?: boolean;
|
|
33
33
|
fields?: string[];
|
|
@@ -38,7 +38,7 @@ export declare function listPosts({ baseApiUrl, perPage, page, langId, categorie
|
|
|
38
38
|
export declare function listPostsWithEmbeds(params: Omit<ListPostsParams, "embed">): Promise<ApiResult<WPPaginatedResponse<WPPost>>>;
|
|
39
39
|
export declare function getPostsTotalPages({ baseApiUrl, perPage, langId, categories, }: ClientConfig & {
|
|
40
40
|
perPage: number;
|
|
41
|
-
langId
|
|
41
|
+
langId?: string;
|
|
42
42
|
categories?: number[];
|
|
43
43
|
}): Promise<ApiResult<number>>;
|
|
44
44
|
export {};
|
package/dist/api/posts.js
CHANGED
|
@@ -8,11 +8,14 @@ export async function getPostBySlug({ baseApiUrl, slug, langId, username, appPas
|
|
|
8
8
|
username,
|
|
9
9
|
appPassword,
|
|
10
10
|
});
|
|
11
|
+
const languageFilter = langId
|
|
12
|
+
? { taxonomies: { language: [langId] } }
|
|
13
|
+
: {};
|
|
11
14
|
const response = await postsApi.list({
|
|
12
15
|
slug,
|
|
13
16
|
per_page: 1,
|
|
14
17
|
_embed: true,
|
|
15
|
-
|
|
18
|
+
...languageFilter,
|
|
16
19
|
});
|
|
17
20
|
return { ok: true, data: response.items[0] ?? null, error: null };
|
|
18
21
|
}
|
|
@@ -23,11 +26,14 @@ export async function getPostBySlug({ baseApiUrl, slug, langId, username, appPas
|
|
|
23
26
|
export async function listPostStaticParams({ baseApiUrl, lang, langId, }) {
|
|
24
27
|
try {
|
|
25
28
|
const { postsApi, categoriesApi } = createWpClient({ baseUrl: baseApiUrl });
|
|
26
|
-
const categories = await categoriesApi.listAll({ lang });
|
|
29
|
+
const categories = await categoriesApi.listAll(lang ? { lang } : undefined);
|
|
30
|
+
const languageFilter = langId
|
|
31
|
+
? { taxonomies: { language: [langId] } }
|
|
32
|
+
: {};
|
|
27
33
|
const response = await postsApi.list({
|
|
28
34
|
per_page: 100,
|
|
29
35
|
_fields: ["slug", "categories"],
|
|
30
|
-
|
|
36
|
+
...languageFilter,
|
|
31
37
|
});
|
|
32
38
|
const paths = [];
|
|
33
39
|
for (const post of response.items) {
|
|
@@ -67,6 +73,9 @@ export async function listPosts({ baseApiUrl, perPage, page, langId, categories,
|
|
|
67
73
|
const { postsApi } = createWpClient({
|
|
68
74
|
baseUrl: baseApiUrl,
|
|
69
75
|
});
|
|
76
|
+
const languageFilter = langId
|
|
77
|
+
? { taxonomies: { language: [langId] } }
|
|
78
|
+
: {};
|
|
70
79
|
const response = await postsApi.list({
|
|
71
80
|
per_page: perPage,
|
|
72
81
|
page,
|
|
@@ -75,7 +84,7 @@ export async function listPosts({ baseApiUrl, perPage, page, langId, categories,
|
|
|
75
84
|
...(categories ? { categories } : {}),
|
|
76
85
|
...(embed ? { _embed: true } : {}),
|
|
77
86
|
...(fields ? { _fields: fields } : {}),
|
|
78
|
-
|
|
87
|
+
...languageFilter,
|
|
79
88
|
});
|
|
80
89
|
return { ok: true, data: response, error: null };
|
|
81
90
|
}
|
package/dist/api/translations.js
CHANGED
|
@@ -21,7 +21,7 @@ export async function fetchCategoriesByTranslationKey({ baseApiUrl, translationK
|
|
|
21
21
|
const response = await categoriesApi.list({
|
|
22
22
|
translation_key_v2: translationKey,
|
|
23
23
|
per_page: perPage,
|
|
24
|
-
lang,
|
|
24
|
+
...(lang ? { lang } : {}),
|
|
25
25
|
_fields: ["id", "slug", "name", "description", "yoast_head_json", "meta"],
|
|
26
26
|
});
|
|
27
27
|
return response.items;
|
|
@@ -4,7 +4,7 @@ type CategoryStaticParamsInput = {
|
|
|
4
4
|
baseApiUrl: string;
|
|
5
5
|
perPage: number;
|
|
6
6
|
lang: string;
|
|
7
|
-
langId
|
|
7
|
+
langId?: string;
|
|
8
8
|
};
|
|
9
9
|
type CategoryStaticParam = {
|
|
10
10
|
category: string;
|
|
@@ -21,7 +21,7 @@ export declare function fetchCategoryPaginatedPosts({ baseApiUrl, categoryId, pa
|
|
|
21
21
|
categoryId: number;
|
|
22
22
|
page: number;
|
|
23
23
|
perPage: number;
|
|
24
|
-
langId
|
|
24
|
+
langId?: string;
|
|
25
25
|
}): Promise<{
|
|
26
26
|
posts: WPPost[];
|
|
27
27
|
totalPages: number;
|
|
@@ -31,7 +31,7 @@ export declare function getCategoryTotalPages({ baseApiUrl, categoryId, perPage,
|
|
|
31
31
|
baseApiUrl: string;
|
|
32
32
|
categoryId: number;
|
|
33
33
|
perPage: number;
|
|
34
|
-
langId
|
|
34
|
+
langId?: string;
|
|
35
35
|
}): Promise<number>;
|
|
36
36
|
export declare function buildCategoryPaginationMetadata({ category, canonicalBaseUrl, currentPage, useYoast, siteName, languages, }: {
|
|
37
37
|
category: WPCategory;
|
|
@@ -3,7 +3,7 @@ import type { Metadata } from "next";
|
|
|
3
3
|
type StaticParamsInput = {
|
|
4
4
|
baseApiUrl: string;
|
|
5
5
|
perPage: number;
|
|
6
|
-
langId
|
|
6
|
+
langId?: string;
|
|
7
7
|
};
|
|
8
8
|
export declare function getHomePaginationStaticParams({ baseApiUrl, perPage, langId, }: StaticParamsInput): Promise<Array<{
|
|
9
9
|
page: string;
|
|
@@ -11,13 +11,13 @@ export declare function getHomePaginationStaticParams({ baseApiUrl, perPage, lan
|
|
|
11
11
|
export declare function getHomeTotalPages({ baseApiUrl, perPage, langId, }: {
|
|
12
12
|
baseApiUrl: string;
|
|
13
13
|
perPage: number;
|
|
14
|
-
langId
|
|
14
|
+
langId?: string;
|
|
15
15
|
}): Promise<number>;
|
|
16
16
|
type FetchPaginatedPostsInput = {
|
|
17
17
|
baseApiUrl: string;
|
|
18
18
|
perPage: number;
|
|
19
19
|
page: number;
|
|
20
|
-
langId
|
|
20
|
+
langId?: string;
|
|
21
21
|
};
|
|
22
22
|
type FetchPaginatedPostsResult = {
|
|
23
23
|
posts: WPPost[];
|
|
@@ -3,7 +3,7 @@ import type { Metadata } from "next";
|
|
|
3
3
|
type PostStaticParamsInput = {
|
|
4
4
|
baseApiUrl: string;
|
|
5
5
|
lang: string;
|
|
6
|
-
langId
|
|
6
|
+
langId?: string;
|
|
7
7
|
};
|
|
8
8
|
type PostStaticParam = {
|
|
9
9
|
category: string;
|
|
@@ -13,7 +13,7 @@ export declare function getPostStaticParams({ baseApiUrl, lang, langId, }: PostS
|
|
|
13
13
|
export declare function fetchPostBySlug({ baseApiUrl, slug, langId, }: {
|
|
14
14
|
baseApiUrl: string;
|
|
15
15
|
slug: string;
|
|
16
|
-
langId
|
|
16
|
+
langId?: string;
|
|
17
17
|
}): Promise<WPPost | null>;
|
|
18
18
|
export declare function fetchPostsByTranslateKey({ baseApiUrl, translationKey, }: {
|
|
19
19
|
baseApiUrl: string;
|
|
@@ -5,6 +5,7 @@ interface PostCardProps {
|
|
|
5
5
|
categorySlug?: string;
|
|
6
6
|
locale?: Locale;
|
|
7
7
|
dateLocale?: string;
|
|
8
|
+
basePath?: string;
|
|
8
9
|
}
|
|
9
|
-
export default function PostCard({ post, categorySlug, locale, dateLocale, }: PostCardProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export default function PostCard({ post, categorySlug, locale, dateLocale, basePath, }: PostCardProps): import("react/jsx-runtime").JSX.Element;
|
|
10
11
|
export {};
|
|
@@ -8,7 +8,7 @@ function truncateText(text, max = 20) {
|
|
|
8
8
|
const normalized = text.trim();
|
|
9
9
|
return normalized.length > max ? `${normalized.slice(0, max)}...` : normalized;
|
|
10
10
|
}
|
|
11
|
-
export default function PostCard({ post, categorySlug, locale = "en", dateLocale = "en-US", }) {
|
|
11
|
+
export default function PostCard({ post, categorySlug, locale = "en", dateLocale = "en-US", basePath, }) {
|
|
12
12
|
const featuredMedia = getFeaturedMedia(post);
|
|
13
13
|
const imageUrl = featuredMedia?.source_url;
|
|
14
14
|
const categories = (post._embedded?.["wp:term"]?.[0] || []).filter((cat) => Boolean(cat?.slug));
|
|
@@ -17,8 +17,9 @@ export default function PostCard({ post, categorySlug, locale = "en", dateLocale
|
|
|
17
17
|
post,
|
|
18
18
|
categorySlug: resolvedCategory,
|
|
19
19
|
locale,
|
|
20
|
+
basePath,
|
|
20
21
|
});
|
|
21
|
-
return (_jsxs("article", { className: `${styles.card} card`, children: [categories.length > 0 && (_jsx("div", { className: styles.badges, children: categories.map((cat) => (_jsx(Link, { href: buildCategoryUrl(cat.slug, locale), className: `badge ${styles.badge}`, title: cat.name, children: truncateText(cat.name, 20) }, cat.id ?? cat.slug))) })), _jsxs(Link, { href: postUrl, className: styles.postLink, children: [imageUrl && (_jsx("div", { className: styles.imageWrapper, children: _jsx(Image, { src: imageUrl, alt: featuredMedia?.alt_text || post.title.rendered, fill: true, style: { objectFit: "cover" }, sizes: "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" }) })), _jsxs("div", { className: styles.body, children: [_jsx("h2", { className: styles.title, dangerouslySetInnerHTML: {
|
|
22
|
+
return (_jsxs("article", { className: `${styles.card} card`, children: [categories.length > 0 && (_jsx("div", { className: styles.badges, children: categories.map((cat) => (_jsx(Link, { href: buildCategoryUrl(cat.slug, locale, basePath), className: `badge ${styles.badge}`, title: cat.name, children: truncateText(cat.name, 20) }, cat.id ?? cat.slug))) })), _jsxs(Link, { href: postUrl, className: styles.postLink, children: [imageUrl && (_jsx("div", { className: styles.imageWrapper, children: _jsx(Image, { src: imageUrl, alt: featuredMedia?.alt_text || post.title.rendered, fill: true, style: { objectFit: "cover" }, sizes: "(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw" }) })), _jsxs("div", { className: styles.body, children: [_jsx("h2", { className: styles.title, dangerouslySetInnerHTML: {
|
|
22
23
|
__html: post.title.rendered,
|
|
23
24
|
} }), _jsx("div", { dangerouslySetInnerHTML: {
|
|
24
25
|
__html: post.excerpt.rendered,
|
|
@@ -3,6 +3,6 @@ import { type Locale } from "../../utils";
|
|
|
3
3
|
import type { BuildUrlArgs } from "./index.types";
|
|
4
4
|
export declare const getLangPrefix: (locale?: Locale) => string;
|
|
5
5
|
export declare const resolveCategorySlug: (post: WPPost, categorySlug?: string) => string | undefined;
|
|
6
|
-
export declare const buildPostUrl: ({ post, categorySlug, locale }: BuildUrlArgs) => string;
|
|
7
|
-
export declare const buildCategoryUrl: (slug: string, locale?: Locale) => string;
|
|
6
|
+
export declare const buildPostUrl: ({ post, categorySlug, locale, basePath, }: BuildUrlArgs) => string;
|
|
7
|
+
export declare const buildCategoryUrl: (slug: string, locale?: Locale, basePath?: string) => string;
|
|
8
8
|
export declare const formatPostDate: (date: string, dateLocale?: string) => string;
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import { ensureTrailingSlash } from "../../utils";
|
|
2
2
|
export const getLangPrefix = (locale) => locale && locale !== "en" ? `/${locale}` : "";
|
|
3
|
+
const normalizeBasePath = (basePath) => {
|
|
4
|
+
if (!basePath)
|
|
5
|
+
return "";
|
|
6
|
+
const withLeadingSlash = basePath.startsWith("/")
|
|
7
|
+
? basePath
|
|
8
|
+
: `/${basePath}`;
|
|
9
|
+
const trimmed = withLeadingSlash.replace(/\/+$/, "");
|
|
10
|
+
return trimmed === "/" ? "" : trimmed;
|
|
11
|
+
};
|
|
12
|
+
const resolveLinkPrefix = (basePath, locale) => basePath !== undefined ? normalizeBasePath(basePath) : getLangPrefix(locale);
|
|
3
13
|
export const resolveCategorySlug = (post, categorySlug) => {
|
|
4
14
|
if (categorySlug)
|
|
5
15
|
return categorySlug;
|
|
6
16
|
const categories = (post._embedded?.["wp:term"]?.[0] || []);
|
|
7
17
|
return categories[0]?.slug;
|
|
8
18
|
};
|
|
9
|
-
export const buildPostUrl = ({ post, categorySlug, locale }) => {
|
|
10
|
-
const langPrefix =
|
|
19
|
+
export const buildPostUrl = ({ post, categorySlug, locale, basePath, }) => {
|
|
20
|
+
const langPrefix = resolveLinkPrefix(basePath, locale);
|
|
11
21
|
const resolvedCategory = categorySlug || resolveCategorySlug(post);
|
|
12
22
|
const postPath = resolvedCategory
|
|
13
23
|
? `/${resolvedCategory}/${post.slug}`
|
|
@@ -15,7 +25,7 @@ export const buildPostUrl = ({ post, categorySlug, locale }) => {
|
|
|
15
25
|
const url = `${langPrefix}${postPath}`.replace(/\/+/g, "/");
|
|
16
26
|
return ensureTrailingSlash(url);
|
|
17
27
|
};
|
|
18
|
-
export const buildCategoryUrl = (slug, locale) => ensureTrailingSlash(`${
|
|
28
|
+
export const buildCategoryUrl = (slug, locale, basePath) => ensureTrailingSlash(`${resolveLinkPrefix(basePath, locale)}/${slug}`.replace(/\/+/g, "/"));
|
|
19
29
|
export const formatPostDate = (date, dateLocale) => new Date(date).toLocaleDateString(dateLocale || "en-US", {
|
|
20
30
|
year: "numeric",
|
|
21
31
|
month: "long",
|
package/dist/utils/sitemap.js
CHANGED
|
@@ -107,7 +107,7 @@ export async function getCategoryEntries(cfg) {
|
|
|
107
107
|
for (const langCfg of languages) {
|
|
108
108
|
const { categoriesApi } = createWpClient({ baseUrl: wpApiUrl });
|
|
109
109
|
const categories = await categoriesApi.listAll({
|
|
110
|
-
lang: langCfg.code,
|
|
110
|
+
...(langCfg.langId ? { lang: langCfg.code } : {}),
|
|
111
111
|
_fields: ["id", "slug", "name", "description", "meta"],
|
|
112
112
|
});
|
|
113
113
|
categoriesPerLang[langCfg.code] = categories;
|
|
@@ -133,7 +133,7 @@ export async function getCategoryEntries(cfg) {
|
|
|
133
133
|
categories: [cat.id],
|
|
134
134
|
perPage: runtimeConfig.postsPerPagePagination,
|
|
135
135
|
page: 1,
|
|
136
|
-
langId: langCfg.langId
|
|
136
|
+
langId: langCfg.langId,
|
|
137
137
|
orderby: "date",
|
|
138
138
|
order: "desc",
|
|
139
139
|
});
|
|
@@ -175,7 +175,7 @@ export async function getCategoryPaginationEntries(cfg) {
|
|
|
175
175
|
baseApiUrl: wpApiUrl,
|
|
176
176
|
perPage: runtimeConfig.postsPerPagePagination,
|
|
177
177
|
lang: langCfg.code,
|
|
178
|
-
langId: langCfg.langId
|
|
178
|
+
langId: langCfg.langId,
|
|
179
179
|
});
|
|
180
180
|
const basePath = ensureTrailingSlash(langCfg.basePath || "/");
|
|
181
181
|
for (const page of catPages) {
|
|
@@ -188,7 +188,7 @@ export async function getCategoryPaginationEntries(cfg) {
|
|
|
188
188
|
categories: [catId],
|
|
189
189
|
perPage: runtimeConfig.postsPerPagePagination,
|
|
190
190
|
page: Number(page.page),
|
|
191
|
-
langId: langCfg.langId
|
|
191
|
+
langId: langCfg.langId,
|
|
192
192
|
orderby: "date",
|
|
193
193
|
order: "desc",
|
|
194
194
|
});
|
|
@@ -213,10 +213,13 @@ export async function getPostEntriesForLang(langCode, cfg) {
|
|
|
213
213
|
const wpApiUrl = resolveWpApiUrl(cfg);
|
|
214
214
|
const siteUrl = resolveSiteUrl(cfg);
|
|
215
215
|
const postsApi = createPostsEndpoints({ baseUrl: wpApiUrl });
|
|
216
|
+
const languageFilter = langCfg.langId
|
|
217
|
+
? { taxonomies: { language: [langCfg.langId] } }
|
|
218
|
+
: {};
|
|
216
219
|
const posts = await postsApi.listAll({
|
|
217
220
|
per_page: 100,
|
|
218
221
|
_embed: true,
|
|
219
|
-
|
|
222
|
+
...languageFilter,
|
|
220
223
|
});
|
|
221
224
|
const postAlternates = {};
|
|
222
225
|
for (const l of languages) {
|
|
@@ -226,7 +229,7 @@ export async function getPostEntriesForLang(langCode, cfg) {
|
|
|
226
229
|
: await postsApi.listAll({
|
|
227
230
|
per_page: 100,
|
|
228
231
|
_embed: true,
|
|
229
|
-
taxonomies: { language: [
|
|
232
|
+
...(l.langId ? { taxonomies: { language: [l.langId] } } : {}),
|
|
230
233
|
});
|
|
231
234
|
for (const p of langPosts) {
|
|
232
235
|
const translationKey = getTranslationKey(p);
|
|
@@ -6,8 +6,9 @@ type CategoryListViewProps = {
|
|
|
6
6
|
totalPages: number;
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
homeHref?: string;
|
|
9
|
+
linkBasePath?: string;
|
|
9
10
|
locale?: Locale;
|
|
10
11
|
dateLocale?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function CategoryListView({ category, posts, totalPages, baseUrl, homeHref, locale, dateLocale, }: CategoryListViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function CategoryListView({ category, posts, totalPages, baseUrl, homeHref, linkBasePath, locale, dateLocale, }: CategoryListViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -5,7 +5,7 @@ import styles from "./index.module.css";
|
|
|
5
5
|
import { getCountLabel, getEmptyLabel, getPaginatorBase } from "./index.utils";
|
|
6
6
|
import { Breadcrumbs } from "../../components";
|
|
7
7
|
import { getTranslator } from "../../utils";
|
|
8
|
-
export function CategoryListView({ category, posts, totalPages, baseUrl, homeHref = "/", locale, dateLocale = "en-US", }) {
|
|
8
|
+
export function CategoryListView({ category, posts, totalPages, baseUrl, homeHref = "/", linkBasePath, locale, dateLocale = "en-US", }) {
|
|
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: `container ${styles.container}`, children: [_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, 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 })] }))] }));
|
|
17
17
|
}
|
|
@@ -6,8 +6,9 @@ type CategoryPaginationViewProps = {
|
|
|
6
6
|
currentPage: number;
|
|
7
7
|
totalPages: number;
|
|
8
8
|
baseUrl?: string;
|
|
9
|
+
linkBasePath?: string;
|
|
9
10
|
locale?: Locale;
|
|
10
11
|
dateLocale?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function CategoryPaginationView({ category, posts, currentPage, totalPages, baseUrl, locale, dateLocale, }: CategoryPaginationViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function CategoryPaginationView({ category, posts, currentPage, totalPages, baseUrl, linkBasePath, locale, dateLocale, }: CategoryPaginationViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -5,7 +5,7 @@ import styles from "./index.module.css";
|
|
|
5
5
|
import { getEmptyLabel, getPageLabel, getPaginatorBase } from "./index.utils";
|
|
6
6
|
import { Breadcrumbs } from "../../components";
|
|
7
7
|
import { getTranslator } from "../../utils";
|
|
8
|
-
export function CategoryPaginationView({ category, posts, currentPage, totalPages, baseUrl, locale, dateLocale = "en-US", }) {
|
|
8
|
+
export function CategoryPaginationView({ category, posts, currentPage, totalPages, baseUrl, linkBasePath, locale, dateLocale = "en-US", }) {
|
|
9
9
|
const paginatorBase = getPaginatorBase(category, baseUrl);
|
|
10
10
|
const pageLabel = getPageLabel(locale, currentPage);
|
|
11
11
|
const emptyLabel = getEmptyLabel(locale);
|
|
@@ -14,5 +14,5 @@ export function CategoryPaginationView({ category, posts, currentPage, totalPage
|
|
|
14
14
|
{ label: "Home", href: paginatorBase || "/" },
|
|
15
15
|
{ label: category.name },
|
|
16
16
|
{ label: pageLabel },
|
|
17
|
-
] }), _jsx("h1", { className: styles.title, children: category.name }), _jsx("p", { className: styles.pageLabel, children: pageLabel })] }), posts.length === 0 ? (_jsx("p", { className: styles.empty, children: emptyLabel })) : (_jsxs("section", { "aria-label": t("category.pageLabel", { page: currentPage }), className: styles.gridSection, children: [_jsx("div", { className: styles.grid, children: posts.map((post) => (_jsx(PostCard, { post: post, categorySlug: category.slug, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: currentPage, totalPages: totalPages, baseUrl: paginatorBase, locale: locale })] }))] }));
|
|
17
|
+
] }), _jsx("h1", { className: styles.title, children: category.name }), _jsx("p", { className: styles.pageLabel, children: pageLabel })] }), posts.length === 0 ? (_jsx("p", { className: styles.empty, children: emptyLabel })) : (_jsxs("section", { "aria-label": t("category.pageLabel", { page: currentPage }), 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: currentPage, totalPages: totalPages, baseUrl: paginatorBase, locale: locale })] }))] }));
|
|
18
18
|
}
|
|
@@ -6,8 +6,9 @@ type HomePaginationViewProps = {
|
|
|
6
6
|
totalPages: number;
|
|
7
7
|
error?: string | null;
|
|
8
8
|
baseUrl?: string;
|
|
9
|
+
linkBasePath?: string;
|
|
9
10
|
locale?: Locale;
|
|
10
11
|
dateLocale?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function HomePaginationView({ posts, currentPage, totalPages, error, baseUrl, locale, dateLocale, }: HomePaginationViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function HomePaginationView({ posts, currentPage, totalPages, error, baseUrl, linkBasePath, locale, dateLocale, }: HomePaginationViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -3,7 +3,7 @@ import Paginator from "../../components/Paginator";
|
|
|
3
3
|
import PostCard from "../../components/PostCard";
|
|
4
4
|
import styles from "./index.module.css";
|
|
5
5
|
import { buildHomePaginationCopy } from "./index.utils";
|
|
6
|
-
export function HomePaginationView({ posts, currentPage, totalPages, error, baseUrl = "", locale, dateLocale = "en-US", }) {
|
|
6
|
+
export function HomePaginationView({ posts, currentPage, totalPages, error, baseUrl = "", linkBasePath, locale, dateLocale = "en-US", }) {
|
|
7
7
|
const copy = buildHomePaginationCopy(locale, currentPage, error);
|
|
8
|
-
return (_jsxs("div", { className: `container ${styles.container}`, children: [_jsxs("header", { className: styles.header, children: [_jsx("h1", { className: styles.title, children: copy.title }), _jsx("p", { className: styles.subtitle, children: copy.subtitle })] }), error ? (_jsx("div", { className: `card ${styles.errorCard}`, children: copy.errorText && _jsx("p", { children: copy.errorText }) })) : posts.length === 0 ? (_jsx("p", { className: styles.empty, children: copy.empty })) : (_jsxs("section", { "aria-label": copy.title, className: styles.gridSection, role: "region", children: [_jsx("div", { className: styles.grid, children: posts.map((post) => (_jsx(PostCard, { post: post, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: currentPage, totalPages: totalPages, baseUrl: baseUrl, locale: locale })] }))] }));
|
|
8
|
+
return (_jsxs("div", { className: `container ${styles.container}`, children: [_jsxs("header", { className: styles.header, children: [_jsx("h1", { className: styles.title, children: copy.title }), _jsx("p", { className: styles.subtitle, children: copy.subtitle })] }), error ? (_jsx("div", { className: `card ${styles.errorCard}`, children: copy.errorText && _jsx("p", { children: copy.errorText }) })) : posts.length === 0 ? (_jsx("p", { className: styles.empty, children: copy.empty })) : (_jsxs("section", { "aria-label": copy.title, className: styles.gridSection, role: "region", children: [_jsx("div", { className: styles.grid, children: posts.map((post) => (_jsx(PostCard, { post: post, basePath: linkBasePath, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: currentPage, totalPages: totalPages, baseUrl: baseUrl, locale: locale })] }))] }));
|
|
9
9
|
}
|
|
@@ -6,8 +6,9 @@ type HomeViewProps = {
|
|
|
6
6
|
error?: string | null;
|
|
7
7
|
totalPages: number;
|
|
8
8
|
baseUrl?: string;
|
|
9
|
+
linkBasePath?: string;
|
|
9
10
|
locale?: Locale;
|
|
10
11
|
dateLocale?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl, locale, dateLocale, }: HomeViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl, linkBasePath, locale, dateLocale, }: HomeViewProps): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -9,10 +9,10 @@ function truncateLabel(label, max = 20) {
|
|
|
9
9
|
const trimmed = label.trim();
|
|
10
10
|
return trimmed.length > max ? `${trimmed.slice(0, max)}...` : trimmed;
|
|
11
11
|
}
|
|
12
|
-
export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl = "", locale, dateLocale = "en-US", }) {
|
|
12
|
+
export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUrl = "", linkBasePath, locale, dateLocale = "en-US", }) {
|
|
13
13
|
const copy = getHomeCopy(locale);
|
|
14
14
|
const featuredModel = featuredPost
|
|
15
|
-
? buildFeaturedViewModel(featuredPost, locale, dateLocale)
|
|
15
|
+
? buildFeaturedViewModel(featuredPost, locale, dateLocale, linkBasePath)
|
|
16
16
|
: null;
|
|
17
17
|
return (_jsx("div", { className: `container ${styles.container}`, children: error ? (_jsxs("div", { className: styles.errorBox, children: [_jsxs("p", { children: [copy.errorTitle, ": ", error] }), _jsx("p", { className: styles.errorHint, children: copy.errorHint })] })) : !featuredModel && regularPosts.length === 0 ? (_jsx("p", { className: styles.empty, children: copy.empty })) : (_jsxs(_Fragment, { children: [featuredModel && (_jsxs("article", { className: `card ${styles.featured} ${featuredModel.image
|
|
18
18
|
? styles.featuredWithImage
|
|
@@ -21,5 +21,5 @@ export function HomeView({ featuredPost, regularPosts, error, totalPages, baseUr
|
|
|
21
21
|
__html: featuredModel.titleHtml,
|
|
22
22
|
}, className: styles.featuredTitle }) }), _jsx("div", { dangerouslySetInnerHTML: {
|
|
23
23
|
__html: featuredModel.excerptHtml,
|
|
24
|
-
}, 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, locale: locale, dateLocale: dateLocale }, post.id))) }), _jsx(Paginator, { currentPage: 1, totalPages: totalPages, baseUrl: baseUrl, locale: locale })] })) }));
|
|
24
|
+
}, 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 })] })) }));
|
|
25
25
|
}
|
|
@@ -20,4 +20,4 @@ export type FeaturedViewModel = {
|
|
|
20
20
|
alt: string;
|
|
21
21
|
} | undefined;
|
|
22
22
|
};
|
|
23
|
-
export declare const buildFeaturedViewModel: (post: WPPost, locale?: Locale, dateLocale?: string) => FeaturedViewModel;
|
|
23
|
+
export declare const buildFeaturedViewModel: (post: WPPost, locale?: Locale, dateLocale?: string, basePath?: string) => FeaturedViewModel;
|
|
@@ -9,7 +9,7 @@ export const getHomeCopy = (locale) => {
|
|
|
9
9
|
errorHint: t("home.errorHint"),
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export const buildFeaturedViewModel = (post, locale, dateLocale = "en-US") => {
|
|
12
|
+
export const buildFeaturedViewModel = (post, locale, dateLocale = "en-US", basePath) => {
|
|
13
13
|
const t = getTranslator(locale);
|
|
14
14
|
const featuredMedia = getFeaturedMedia(post);
|
|
15
15
|
const imageUrl = featuredMedia?.source_url;
|
|
@@ -19,9 +19,10 @@ export const buildFeaturedViewModel = (post, locale, dateLocale = "en-US") => {
|
|
|
19
19
|
post,
|
|
20
20
|
categorySlug: primaryCategory?.slug,
|
|
21
21
|
locale,
|
|
22
|
+
basePath,
|
|
22
23
|
});
|
|
23
24
|
const badgeUrl = primaryCategory
|
|
24
|
-
? buildCategoryUrl(primaryCategory.slug, locale)
|
|
25
|
+
? buildCategoryUrl(primaryCategory.slug, locale, basePath)
|
|
25
26
|
: null;
|
|
26
27
|
return {
|
|
27
28
|
postUrl,
|