@anywayseo/gatsby-plugin 2.0.0 → 2.1.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.js +17 -12
- package/package.json +1 -1
- package/types/index.d.ts +5 -0
- package/utils/strapi-source/schema/navigation.d.ts +1 -1
- package/utils/strapi-source/schema/navigation.js +2 -2
- package/utils/strapi-source/strapi-navigation/index.js +8 -6
- package/utils/strapi-source/strapi-navigation/types.d.ts +18 -1
package/gatsby-node.js
CHANGED
|
@@ -81,11 +81,11 @@ function createStrapiPages(_a, root_1) {
|
|
|
81
81
|
let pageCount = 0;
|
|
82
82
|
strapiPages.forEach(({ id, slug, title, locale }) => {
|
|
83
83
|
if (slug === slug_1.DUMMY_PAGE_SLUG) {
|
|
84
|
-
reporter.
|
|
84
|
+
reporter.warn('Skipping page creation: dummy page detected');
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
if (!title && !slug) {
|
|
88
|
-
reporter.
|
|
88
|
+
reporter.warn('Skipping page creation: empty page detected');
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
const strapiPageTemplate = (0, path_1.resolve)(root, `./src/templates/strapi-page.tsx`);
|
|
@@ -104,9 +104,9 @@ function createStrapiPages(_a, root_1) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
function createMdxPages(_a, root_1) {
|
|
107
|
-
return __awaiter(this, arguments, void 0, function* ({ actions,
|
|
108
|
-
var _b, _c;
|
|
109
|
-
reporter.info('Starting to create
|
|
107
|
+
return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
|
|
108
|
+
var _b, _c, _d, _e, _f, _g;
|
|
109
|
+
reporter.info('Starting to create MDX pages');
|
|
110
110
|
try {
|
|
111
111
|
const result = yield graphql(`
|
|
112
112
|
query GetAllMdxPage {
|
|
@@ -121,26 +121,31 @@ function createMdxPages(_a, root_1) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
|
+
allStrapiPage {
|
|
125
|
+
nodes {
|
|
126
|
+
slug
|
|
127
|
+
}
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
`);
|
|
126
131
|
if (result.errors) {
|
|
127
|
-
throw new Error(`There was an error loading your
|
|
132
|
+
throw new Error(`There was an error loading your MDX pages: ${result.errors}`);
|
|
128
133
|
}
|
|
129
|
-
const mdxPages = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.allMdx) === null || _c === void 0 ? void 0 : _c.nodes;
|
|
130
|
-
|
|
134
|
+
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 : [];
|
|
135
|
+
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 : [];
|
|
136
|
+
if (!mdxPages.length) {
|
|
131
137
|
reporter.warn('No MDX pages found. Skipping MDX page creation.');
|
|
132
138
|
return;
|
|
133
139
|
}
|
|
134
140
|
reporter.info(`Found ${mdxPages.length} MDX pages`);
|
|
135
|
-
const existingPages = [...store.getState().pages.values()];
|
|
136
141
|
let count = 0;
|
|
137
142
|
mdxPages.forEach(({ frontmatter, internal }) => {
|
|
138
143
|
const slug = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.slug;
|
|
139
144
|
const contentFilePath = internal.contentFilePath;
|
|
140
145
|
if (slug && contentFilePath) {
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
reporter.warn(`Skipping
|
|
146
|
+
const existingPage = strapiPages.find((strapiPage) => (0, slug_1.normalizeSlug)(strapiPage === null || strapiPage === void 0 ? void 0 : strapiPage.slug) === (0, slug_1.normalizeSlug)(slug));
|
|
147
|
+
if (!!existingPage) {
|
|
148
|
+
reporter.warn(`Skipping MDX page creation: "${slug}" already exists`);
|
|
144
149
|
return;
|
|
145
150
|
}
|
|
146
151
|
const mdxPageTemplate = (0, path_1.resolve)(root, `./src/templates/mdx-page.jsx`);
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -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
|
`;
|
|
@@ -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 {};
|