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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itmar-block-packages",
3
- "version": "1.10.0",
3
+ "version": "1.10.1",
4
4
  "description": "We have put together a package of common React components used for WordPress custom blocks.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -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 pages = await apiFetch({ path: "/wp/v2/pages" });
543
- //ページIDが-1である要素をホーム要素として作成
544
- if (pages && !pages.some((page) => page.id === -1)) {
545
- pages.unshift({
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 = pages
554
- ? pages.map((page) => ({
555
- value: page.id,
556
- slug: page.slug,
557
- label: page.title.rendered,
558
- link: `${home_url}/${page.slug}`,
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
  };