@anywayseo/gatsby-plugin 2.0.0 → 2.2.0
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/gatsby-node.d.ts +4 -3
- package/gatsby-node.js +16 -137
- package/index.d.ts +0 -1
- package/index.js +1 -4
- package/package.json +1 -1
- package/types/index.d.ts +3 -27
- package/utils/create-pages/index.d.ts +3 -0
- package/utils/create-pages/index.js +9 -0
- package/utils/create-pages/mdx/index.d.ts +2 -0
- package/utils/create-pages/mdx/index.js +76 -0
- package/utils/create-pages/mdx/types.d.ts +18 -0
- package/utils/create-pages/mdx/types.js +2 -0
- package/utils/create-pages/redirect/index.d.ts +2 -0
- package/utils/create-pages/redirect/index.js +28 -0
- package/utils/create-pages/strapi/index.d.ts +2 -0
- package/utils/create-pages/strapi/index.js +69 -0
- package/utils/create-pages/strapi/types.d.ts +13 -0
- package/utils/create-pages/strapi/types.js +2 -0
- package/utils/source.d.ts +2 -1
- package/utils/source.js +4 -4
- package/utils/strapi-source/schema/navigation.d.ts +1 -1
- package/utils/strapi-source/schema/navigation.js +2 -2
- package/utils/strapi-source/strapi-content/fetch-entities.d.ts +4 -0
- package/utils/strapi-source/strapi-content/fetch-entities.js +60 -0
- package/utils/strapi-source/strapi-content/get-endpoints.js +8 -4
- package/utils/strapi-source/strapi-content/helpers.d.ts +2 -2
- package/utils/strapi-source/strapi-content/index.d.ts +2 -1
- package/utils/strapi-source/strapi-content/index.js +66 -63
- package/utils/strapi-source/strapi-content/types.d.ts +34 -9
- package/utils/strapi-source/strapi-content/utils.d.ts +1 -1
- package/utils/strapi-source/strapi-content/utils.js +2 -5
- package/utils/strapi-source/strapi-navigation/index.js +8 -6
- package/utils/strapi-source/strapi-navigation/types.d.ts +18 -1
- package/utils/strapi-source/strapi-content/fetch-entity.d.ts +0 -4
- package/utils/strapi-source/strapi-content/fetch-entity.js +0 -35
- /package/utils/{slug.d.ts → create-pages/slug.d.ts} +0 -0
- /package/utils/{slug.js → create-pages/slug.js} +0 -0
package/gatsby-node.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { CreatePagesArgs, CreateSchemaCustomizationArgs, CreateWebpackConfigArgs, SourceNodesArgs } from 'gatsby';
|
|
1
|
+
import type { CreatePagesArgs, CreateSchemaCustomizationArgs, CreateWebpackConfigArgs, PreInitArgs, SourceNodesArgs } from 'gatsby';
|
|
2
2
|
import type { IPluginOptions } from './types';
|
|
3
3
|
export declare function onCreateWebpackConfig(args: CreateWebpackConfigArgs): void;
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function onPreInit(args: PreInitArgs, options: IPluginOptions): void;
|
|
5
|
+
export declare function createSchemaCustomization(args: CreateSchemaCustomizationArgs): void;
|
|
5
6
|
export declare function sourceNodes(args: SourceNodesArgs, options: IPluginOptions): Promise<void>;
|
|
6
|
-
export declare function createPages(args: CreatePagesArgs
|
|
7
|
+
export declare function createPages(args: CreatePagesArgs): Promise<void>;
|
package/gatsby-node.js
CHANGED
|
@@ -10,12 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.onCreateWebpackConfig = onCreateWebpackConfig;
|
|
13
|
+
exports.onPreInit = onPreInit;
|
|
13
14
|
exports.createSchemaCustomization = createSchemaCustomization;
|
|
14
15
|
exports.sourceNodes = sourceNodes;
|
|
15
16
|
exports.createPages = createPages;
|
|
16
17
|
const path_1 = require("path");
|
|
17
|
-
const
|
|
18
|
+
const source_1 = require("./utils/source");
|
|
18
19
|
const strapi_source_1 = require("./utils/strapi-source");
|
|
20
|
+
const create_pages_1 = require("./utils/create-pages");
|
|
21
|
+
let source;
|
|
19
22
|
function onCreateWebpackConfig(args) {
|
|
20
23
|
const { actions, store } = args;
|
|
21
24
|
const root = store.getState().program.directory;
|
|
@@ -25,9 +28,13 @@ function onCreateWebpackConfig(args) {
|
|
|
25
28
|
},
|
|
26
29
|
});
|
|
27
30
|
}
|
|
28
|
-
function
|
|
31
|
+
function onPreInit(args, options) {
|
|
32
|
+
const { reporter } = args;
|
|
33
|
+
reporter.info('Loaded anywayseo-gatsby-plugin');
|
|
34
|
+
source = (0, source_1.extractValidSource)(options.source, reporter);
|
|
35
|
+
}
|
|
36
|
+
function createSchemaCustomization(args) {
|
|
29
37
|
const { actions, reporter } = args;
|
|
30
|
-
const { source } = options;
|
|
31
38
|
if (source === 'local') {
|
|
32
39
|
reporter.warn('Local source mode enabled. Apply Strapi type definitions fallback.');
|
|
33
40
|
actions.createTypes(strapi_source_1.typeDefs);
|
|
@@ -36,157 +43,29 @@ function createSchemaCustomization(args, options) {
|
|
|
36
43
|
function sourceNodes(args, options) {
|
|
37
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
45
|
const { reporter } = args;
|
|
39
|
-
const {
|
|
46
|
+
const { strapiApiUrl, strapiAccessToken, pageSize, skipFileDownloads = false } = options;
|
|
40
47
|
if (source === 'local') {
|
|
41
48
|
reporter.warn('Local source mode enabled. Skipping Strapi source nodes.');
|
|
42
49
|
}
|
|
43
50
|
else {
|
|
44
51
|
const strapiClient = new strapi_source_1.StrapiClient(strapiApiUrl, strapiAccessToken);
|
|
45
|
-
yield (0, strapi_source_1.sourceStrapiContentNode)(args, strapiClient);
|
|
52
|
+
yield (0, strapi_source_1.sourceStrapiContentNode)(args, strapiClient, { pageSize, skipFileDownloads });
|
|
46
53
|
yield (0, strapi_source_1.sourceStrapiNavigationNode)(args, strapiClient);
|
|
47
54
|
yield (0, strapi_source_1.sourceStrapiLocalizationNode)(args, strapiClient);
|
|
48
55
|
}
|
|
49
56
|
});
|
|
50
57
|
}
|
|
51
|
-
function
|
|
52
|
-
return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
|
|
53
|
-
var _b, _c, _d, _e;
|
|
54
|
-
reporter.info('Starting to create Strapi pages');
|
|
55
|
-
try {
|
|
56
|
-
const result = yield graphql(`
|
|
57
|
-
query GetStrapiPages {
|
|
58
|
-
strapiSite {
|
|
59
|
-
locale
|
|
60
|
-
}
|
|
61
|
-
allStrapiPage {
|
|
62
|
-
nodes {
|
|
63
|
-
id
|
|
64
|
-
title
|
|
65
|
-
slug
|
|
66
|
-
locale
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
`);
|
|
71
|
-
if (result.errors) {
|
|
72
|
-
throw new Error(`There was an error loading your Strapi pages: ${result.errors}`);
|
|
73
|
-
}
|
|
74
|
-
const defaultLocale = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.strapiSite) === null || _c === void 0 ? void 0 : _c.locale;
|
|
75
|
-
const strapiPages = (_e = (_d = result.data) === null || _d === void 0 ? void 0 : _d.allStrapiPage) === null || _e === void 0 ? void 0 : _e.nodes;
|
|
76
|
-
if (!(strapiPages === null || strapiPages === void 0 ? void 0 : strapiPages.length)) {
|
|
77
|
-
reporter.warn('No Strapi pages found. Skipping Strapi page creation.');
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
reporter.info(`Found ${strapiPages.length} Strapi pages`);
|
|
81
|
-
let pageCount = 0;
|
|
82
|
-
strapiPages.forEach(({ id, slug, title, locale }) => {
|
|
83
|
-
if (slug === slug_1.DUMMY_PAGE_SLUG) {
|
|
84
|
-
reporter.info('Skipping page creation: dummy page detected.');
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
if (!title && !slug) {
|
|
88
|
-
reporter.info('Skipping page creation: empty page detected.');
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const strapiPageTemplate = (0, path_1.resolve)(root, `./src/templates/strapi-page.tsx`);
|
|
92
|
-
actions.createPage({
|
|
93
|
-
path: `/${locale === defaultLocale ? '' : locale + '/'}${(0, slug_1.normalizeSlug)(slug)}`,
|
|
94
|
-
component: strapiPageTemplate,
|
|
95
|
-
context: { id },
|
|
96
|
-
});
|
|
97
|
-
pageCount++;
|
|
98
|
-
});
|
|
99
|
-
reporter.success(`Created ${pageCount} Strapi pages`);
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
reporter.panicOnBuild(`Error creating Strapi pages: ${error}`);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function createMdxPages(_a, root_1) {
|
|
107
|
-
return __awaiter(this, arguments, void 0, function* ({ actions, store, reporter, graphql }, root) {
|
|
108
|
-
var _b, _c;
|
|
109
|
-
reporter.info('Starting to create Mdx pages');
|
|
110
|
-
try {
|
|
111
|
-
const result = yield graphql(`
|
|
112
|
-
query GetAllMdxPage {
|
|
113
|
-
allMdx {
|
|
114
|
-
nodes {
|
|
115
|
-
frontmatter {
|
|
116
|
-
slug
|
|
117
|
-
title
|
|
118
|
-
}
|
|
119
|
-
internal {
|
|
120
|
-
contentFilePath
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
`);
|
|
126
|
-
if (result.errors) {
|
|
127
|
-
throw new Error(`There was an error loading your Mdx pages: ${result.errors}`);
|
|
128
|
-
}
|
|
129
|
-
const mdxPages = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.allMdx) === null || _c === void 0 ? void 0 : _c.nodes;
|
|
130
|
-
if (!(mdxPages === null || mdxPages === void 0 ? void 0 : mdxPages.length)) {
|
|
131
|
-
reporter.warn('No MDX pages found. Skipping MDX page creation.');
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
reporter.info(`Found ${mdxPages.length} MDX pages`);
|
|
135
|
-
const existingPages = [...store.getState().pages.values()];
|
|
136
|
-
let count = 0;
|
|
137
|
-
mdxPages.forEach(({ frontmatter, internal }) => {
|
|
138
|
-
const slug = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.slug;
|
|
139
|
-
const contentFilePath = internal.contentFilePath;
|
|
140
|
-
if (slug && contentFilePath) {
|
|
141
|
-
const hasRemoteVersion = existingPages.some(({ path }) => path.includes(slug));
|
|
142
|
-
if (hasRemoteVersion) {
|
|
143
|
-
reporter.warn(`Skipping local page, remote exists: ${slug}`);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const mdxPageTemplate = (0, path_1.resolve)(root, `./src/templates/mdx-page.jsx`);
|
|
147
|
-
const component = `${mdxPageTemplate}?__contentFilePath=${contentFilePath}`;
|
|
148
|
-
actions.createPage({
|
|
149
|
-
path: `/${(0, slug_1.normalizeSlug)(slug)}`,
|
|
150
|
-
component,
|
|
151
|
-
context: { slug },
|
|
152
|
-
});
|
|
153
|
-
count++;
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
reporter.success(`Created ${count} MDX pages successfully`);
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
reporter.panicOnBuild(`Error creating MDX pages: ${error}`);
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function createRedirectPage(_a, root_1) {
|
|
164
|
-
return __awaiter(this, arguments, void 0, function* ({ actions, reporter }, root) {
|
|
165
|
-
reporter.info('Starting to create Redirect page');
|
|
166
|
-
try {
|
|
167
|
-
actions.createPage({
|
|
168
|
-
path: '/follow',
|
|
169
|
-
component: (0, path_1.resolve)(root, `./src/templates/redirect-page.tsx`),
|
|
170
|
-
});
|
|
171
|
-
reporter.success(`Created Redirect page successfully`);
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
reporter.panicOnBuild(`Error creating Redirect page: ${error}`);
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
function createPages(args, options) {
|
|
58
|
+
function createPages(args) {
|
|
179
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
180
60
|
const { reporter, store } = args;
|
|
181
|
-
const { source } = options;
|
|
182
61
|
const root = store.getState().program.directory;
|
|
183
62
|
if (source === 'local') {
|
|
184
63
|
reporter.warn('Local source mode enabled. Skipping Strapi page creation.');
|
|
185
64
|
}
|
|
186
65
|
else {
|
|
187
|
-
yield createStrapiPages(args, root);
|
|
66
|
+
yield (0, create_pages_1.createStrapiPages)(args, root);
|
|
188
67
|
}
|
|
189
|
-
yield createMdxPages(args, root);
|
|
190
|
-
yield createRedirectPage(args, root);
|
|
68
|
+
yield (0, create_pages_1.createMdxPages)(args, root);
|
|
69
|
+
yield (0, create_pages_1.createRedirectPage)(args, root);
|
|
191
70
|
});
|
|
192
71
|
}
|
package/index.d.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getValidSource } from './utils/source';
|
package/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.getValidSource = void 0;
|
|
4
|
-
var source_1 = require("./utils/source");
|
|
5
|
-
Object.defineProperty(exports, "getValidSource", { enumerable: true, get: function () { return source_1.getValidSource; } });
|
|
2
|
+
// noop
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import type { IPluginRefOptions } from 'gatsby';
|
|
2
2
|
export type Source = 'local' | 'remote';
|
|
3
3
|
export interface IPluginOptions extends IPluginRefOptions {
|
|
4
|
-
source:
|
|
4
|
+
source: string;
|
|
5
5
|
strapiApiUrl?: string;
|
|
6
6
|
strapiAccessToken?: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
strapiSite?: {
|
|
10
|
-
locale?: string;
|
|
11
|
-
};
|
|
12
|
-
allStrapiPage?: {
|
|
13
|
-
nodes: {
|
|
14
|
-
id: string;
|
|
15
|
-
title?: string | null;
|
|
16
|
-
slug?: string | null;
|
|
17
|
-
locale?: string | null;
|
|
18
|
-
}[];
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
export interface IGetAllMdxPageQuery {
|
|
22
|
-
allMdx?: {
|
|
23
|
-
nodes: {
|
|
24
|
-
frontmatter: {
|
|
25
|
-
slug: string;
|
|
26
|
-
title: string;
|
|
27
|
-
};
|
|
28
|
-
internal: {
|
|
29
|
-
contentFilePath: string;
|
|
30
|
-
};
|
|
31
|
-
}[];
|
|
32
|
-
};
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
skipFileDownloads?: boolean;
|
|
33
9
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createStrapiPages = exports.createRedirectPage = exports.createMdxPages = void 0;
|
|
4
|
+
var mdx_1 = require("./mdx");
|
|
5
|
+
Object.defineProperty(exports, "createMdxPages", { enumerable: true, get: function () { return mdx_1.createMdxPages; } });
|
|
6
|
+
var redirect_1 = require("./redirect");
|
|
7
|
+
Object.defineProperty(exports, "createRedirectPage", { enumerable: true, get: function () { return redirect_1.createRedirectPage; } });
|
|
8
|
+
var strapi_1 = require("./strapi");
|
|
9
|
+
Object.defineProperty(exports, "createStrapiPages", { enumerable: true, get: function () { return strapi_1.createStrapiPages; } });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createMdxPages = createMdxPages;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const slug_1 = require("../slug");
|
|
15
|
+
function createMdxPages(_a, root_1) {
|
|
16
|
+
return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
|
|
17
|
+
var _b, _c, _d, _e, _f, _g;
|
|
18
|
+
reporter.info('Starting to create MDX pages');
|
|
19
|
+
try {
|
|
20
|
+
const result = yield graphql(`
|
|
21
|
+
query GetAllMdxPage {
|
|
22
|
+
allMdx {
|
|
23
|
+
nodes {
|
|
24
|
+
frontmatter {
|
|
25
|
+
slug
|
|
26
|
+
title
|
|
27
|
+
}
|
|
28
|
+
internal {
|
|
29
|
+
contentFilePath
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
allStrapiPage {
|
|
34
|
+
nodes {
|
|
35
|
+
slug
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
`);
|
|
40
|
+
if (result.errors) {
|
|
41
|
+
throw new Error(`There was an error loading your MDX pages: ${result.errors}`);
|
|
42
|
+
}
|
|
43
|
+
const mdxPages = (_d = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.allMdx) === null || _c === void 0 ? void 0 : _c.nodes) !== null && _d !== void 0 ? _d : [];
|
|
44
|
+
const strapiPages = (_g = (_f = (_e = result.data) === null || _e === void 0 ? void 0 : _e.allStrapiPage) === null || _f === void 0 ? void 0 : _f.nodes) !== null && _g !== void 0 ? _g : [];
|
|
45
|
+
if (!mdxPages.length) {
|
|
46
|
+
reporter.warn('No MDX pages found. Skipping MDX page creation.');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
reporter.info(`Found ${mdxPages.length} MDX pages`);
|
|
50
|
+
let count = 0;
|
|
51
|
+
mdxPages.forEach(({ frontmatter, internal }) => {
|
|
52
|
+
const slug = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.slug;
|
|
53
|
+
const contentFilePath = internal.contentFilePath;
|
|
54
|
+
if (slug && contentFilePath) {
|
|
55
|
+
const existingPage = strapiPages.find((strapiPage) => (0, slug_1.normalizeSlug)(strapiPage === null || strapiPage === void 0 ? void 0 : strapiPage.slug) === (0, slug_1.normalizeSlug)(slug));
|
|
56
|
+
if (!!existingPage) {
|
|
57
|
+
reporter.warn(`Skipping MDX page creation: "${slug}" already exists`);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const mdxPageTemplate = (0, path_1.resolve)(root, `./src/templates/mdx-page.jsx`);
|
|
61
|
+
const component = `${mdxPageTemplate}?__contentFilePath=${contentFilePath}`;
|
|
62
|
+
actions.createPage({
|
|
63
|
+
path: `/${(0, slug_1.normalizeSlug)(slug)}`,
|
|
64
|
+
component,
|
|
65
|
+
context: { slug },
|
|
66
|
+
});
|
|
67
|
+
count++;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
reporter.success(`Created ${count} MDX pages successfully`);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
reporter.panicOnBuild(`Error creating MDX pages: ${error}`);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface IGetAllMdxPageQuery {
|
|
2
|
+
allMdx?: {
|
|
3
|
+
nodes: {
|
|
4
|
+
frontmatter: {
|
|
5
|
+
slug: string;
|
|
6
|
+
title: string;
|
|
7
|
+
};
|
|
8
|
+
internal: {
|
|
9
|
+
contentFilePath: string;
|
|
10
|
+
};
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
allStrapiPage?: {
|
|
14
|
+
nodes: {
|
|
15
|
+
slug?: string | null;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createRedirectPage = createRedirectPage;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
function createRedirectPage(_a, root_1) {
|
|
15
|
+
return __awaiter(this, arguments, void 0, function* ({ actions, reporter }, root) {
|
|
16
|
+
reporter.info('Starting to create Redirect page');
|
|
17
|
+
try {
|
|
18
|
+
actions.createPage({
|
|
19
|
+
path: '/follow',
|
|
20
|
+
component: (0, path_1.resolve)(root, `./src/templates/redirect-page.tsx`),
|
|
21
|
+
});
|
|
22
|
+
reporter.success(`Created Redirect page successfully`);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
reporter.panicOnBuild(`Error creating Redirect page: ${error}`);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createStrapiPages = createStrapiPages;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const slug_1 = require("../slug");
|
|
15
|
+
function createStrapiPages(_a, root_1) {
|
|
16
|
+
return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
|
|
17
|
+
var _b, _c, _d, _e;
|
|
18
|
+
reporter.info('Starting to create Strapi pages');
|
|
19
|
+
try {
|
|
20
|
+
const result = yield graphql(`
|
|
21
|
+
query GetAllStrapiPage {
|
|
22
|
+
strapiSite {
|
|
23
|
+
locale
|
|
24
|
+
}
|
|
25
|
+
allStrapiPage {
|
|
26
|
+
nodes {
|
|
27
|
+
id
|
|
28
|
+
title
|
|
29
|
+
slug
|
|
30
|
+
locale
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
`);
|
|
35
|
+
if (result.errors) {
|
|
36
|
+
throw new Error(`There was an error loading your Strapi pages: ${result.errors}`);
|
|
37
|
+
}
|
|
38
|
+
const defaultLocale = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.strapiSite) === null || _c === void 0 ? void 0 : _c.locale;
|
|
39
|
+
const strapiPages = (_e = (_d = result.data) === null || _d === void 0 ? void 0 : _d.allStrapiPage) === null || _e === void 0 ? void 0 : _e.nodes;
|
|
40
|
+
if (!(strapiPages === null || strapiPages === void 0 ? void 0 : strapiPages.length)) {
|
|
41
|
+
reporter.warn('No Strapi pages found. Skipping Strapi page creation.');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
reporter.info(`Found ${strapiPages.length} Strapi pages`);
|
|
45
|
+
let pageCount = 0;
|
|
46
|
+
strapiPages.forEach(({ id, slug, title, locale }) => {
|
|
47
|
+
if (slug === slug_1.DUMMY_PAGE_SLUG) {
|
|
48
|
+
reporter.warn('Skipping page creation: dummy page detected');
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (!title && !slug) {
|
|
52
|
+
reporter.warn('Skipping page creation: empty page detected');
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const strapiPageTemplate = (0, path_1.resolve)(root, `./src/templates/strapi-page.tsx`);
|
|
56
|
+
actions.createPage({
|
|
57
|
+
path: `/${locale === defaultLocale ? '' : locale + '/'}${(0, slug_1.normalizeSlug)(slug)}`,
|
|
58
|
+
component: strapiPageTemplate,
|
|
59
|
+
context: { id },
|
|
60
|
+
});
|
|
61
|
+
pageCount++;
|
|
62
|
+
});
|
|
63
|
+
reporter.success(`Created ${pageCount} Strapi pages`);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
reporter.panicOnBuild(`Error creating Strapi pages: ${error}`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
package/utils/source.d.ts
CHANGED
package/utils/source.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.extractValidSource = extractValidSource;
|
|
4
4
|
function isValidSource(value) {
|
|
5
5
|
const validSources = ['local', 'remote'];
|
|
6
6
|
return validSources.includes(value);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
9
|
-
|
|
8
|
+
function extractValidSource(source, reporter) {
|
|
9
|
+
reporter.info(`Selected source mode is: ${source}`);
|
|
10
10
|
if (source && isValidSource(source)) {
|
|
11
11
|
return source;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
reporter.warn('Invalid or missing GATSBY_SITE_SOURCE. Defaulting to "local".');
|
|
14
14
|
return 'local';
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const navigation = "\n # === STRAPI NAVIGATION DEFINITIONS ===\n type StrapiNavigation implements Node {\n id: ID!\n items: [NavigationGroup!]\n }\n\n type NavigationGroup {\n
|
|
1
|
+
export declare const navigation = "\n # === STRAPI NAVIGATION DEFINITIONS ===\n type StrapiNavigation implements Node {\n id: ID!\n items: [NavigationGroup!]\n }\n\n type NavigationGroup {\n slug: String!\n locale: String!\n items: [NavigationItem!]\n }\n\n type NavigationItem {\n type: String!\n title: String!\n slug: String!\n path: String!\n items: [NavigationItem!]\n menuAttached: Boolean\n }\n ";
|
|
@@ -9,8 +9,8 @@ exports.navigation = `
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type NavigationGroup {
|
|
12
|
-
name: String!
|
|
13
12
|
slug: String!
|
|
13
|
+
locale: String!
|
|
14
14
|
items: [NavigationItem!]
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -19,7 +19,7 @@ exports.navigation = `
|
|
|
19
19
|
title: String!
|
|
20
20
|
slug: String!
|
|
21
21
|
path: String!
|
|
22
|
-
menuAttached: Boolean!
|
|
23
22
|
items: [NavigationItem!]
|
|
23
|
+
menuAttached: Boolean
|
|
24
24
|
}
|
|
25
25
|
`;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Reporter } from 'gatsby';
|
|
2
|
+
import type { StrapiClient } from '../strapi-client';
|
|
3
|
+
import type { Entity, Schema, SchemaEndpoint } from './types';
|
|
4
|
+
export declare function fetchEntities({ endpoint, queryParams, uid }: SchemaEndpoint, schemas: Schema[], strapiClient: StrapiClient, reporter: Reporter): Promise<Entity[]>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.fetchEntities = fetchEntities;
|
|
16
|
+
const qs_1 = __importDefault(require("qs"));
|
|
17
|
+
const clean_entity_1 = require("./clean-entity");
|
|
18
|
+
const helpers_1 = require("./helpers");
|
|
19
|
+
const utils_1 = require("./utils");
|
|
20
|
+
function fetchEntities(_a, schemas_1, strapiClient_1, reporter_1) {
|
|
21
|
+
return __awaiter(this, arguments, void 0, function* ({ endpoint, queryParams, uid }, schemas, strapiClient, reporter) {
|
|
22
|
+
var _b, _c, _d, _e;
|
|
23
|
+
const params = (0, helpers_1.convertQueryParameters)(queryParams);
|
|
24
|
+
const query = qs_1.default.stringify(params, { encodeValuesOnly: true });
|
|
25
|
+
const path = `${endpoint}?${query}`;
|
|
26
|
+
reporter.info(`Starting to fetch ${endpoint} with ${query}`);
|
|
27
|
+
try {
|
|
28
|
+
const result = yield strapiClient.fetch(path);
|
|
29
|
+
const data = (0, utils_1.castArray)(result.data);
|
|
30
|
+
if (result.meta.pagination) {
|
|
31
|
+
const page = (_b = result.meta.pagination.page) !== null && _b !== void 0 ? _b : 1;
|
|
32
|
+
const pageCount = (_c = result.meta.pagination.pageCount) !== null && _c !== void 0 ? _c : 1;
|
|
33
|
+
const pagesToGet = Array.from({ length: pageCount - page }).map((_, index) => index + page + 1);
|
|
34
|
+
for (const pageToGet of pagesToGet) {
|
|
35
|
+
const params = (0, helpers_1.convertQueryParameters)(Object.assign(Object.assign({}, queryParams), { pagination: {
|
|
36
|
+
pageSize: (_e = (_d = queryParams.pagination) === null || _d === void 0 ? void 0 : _d.pageSize) !== null && _e !== void 0 ? _e : utils_1.DEFAULT_PAGE_SIZE,
|
|
37
|
+
page: pageToGet,
|
|
38
|
+
} }));
|
|
39
|
+
const query = qs_1.default.stringify(params, { encodeValuesOnly: true });
|
|
40
|
+
const path = `${endpoint}?${query}`;
|
|
41
|
+
reporter.info(`Starting to fetch next page (${pageToGet}) of ${endpoint}`);
|
|
42
|
+
try {
|
|
43
|
+
const pageResult = yield strapiClient.fetch(path);
|
|
44
|
+
if (pageResult.data) {
|
|
45
|
+
data.push(pageResult.data);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const entities = data.map((entity) => (0, clean_entity_1.cleanEntity)(entity, uid, schemas));
|
|
54
|
+
return entities;
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
reporter.panic(`Failed to fetch data from Strapi ${endpoint}`, error);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEndpoints = getEndpoints;
|
|
4
4
|
const helpers_1 = require("./helpers");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
5
6
|
function getEndpoints(schemas, typeConfigs) {
|
|
6
7
|
const endpoints = schemas.filter((0, helpers_1.isValidEndpoint)(typeConfigs)).map(({ schema, uid, plugin }) => {
|
|
7
8
|
const { kind, singularName, pluralName } = schema;
|
|
8
9
|
const typeConfig = typeConfigs.find((config) => config.singularName === singularName);
|
|
9
|
-
const { queryParams, queryLimit } = typeConfig;
|
|
10
10
|
const defaultSingleTypeQueryParams = { populate: '*' };
|
|
11
11
|
const defaultCollectionTypeQueryParams = {
|
|
12
12
|
populate: '*',
|
|
13
13
|
pagination: {
|
|
14
|
-
pageSize:
|
|
14
|
+
pageSize: utils_1.DEFAULT_PAGE_SIZE,
|
|
15
15
|
page: 1,
|
|
16
16
|
},
|
|
17
17
|
};
|
|
@@ -21,10 +21,14 @@ function getEndpoints(schemas, typeConfigs) {
|
|
|
21
21
|
endpoint,
|
|
22
22
|
singularName,
|
|
23
23
|
kind }, (kind === 'singleType'
|
|
24
|
-
? {
|
|
24
|
+
? {
|
|
25
|
+
queryParams: typeConfig.queryParams
|
|
26
|
+
? Object.assign(Object.assign({}, defaultSingleTypeQueryParams), typeConfig.queryParams) : defaultSingleTypeQueryParams,
|
|
27
|
+
}
|
|
25
28
|
: {
|
|
26
29
|
pluralName: pluralName,
|
|
27
|
-
queryParams: queryParams
|
|
30
|
+
queryParams: typeConfig.queryParams
|
|
31
|
+
? Object.assign(Object.assign({}, defaultCollectionTypeQueryParams), typeConfig.queryParams) : defaultCollectionTypeQueryParams,
|
|
28
32
|
}));
|
|
29
33
|
return schemaEndpoint;
|
|
30
34
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Node } from 'gatsby';
|
|
2
|
-
import type { Schema, TypeConfig } from './types';
|
|
2
|
+
import type { QueryParams, Schema, TypeConfig } from './types';
|
|
3
3
|
export declare function isStrapiOrFileNode(node: Node): boolean;
|
|
4
4
|
export declare function isValidEndpoint(config: TypeConfig[]): (endpoint: Schema) => boolean;
|
|
5
|
-
export declare function convertQueryParameters(queryParameters:
|
|
5
|
+
export declare function convertQueryParameters(queryParameters: QueryParams): QueryParams;
|
|
6
6
|
export declare function getContentTypeSchema(schemas: Schema[], uid: string): Schema | null;
|
|
7
7
|
export declare function makeNodeName(singularName: string): string;
|
|
8
8
|
export declare function makeComponentNodeName(uid: string): string;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { SourceNodesArgs } from 'gatsby';
|
|
2
2
|
import type { StrapiClient } from '../strapi-client';
|
|
3
|
-
|
|
3
|
+
import type { Config } from './types';
|
|
4
|
+
export declare function sourceStrapiContentNode(args: SourceNodesArgs, strapiClient: StrapiClient, config?: Config): Promise<void>;
|
|
@@ -13,89 +13,92 @@ exports.sourceStrapiContentNode = sourceStrapiContentNode;
|
|
|
13
13
|
const create_nodes_1 = require("./create-nodes");
|
|
14
14
|
const delete_nodes_1 = require("./delete-nodes");
|
|
15
15
|
const download_media_1 = require("./download-media");
|
|
16
|
-
const
|
|
16
|
+
const fetch_entities_1 = require("./fetch-entities");
|
|
17
17
|
const fetch_schemas_1 = require("./fetch-schemas");
|
|
18
18
|
const get_endpoints_1 = require("./get-endpoints");
|
|
19
19
|
const get_entities_1 = require("./get-entities");
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'content.faq': {
|
|
40
|
-
populate: '*',
|
|
41
|
-
},
|
|
42
|
-
'content.features': {
|
|
43
|
-
populate: '*',
|
|
44
|
-
},
|
|
45
|
-
'content.game-demo': {
|
|
46
|
-
populate: '*',
|
|
47
|
-
},
|
|
48
|
-
'content.game-info': {
|
|
20
|
+
const utils_1 = require("./utils");
|
|
21
|
+
function sourceStrapiContentNode(args, strapiClient, config) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
24
|
+
const { actions, reporter } = args;
|
|
25
|
+
const { createNode } = actions;
|
|
26
|
+
reporter.info('Starting to fetch content data from Strapi');
|
|
27
|
+
const singleTypes = [
|
|
28
|
+
{
|
|
29
|
+
singularName: 'site',
|
|
30
|
+
queryParams: { populate: '*' },
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
const collectionTypes = [
|
|
34
|
+
{
|
|
35
|
+
singularName: 'page',
|
|
36
|
+
queryParams: {
|
|
37
|
+
populate: {
|
|
38
|
+
seo: {
|
|
49
39
|
populate: '*',
|
|
50
40
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
content: {
|
|
42
|
+
on: {
|
|
43
|
+
'content.faq': {
|
|
44
|
+
populate: '*',
|
|
45
|
+
},
|
|
46
|
+
'content.features': {
|
|
47
|
+
populate: '*',
|
|
48
|
+
},
|
|
49
|
+
'content.game-demo': {
|
|
50
|
+
populate: '*',
|
|
51
|
+
},
|
|
52
|
+
'content.game-info': {
|
|
53
|
+
populate: '*',
|
|
54
|
+
},
|
|
55
|
+
'content.how-to': {
|
|
56
|
+
populate: {
|
|
57
|
+
steps: {
|
|
58
|
+
populate: '*',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
'content.list': {
|
|
63
|
+
populate: '*',
|
|
64
|
+
},
|
|
65
|
+
'content.media': {
|
|
66
|
+
populate: '*',
|
|
67
|
+
},
|
|
68
|
+
'content.pros-cons': {
|
|
69
|
+
populate: '*',
|
|
70
|
+
},
|
|
71
|
+
'content.rich-text': {
|
|
72
|
+
populate: '*',
|
|
73
|
+
},
|
|
74
|
+
'content.table': {
|
|
75
|
+
populate: '*',
|
|
76
|
+
},
|
|
77
|
+
'content.tip': {
|
|
54
78
|
populate: '*',
|
|
55
79
|
},
|
|
56
80
|
},
|
|
57
81
|
},
|
|
58
|
-
|
|
59
|
-
populate: '*',
|
|
60
|
-
},
|
|
61
|
-
'content.media': {
|
|
62
|
-
populate: '*',
|
|
63
|
-
},
|
|
64
|
-
'content.pros-cons': {
|
|
65
|
-
populate: '*',
|
|
66
|
-
},
|
|
67
|
-
'content.rich-text': {
|
|
68
|
-
populate: '*',
|
|
69
|
-
},
|
|
70
|
-
'content.table': {
|
|
71
|
-
populate: '*',
|
|
72
|
-
},
|
|
73
|
-
'content.tip': {
|
|
82
|
+
author: {
|
|
74
83
|
populate: '*',
|
|
75
84
|
},
|
|
76
85
|
},
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
86
|
+
locale: '*',
|
|
87
|
+
pagination: {
|
|
88
|
+
page: 1,
|
|
89
|
+
pageSize: (_a = config === null || config === void 0 ? void 0 : config.pageSize) !== null && _a !== void 0 ? _a : utils_1.DEFAULT_PAGE_SIZE,
|
|
90
|
+
},
|
|
80
91
|
},
|
|
81
92
|
},
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
];
|
|
86
|
-
function sourceStrapiContentNode(args, strapiClient) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
const { actions, reporter, cache } = args;
|
|
89
|
-
const { createNode } = actions;
|
|
90
|
-
reporter.info('Starting to fetch content data from Strapi');
|
|
93
|
+
];
|
|
91
94
|
const schemas = yield (0, fetch_schemas_1.fetchSchemas)(strapiClient);
|
|
92
95
|
const endpoints = (0, get_endpoints_1.getEndpoints)(schemas, [...singleTypes, ...collectionTypes]);
|
|
93
96
|
// TODO: Add cache values extraction (see. getCachedEntities)
|
|
94
|
-
const entities = yield (0, get_entities_1.getEntities)(endpoints, (endpoint) => (0,
|
|
97
|
+
const entities = yield (0, get_entities_1.getEntities)(endpoints, (endpoint) => (0, fetch_entities_1.fetchEntities)(endpoint, schemas, strapiClient, reporter));
|
|
95
98
|
(0, delete_nodes_1.deleteNodes)(entities, endpoints, args);
|
|
96
99
|
for (const [index, { uid }] of endpoints.entries()) {
|
|
97
100
|
if (entities[index]) {
|
|
98
|
-
if (!config.skipFileDownloads) {
|
|
101
|
+
if (!(config === null || config === void 0 ? void 0 : config.skipFileDownloads)) {
|
|
99
102
|
yield (0, download_media_1.downloadMediaFiles)(entities[index], uid, {
|
|
100
103
|
args,
|
|
101
104
|
schemas,
|
|
@@ -1,10 +1,35 @@
|
|
|
1
|
-
export
|
|
1
|
+
export interface Config {
|
|
2
|
+
pageSize?: number;
|
|
3
|
+
skipFileDownloads?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface QueryParams {
|
|
6
|
+
populate?: string | Record<string, any>;
|
|
7
|
+
locale?: string;
|
|
8
|
+
pagination?: {
|
|
9
|
+
pageSize: number;
|
|
10
|
+
page: number;
|
|
11
|
+
};
|
|
12
|
+
filters?: {
|
|
13
|
+
createdAt?: {
|
|
14
|
+
$gt?: number;
|
|
15
|
+
$lt?: number;
|
|
16
|
+
$eq?: number;
|
|
17
|
+
};
|
|
18
|
+
updatedAt?: {
|
|
19
|
+
$gt?: number;
|
|
20
|
+
$lt?: number;
|
|
21
|
+
$eq?: number;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
publicationState?: string;
|
|
25
|
+
status?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface TypeConfig {
|
|
2
28
|
singularName: string;
|
|
3
29
|
pluralName?: string;
|
|
4
|
-
queryParams?:
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export type Schema = {
|
|
30
|
+
queryParams?: QueryParams;
|
|
31
|
+
}
|
|
32
|
+
export interface Schema {
|
|
8
33
|
uid: string;
|
|
9
34
|
schema: {
|
|
10
35
|
kind: 'collectionType' | 'singleType';
|
|
@@ -13,15 +38,15 @@ export type Schema = {
|
|
|
13
38
|
attributes: AnyAttributes;
|
|
14
39
|
};
|
|
15
40
|
plugin?: string;
|
|
16
|
-
}
|
|
17
|
-
export
|
|
41
|
+
}
|
|
42
|
+
export interface SchemaEndpoint {
|
|
18
43
|
kind: 'collectionType' | 'singleType';
|
|
19
44
|
singularName: string;
|
|
20
45
|
pluralName?: string;
|
|
21
46
|
uid: string;
|
|
22
47
|
endpoint: string;
|
|
23
|
-
queryParams:
|
|
24
|
-
}
|
|
48
|
+
queryParams: QueryParams;
|
|
49
|
+
}
|
|
25
50
|
interface AnyAttributes {
|
|
26
51
|
[attribute: string]: any;
|
|
27
52
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const STRAPI_ID_PROPERTY = "strapi_id";
|
|
2
|
+
export declare const DEFAULT_PAGE_SIZE = 25;
|
|
2
3
|
export declare function castArray<T>(value: T | T[]): T[];
|
|
3
4
|
export declare function toSnakeCase(str?: string): string;
|
|
4
5
|
export declare function pick<T extends Record<string, any>>(obj: T, keys: string[]): Partial<T>;
|
|
5
|
-
export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STRAPI_ID_PROPERTY = void 0;
|
|
3
|
+
exports.DEFAULT_PAGE_SIZE = exports.STRAPI_ID_PROPERTY = void 0;
|
|
4
4
|
exports.castArray = castArray;
|
|
5
5
|
exports.toSnakeCase = toSnakeCase;
|
|
6
6
|
exports.pick = pick;
|
|
7
|
-
exports.isPlainObject = isPlainObject;
|
|
8
7
|
exports.STRAPI_ID_PROPERTY = 'strapi_id';
|
|
8
|
+
exports.DEFAULT_PAGE_SIZE = 25;
|
|
9
9
|
function castArray(value) {
|
|
10
10
|
return Array.isArray(value) ? value : [value];
|
|
11
11
|
}
|
|
@@ -25,6 +25,3 @@ function pick(obj, keys) {
|
|
|
25
25
|
}
|
|
26
26
|
return result;
|
|
27
27
|
}
|
|
28
|
-
function isPlainObject(obj) {
|
|
29
|
-
return Object.prototype.toString.call(obj) === '[object Object]';
|
|
30
|
-
}
|
|
@@ -10,21 +10,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.sourceStrapiNavigationNode = sourceStrapiNavigationNode;
|
|
13
|
+
const navigationSlugs = ['header-navigation', 'footer-navigation'];
|
|
13
14
|
function sourceStrapiNavigationNode(args, strapiClient) {
|
|
14
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
16
|
const { actions, reporter, createNodeId, createContentDigest } = args;
|
|
16
17
|
reporter.info('Starting to fetch navigation data from Strapi');
|
|
17
18
|
try {
|
|
18
|
-
const
|
|
19
|
+
const allNavigation = yield strapiClient.fetch('navigation/?orderBy=locale&locale=*');
|
|
20
|
+
const navigation = allNavigation.filter(({ slug }) => navigationSlugs.includes(slug));
|
|
19
21
|
reporter.info(`Found ${navigation.length} navigation objects`);
|
|
20
22
|
const strapiNavigation = [];
|
|
21
|
-
for (const { slug,
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
24
|
-
reporter.warn(`Missing navigation items in ${slug}`);
|
|
23
|
+
for (const { slug, locale } of navigation) {
|
|
24
|
+
const items = yield strapiClient.fetch(`navigation/render/${slug}?locale=${locale}&type=TREE`);
|
|
25
|
+
if (!items.length) {
|
|
26
|
+
reporter.warn(`Missing navigation items in ${slug} with locale ${locale}`);
|
|
25
27
|
continue;
|
|
26
28
|
}
|
|
27
|
-
strapiNavigation.push({
|
|
29
|
+
strapiNavigation.push({ slug, locale, items });
|
|
28
30
|
}
|
|
29
31
|
const nodeContent = JSON.stringify(strapiNavigation);
|
|
30
32
|
const nodeMeta = {
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface INavigationData {
|
|
2
2
|
id: number;
|
|
3
3
|
name: string;
|
|
4
4
|
slug: string;
|
|
5
|
+
locale: string;
|
|
5
6
|
}
|
|
7
|
+
type NavigationItemType = 'WRAPPER' | 'INTERNAL' | 'EXTERNAL';
|
|
8
|
+
export interface INavigationItem {
|
|
9
|
+
id: number;
|
|
10
|
+
documentId: string;
|
|
11
|
+
type: NavigationItemType;
|
|
12
|
+
title: string;
|
|
13
|
+
slug: string;
|
|
14
|
+
path: string;
|
|
15
|
+
items: INavigationItem[];
|
|
16
|
+
order: number;
|
|
17
|
+
uiRouterKey: string;
|
|
18
|
+
additionalFields: Record<string, unknown>;
|
|
19
|
+
collapsed: boolean;
|
|
20
|
+
menuAttached: boolean;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { Reporter } from 'gatsby';
|
|
2
|
-
import type { StrapiClient } from '../strapi-client';
|
|
3
|
-
import type { Entity, Schema, SchemaEndpoint } from './types';
|
|
4
|
-
export declare function fetchEntity({ endpoint, queryParams, uid }: SchemaEndpoint, schemas: Schema[], strapiClient: StrapiClient, reporter: Reporter): Promise<Entity[]>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fetchEntity = fetchEntity;
|
|
16
|
-
const qs_1 = __importDefault(require("qs"));
|
|
17
|
-
const clean_entity_1 = require("./clean-entity");
|
|
18
|
-
const helpers_1 = require("./helpers");
|
|
19
|
-
const utils_1 = require("./utils");
|
|
20
|
-
function fetchEntity(_a, schemas_1, strapiClient_1, reporter_1) {
|
|
21
|
-
return __awaiter(this, arguments, void 0, function* ({ endpoint, queryParams, uid }, schemas, strapiClient, reporter) {
|
|
22
|
-
const params = (0, helpers_1.convertQueryParameters)(queryParams);
|
|
23
|
-
const query = qs_1.default.stringify(params, { encodeValuesOnly: true });
|
|
24
|
-
const path = `${endpoint}?${query}`;
|
|
25
|
-
reporter.info(`Starting to fetch data from Strapi: ${endpoint} with ${query}`);
|
|
26
|
-
try {
|
|
27
|
-
const result = yield strapiClient.fetch(path);
|
|
28
|
-
const entity = (0, utils_1.castArray)(result.data).map((data) => (0, clean_entity_1.cleanEntity)(data, uid, schemas));
|
|
29
|
-
return entity;
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
reporter.panic(`Failed to fetch data from Strapi ${endpoint}`, error);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
File without changes
|
|
File without changes
|