itmar-block-packages 1.10.0 → 1.10.1
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/README.md +3 -0
- package/build/index.asset.php +1 -1
- package/build/index.js +3 -3
- package/package.json +1 -1
- package/src/wordpressApi.js +33 -12
package/package.json
CHANGED
package/src/wordpressApi.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
ToggleControl,
|
|
7
7
|
} from "@wordpress/components";
|
|
8
8
|
import apiFetch from "@wordpress/api-fetch";
|
|
9
|
+
import { addQueryArgs } from "@wordpress/url";
|
|
9
10
|
|
|
10
11
|
//const _ = require("lodash");
|
|
11
12
|
|
|
@@ -539,10 +540,31 @@ const ChoiceControl = (props) => {
|
|
|
539
540
|
|
|
540
541
|
//固定ページ取得RestAPI関数
|
|
541
542
|
export const fetchPagesOptions = async (home_url) => {
|
|
542
|
-
const
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
543
|
+
const allPages = [];
|
|
544
|
+
let page = 1;
|
|
545
|
+
|
|
546
|
+
while (true) {
|
|
547
|
+
const items = await apiFetch({
|
|
548
|
+
path: addQueryArgs("/wp/v2/pages", {
|
|
549
|
+
status: "publish", // 公開のみ
|
|
550
|
+
per_page: 100, // 最大100
|
|
551
|
+
page,
|
|
552
|
+
// orderby: "title",
|
|
553
|
+
// order: "asc",
|
|
554
|
+
}),
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
allPages.push(...items);
|
|
558
|
+
|
|
559
|
+
// 100件未満ならこれが最後
|
|
560
|
+
if (!items || items.length < 100) break;
|
|
561
|
+
|
|
562
|
+
page++;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// ページIDが-1である要素をホーム要素として作成
|
|
566
|
+
if (!allPages.some((p) => p.id === -1)) {
|
|
567
|
+
allPages.unshift({
|
|
546
568
|
id: -1,
|
|
547
569
|
title: { rendered: "ホーム" },
|
|
548
570
|
link: home_url,
|
|
@@ -550,14 +572,13 @@ export const fetchPagesOptions = async (home_url) => {
|
|
|
550
572
|
});
|
|
551
573
|
}
|
|
552
574
|
|
|
553
|
-
const ret_pages =
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
: [];
|
|
575
|
+
const ret_pages = allPages.map((p) => ({
|
|
576
|
+
value: p.id,
|
|
577
|
+
slug: p.slug,
|
|
578
|
+
label: p.title?.rendered ?? "",
|
|
579
|
+
// 階層ページでも正しいURLになるようにRESTのlinkを優先
|
|
580
|
+
link: p.link || (p.slug ? `${home_url}/${p.slug}` : home_url),
|
|
581
|
+
}));
|
|
561
582
|
|
|
562
583
|
return ret_pages;
|
|
563
584
|
};
|