@anywayseo/gatsby-plugin 1.0.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @anywayseo/gatsby-plugin
2
+
3
+ Gatsby plugin for creating Anywayseo site
@@ -0,0 +1,6 @@
1
+ import type { CreatePagesArgs, CreateSchemaCustomizationArgs, CreateWebpackConfigArgs, SourceNodesArgs } from 'gatsby';
2
+ import type { IPluginOptions } from './types';
3
+ export declare function onCreateWebpackConfig({ actions, store }: CreateWebpackConfigArgs): void;
4
+ export declare function createSchemaCustomization({ actions }: CreateSchemaCustomizationArgs, options: IPluginOptions): void;
5
+ export declare function sourceNodes(args: SourceNodesArgs, { source, strapiApiUrl, strapiAccessToken }: IPluginOptions): Promise<void>;
6
+ export declare function createPages(args: CreatePagesArgs, { source }: IPluginOptions): Promise<void>;
package/gatsby-node.js ADDED
@@ -0,0 +1,212 @@
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.onCreateWebpackConfig = onCreateWebpackConfig;
13
+ exports.createSchemaCustomization = createSchemaCustomization;
14
+ exports.sourceNodes = sourceNodes;
15
+ exports.createPages = createPages;
16
+ const path_1 = require("path");
17
+ const strapi_client_1 = require("./utils/strapi-client");
18
+ const schema_1 = require("./utils/schema");
19
+ function onCreateWebpackConfig({ actions, store }) {
20
+ const root = store.getState().program.directory;
21
+ actions.setWebpackConfig({
22
+ resolve: {
23
+ modules: [(0, path_1.resolve)(root, 'src'), 'node_modules'],
24
+ },
25
+ });
26
+ }
27
+ function createSchemaCustomization({ actions }, options) {
28
+ if (options.source === 'local') {
29
+ actions.createTypes(schema_1.typeDefs);
30
+ }
31
+ }
32
+ function sourceStrapiNavigationNode(_a, strapiClient_1) {
33
+ return __awaiter(this, arguments, void 0, function* ({ actions, reporter, createNodeId, createContentDigest }, strapiClient) {
34
+ reporter.info('Starting to fetch navigation data from Strapi');
35
+ try {
36
+ const result = yield strapiClient.fetch('navigation');
37
+ if (!result.ok) {
38
+ throw new Error(`Failed to fetch navigation list: ${result.status} ${result.statusText}`);
39
+ }
40
+ const navigation = yield result.json();
41
+ const navigationList = Array.isArray(navigation) ? navigation : [];
42
+ reporter.info(`Found ${navigationList.length} navigation objects`);
43
+ const strapiNavigation = [];
44
+ for (const { slug, name } of navigationList) {
45
+ const result = yield strapiClient.fetch(`navigation/render/${slug}?type=TREE`);
46
+ if (!result.ok) {
47
+ reporter.warn(`Failed to fetch rendered navigation: ${slug} (${result.status})`);
48
+ continue;
49
+ }
50
+ const navigationItems = yield result.json();
51
+ if (!navigationItems.length) {
52
+ reporter.warn(`Missing navigation items in ${slug}`);
53
+ continue;
54
+ }
55
+ strapiNavigation.push({ name, slug, items: navigationItems });
56
+ }
57
+ const nodeContent = JSON.stringify(strapiNavigation);
58
+ const nodeMeta = {
59
+ id: createNodeId(`strapi-navigation-header`),
60
+ parent: null,
61
+ children: [],
62
+ internal: {
63
+ type: `StrapiNavigation`,
64
+ mediaType: `application/json`,
65
+ content: nodeContent,
66
+ contentDigest: createContentDigest(strapiNavigation),
67
+ },
68
+ };
69
+ actions.createNode(Object.assign(Object.assign({}, nodeMeta), { items: strapiNavigation }));
70
+ reporter.success('Navigation node created');
71
+ }
72
+ catch (error) {
73
+ reporter.panicOnBuild('Error fetching navigation from Strapi:', error);
74
+ }
75
+ });
76
+ }
77
+ function sourceNodes(args_1, _a) {
78
+ return __awaiter(this, arguments, void 0, function* (args, { source, strapiApiUrl, strapiAccessToken }) {
79
+ if (source === 'local') {
80
+ args.reporter.warn('Local source mode enabled. Using local navigation data.');
81
+ }
82
+ else {
83
+ const strapiClient = new strapi_client_1.StrapiClient(strapiApiUrl, strapiAccessToken);
84
+ yield sourceStrapiNavigationNode(args, strapiClient);
85
+ }
86
+ });
87
+ }
88
+ function createStrapiPages(_a, root_1) {
89
+ return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
90
+ var _b, _c;
91
+ reporter.info('Starting to create Strapi pages');
92
+ try {
93
+ const result = yield graphql(`
94
+ query GetAllStrapiPageSlug {
95
+ allStrapiPage {
96
+ nodes {
97
+ slug
98
+ }
99
+ }
100
+ }
101
+ `);
102
+ if (result.errors) {
103
+ throw new Error(`There was an error loading your Strapi pages: ${result.errors}`);
104
+ }
105
+ const strapiPages = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.allStrapiPage) === null || _c === void 0 ? void 0 : _c.nodes;
106
+ if (!(strapiPages === null || strapiPages === void 0 ? void 0 : strapiPages.length)) {
107
+ reporter.warn('No Strapi pages found. Skipping Strapi page creation.');
108
+ return;
109
+ }
110
+ reporter.info(`Found ${strapiPages.length} Strapi pages`);
111
+ let count = 0;
112
+ strapiPages.forEach(({ slug }) => {
113
+ if (slug) {
114
+ if (slug === 'dummy') {
115
+ reporter.info('Skipping page creation: dummy page detected.');
116
+ return;
117
+ }
118
+ const strapiPageTemplate = (0, path_1.resolve)(root, `./src/templates/strapi-page.tsx`);
119
+ actions.createPage({
120
+ path: `/${slug === 'index' ? '' : slug}`,
121
+ component: strapiPageTemplate,
122
+ context: { slug },
123
+ });
124
+ count++;
125
+ }
126
+ });
127
+ reporter.success(`Created ${count} Strapi pages`);
128
+ }
129
+ catch (error) {
130
+ reporter.panicOnBuild(`Error creating Strapi pages: ${error}`);
131
+ }
132
+ });
133
+ }
134
+ function createMdxPages(_a, root_1) {
135
+ return __awaiter(this, arguments, void 0, function* ({ actions, reporter, graphql }, root) {
136
+ var _b, _c;
137
+ reporter.info('Starting to create Mdx pages');
138
+ try {
139
+ const result = yield graphql(`
140
+ query GetAllMdxPage {
141
+ allMdx {
142
+ nodes {
143
+ frontmatter {
144
+ slug
145
+ title
146
+ }
147
+ internal {
148
+ contentFilePath
149
+ }
150
+ }
151
+ }
152
+ }
153
+ `);
154
+ if (result.errors) {
155
+ throw new Error(`There was an error loading your Mdx pages: ${result.errors}`);
156
+ }
157
+ const mdxPages = (_c = (_b = result.data) === null || _b === void 0 ? void 0 : _b.allMdx) === null || _c === void 0 ? void 0 : _c.nodes;
158
+ if (!(mdxPages === null || mdxPages === void 0 ? void 0 : mdxPages.length)) {
159
+ reporter.warn('No MDX pages found. Skipping MDX page creation.');
160
+ return;
161
+ }
162
+ reporter.info(`Found ${mdxPages.length} MDX pages`);
163
+ let count = 0;
164
+ mdxPages.forEach(({ frontmatter, internal }) => {
165
+ const slug = frontmatter === null || frontmatter === void 0 ? void 0 : frontmatter.slug;
166
+ const contentFilePath = internal.contentFilePath;
167
+ if (slug && contentFilePath) {
168
+ const mdxPageTemplate = (0, path_1.resolve)(root, `./src/templates/mdx-page.jsx`);
169
+ const component = `${mdxPageTemplate}?__contentFilePath=${contentFilePath}`;
170
+ actions.createPage({
171
+ path: `/${slug === 'index' ? '' : slug}`,
172
+ component,
173
+ context: { slug },
174
+ });
175
+ count++;
176
+ }
177
+ });
178
+ reporter.success(`Created ${count} MDX pages successfully`);
179
+ }
180
+ catch (error) {
181
+ reporter.panicOnBuild(`Error creating MDX pages: ${error}`);
182
+ }
183
+ });
184
+ }
185
+ function createRedirectPage(_a, root_1) {
186
+ return __awaiter(this, arguments, void 0, function* ({ actions, reporter }, root) {
187
+ reporter.info('Starting to create Redirect page');
188
+ try {
189
+ actions.createPage({
190
+ path: '/follow',
191
+ component: (0, path_1.resolve)(root, `./src/templates/redirect-page.tsx`),
192
+ });
193
+ reporter.success(`Created Redirect page successfully`);
194
+ }
195
+ catch (error) {
196
+ reporter.panicOnBuild(`Error creating Redirect page: ${error}`);
197
+ }
198
+ });
199
+ }
200
+ function createPages(args_1, _a) {
201
+ return __awaiter(this, arguments, void 0, function* (args, { source }) {
202
+ const root = args.store.getState().program.directory;
203
+ if (source === 'local') {
204
+ args.reporter.warn('Local source mode enabled. Skipping Strapi page creation.');
205
+ }
206
+ else {
207
+ yield createStrapiPages(args, root);
208
+ }
209
+ yield createMdxPages(args, root);
210
+ yield createRedirectPage(args, root);
211
+ });
212
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@anywayseo/gatsby-plugin",
3
+ "description": "Shared config for Anywayseo sites",
4
+ "version": "1.0.0",
5
+ "author": "zerg41",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "files": [
11
+ "gatsby-node.js",
12
+ "gatsby-node.d.ts",
13
+ "utils",
14
+ "README.md",
15
+ "LICENSE"
16
+ ],
17
+ "main": "gatsby-node.js",
18
+ "types": "gatsby-node.d.ts",
19
+ "scripts": {
20
+ "clean": "rimraf utils types gatsby-node.js gatsby-node.d.ts",
21
+ "build": "npm run clean && tsc",
22
+ "prepack": "npm run build",
23
+ "preversion": "tsc --noEmit",
24
+ "bump:patch": "npm version patch",
25
+ "bump:minor": "npm version minor",
26
+ "bump:major": "npm version major",
27
+ "postversion": "git push --follow-tags && npm publish"
28
+ },
29
+ "devDependencies": {
30
+ "@types/node": "^20.0.0",
31
+ "rimraf": "^6.0.1",
32
+ "typescript": "^5.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "gatsby": "^5.0.0"
36
+ }
37
+ }
@@ -0,0 +1 @@
1
+ export declare const typeDefs = "\n # === BASE DEFINITIONS ===\n type Image {\n localFile: File @link(from: \"localFile\")\n alternativeText: String\n }\n\n type Seo {\n metaTitle: String\n metaDescription: String\n }\n\n type Author {\n name: String\n role: String\n bio: String\n avatar: Image\n }\n\n # === STRAPI DEFINITIONS ===\n type StrapiSite implements Node {\n id: ID!\n name: String\n lang: String\n currency: String\n theme: String\n primaryColor: String\n logo: Image\n seo: Seo\n }\n\n type StrapiPage implements Node {\n id: ID!\n title: String\n slug: String\n seo: Seo\n author: Author\n content: [ContentComponent]\n createdAt: Date @dateformat\n updatedAt: Date @dateformat\n }\n\n # === STRAPI NAVIGATION DEFINITIONS ===\n type StrapiNavigation implements Node {\n id: ID!\n items: [NavigationGroup!]\n }\n\n type NavigationGroup {\n name: String!\n slug: String!\n items: [NavigationItem!]\n }\n\n type NavigationItem {\n type: String!\n title: String!\n slug: String!\n path: String!\n menuAttached: Boolean!\n items: [NavigationItem!]\n }\n\n # === COMPONENT DEFINITIONS ===\n union ContentComponent =\n STRAPI__COMPONENT_CONTENT_FAQ\n | STRAPI__COMPONENT_CONTENT_FEATURES\n | STRAPI__COMPONENT_CONTENT_GAME_DEMO\n | STRAPI__COMPONENT_CONTENT_GAME_INFO\n | STRAPI__COMPONENT_CONTENT_HOW_TO\n | STRAPI__COMPONENT_CONTENT_LIST\n | STRAPI__COMPONENT_CONTENT_MEDIA\n | STRAPI__COMPONENT_CONTENT_PROS_CONS\n | STRAPI__COMPONENT_CONTENT_RICH_TEXT\n | STRAPI__COMPONENT_CONTENT_TABLE\n | STRAPI__COMPONENT_CONTENT_TIP\n\n type STRAPI__COMPONENT_CONTENT_FAQ {\n items: [FaqItem!]\n }\n\n type FaqItem {\n question: String\n answer: String\n }\n\n type STRAPI__COMPONENT_CONTENT_FEATURES {\n items: [ListItem!]\n }\n\n type STRAPI__COMPONENT_CONTENT_PROS_CONS {\n pros: [ListItem!]\n cons: [ListItem!]\n }\n\n type ListItem {\n title: String\n description: String\n }\n\n type STRAPI__COMPONENT_CONTENT_GAME_DEMO {\n name: String\n src: String\n href: String\n previewImage: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_GAME_INFO {\n general: GAME_GENERAL\n features: GAME_FEATURES\n }\n\n type GAME_GENERAL {\n NAME: String\n DEVELOPER: String\n RELEASE_DATE: Date @dateformat\n THEME: String\n TYPE: String\n VOLATILITY: String\n RTP: String\n PAY_LINES: String\n ROWS_WITH_PINS: String\n REELS_NUMBER: String\n MIN_BET: String\n MAX_BET: String\n MAX_WIN: String\n COMPATIBILITY: String\n }\n\n type GAME_FEATURES {\n HAS_DEMO: Boolean\n HAS_AUTOPLAY: Boolean\n HAS_FREE_SPINS: Boolean\n HAS_FAST_SPIN: Boolean\n HAS_BONUS_PURCHASE: Boolean\n HAS_COLLECTION_SYMBOLS: Boolean\n HAS_PROGRESSIVE_JACKPOT: Boolean\n BONUS_FEATURES: String\n FUNCTIONS: String\n LANGUAGES: String\n }\n\n type STRAPI__COMPONENT_CONTENT_HOW_TO {\n steps: [HowToStep!]\n }\n\n type HowToStep {\n title: String!\n description: String\n thumbnail: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_TIP {\n tip: String\n author: Author\n }\n\n type STRAPI__COMPONENT_CONTENT_RICH_TEXT {\n content: RichTextContent\n }\n\n type RichTextContent {\n data: RichTextData\n }\n\n type RichTextData {\n content: String\n }\n\n type STRAPI__COMPONENT_CONTENT_LIST {\n bullet: String\n content: JsonValue\n }\n\n type STRAPI__COMPONENT_CONTENT_MEDIA {\n file: Image\n }\n\n type STRAPI__COMPONENT_CONTENT_TABLE {\n columnNumber: Int\n striped: Boolean\n bordered: Boolean\n scrollable: Boolean\n content: JsonValue\n caption: String\n }\n\n type JsonValue {\n strapi_json_value: JSON\n }\n ";
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeDefs = void 0;
4
+ exports.typeDefs = `
5
+ # === BASE DEFINITIONS ===
6
+ type Image {
7
+ localFile: File @link(from: "localFile")
8
+ alternativeText: String
9
+ }
10
+
11
+ type Seo {
12
+ metaTitle: String
13
+ metaDescription: String
14
+ }
15
+
16
+ type Author {
17
+ name: String
18
+ role: String
19
+ bio: String
20
+ avatar: Image
21
+ }
22
+
23
+ # === STRAPI DEFINITIONS ===
24
+ type StrapiSite implements Node {
25
+ id: ID!
26
+ name: String
27
+ lang: String
28
+ currency: String
29
+ theme: String
30
+ primaryColor: String
31
+ logo: Image
32
+ seo: Seo
33
+ }
34
+
35
+ type StrapiPage implements Node {
36
+ id: ID!
37
+ title: String
38
+ slug: String
39
+ seo: Seo
40
+ author: Author
41
+ content: [ContentComponent]
42
+ createdAt: Date @dateformat
43
+ updatedAt: Date @dateformat
44
+ }
45
+
46
+ # === STRAPI NAVIGATION DEFINITIONS ===
47
+ type StrapiNavigation implements Node {
48
+ id: ID!
49
+ items: [NavigationGroup!]
50
+ }
51
+
52
+ type NavigationGroup {
53
+ name: String!
54
+ slug: String!
55
+ items: [NavigationItem!]
56
+ }
57
+
58
+ type NavigationItem {
59
+ type: String!
60
+ title: String!
61
+ slug: String!
62
+ path: String!
63
+ menuAttached: Boolean!
64
+ items: [NavigationItem!]
65
+ }
66
+
67
+ # === COMPONENT DEFINITIONS ===
68
+ union ContentComponent =
69
+ STRAPI__COMPONENT_CONTENT_FAQ
70
+ | STRAPI__COMPONENT_CONTENT_FEATURES
71
+ | STRAPI__COMPONENT_CONTENT_GAME_DEMO
72
+ | STRAPI__COMPONENT_CONTENT_GAME_INFO
73
+ | STRAPI__COMPONENT_CONTENT_HOW_TO
74
+ | STRAPI__COMPONENT_CONTENT_LIST
75
+ | STRAPI__COMPONENT_CONTENT_MEDIA
76
+ | STRAPI__COMPONENT_CONTENT_PROS_CONS
77
+ | STRAPI__COMPONENT_CONTENT_RICH_TEXT
78
+ | STRAPI__COMPONENT_CONTENT_TABLE
79
+ | STRAPI__COMPONENT_CONTENT_TIP
80
+
81
+ type STRAPI__COMPONENT_CONTENT_FAQ {
82
+ items: [FaqItem!]
83
+ }
84
+
85
+ type FaqItem {
86
+ question: String
87
+ answer: String
88
+ }
89
+
90
+ type STRAPI__COMPONENT_CONTENT_FEATURES {
91
+ items: [ListItem!]
92
+ }
93
+
94
+ type STRAPI__COMPONENT_CONTENT_PROS_CONS {
95
+ pros: [ListItem!]
96
+ cons: [ListItem!]
97
+ }
98
+
99
+ type ListItem {
100
+ title: String
101
+ description: String
102
+ }
103
+
104
+ type STRAPI__COMPONENT_CONTENT_GAME_DEMO {
105
+ name: String
106
+ src: String
107
+ href: String
108
+ previewImage: Image
109
+ }
110
+
111
+ type STRAPI__COMPONENT_CONTENT_GAME_INFO {
112
+ general: GAME_GENERAL
113
+ features: GAME_FEATURES
114
+ }
115
+
116
+ type GAME_GENERAL {
117
+ NAME: String
118
+ DEVELOPER: String
119
+ RELEASE_DATE: Date @dateformat
120
+ THEME: String
121
+ TYPE: String
122
+ VOLATILITY: String
123
+ RTP: String
124
+ PAY_LINES: String
125
+ ROWS_WITH_PINS: String
126
+ REELS_NUMBER: String
127
+ MIN_BET: String
128
+ MAX_BET: String
129
+ MAX_WIN: String
130
+ COMPATIBILITY: String
131
+ }
132
+
133
+ type GAME_FEATURES {
134
+ HAS_DEMO: Boolean
135
+ HAS_AUTOPLAY: Boolean
136
+ HAS_FREE_SPINS: Boolean
137
+ HAS_FAST_SPIN: Boolean
138
+ HAS_BONUS_PURCHASE: Boolean
139
+ HAS_COLLECTION_SYMBOLS: Boolean
140
+ HAS_PROGRESSIVE_JACKPOT: Boolean
141
+ BONUS_FEATURES: String
142
+ FUNCTIONS: String
143
+ LANGUAGES: String
144
+ }
145
+
146
+ type STRAPI__COMPONENT_CONTENT_HOW_TO {
147
+ steps: [HowToStep!]
148
+ }
149
+
150
+ type HowToStep {
151
+ title: String!
152
+ description: String
153
+ thumbnail: Image
154
+ }
155
+
156
+ type STRAPI__COMPONENT_CONTENT_TIP {
157
+ tip: String
158
+ author: Author
159
+ }
160
+
161
+ type STRAPI__COMPONENT_CONTENT_RICH_TEXT {
162
+ content: RichTextContent
163
+ }
164
+
165
+ type RichTextContent {
166
+ data: RichTextData
167
+ }
168
+
169
+ type RichTextData {
170
+ content: String
171
+ }
172
+
173
+ type STRAPI__COMPONENT_CONTENT_LIST {
174
+ bullet: String
175
+ content: JsonValue
176
+ }
177
+
178
+ type STRAPI__COMPONENT_CONTENT_MEDIA {
179
+ file: Image
180
+ }
181
+
182
+ type STRAPI__COMPONENT_CONTENT_TABLE {
183
+ columnNumber: Int
184
+ striped: Boolean
185
+ bordered: Boolean
186
+ scrollable: Boolean
187
+ content: JsonValue
188
+ caption: String
189
+ }
190
+
191
+ type JsonValue {
192
+ strapi_json_value: JSON
193
+ }
194
+ `;
@@ -0,0 +1,6 @@
1
+ export declare class StrapiClient {
2
+ private apiUrl;
3
+ private accessToken;
4
+ constructor(apiUrl?: string, accessToken?: string);
5
+ fetch(path: string): Promise<Response>;
6
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StrapiClient = void 0;
4
+ class StrapiClient {
5
+ constructor(apiUrl, accessToken) {
6
+ if (!apiUrl || !accessToken) {
7
+ throw new Error('Missing STRAPI_API_URL or STRAPI_TOKEN in environment variables.');
8
+ }
9
+ this.apiUrl = apiUrl;
10
+ this.accessToken = accessToken;
11
+ }
12
+ fetch(path) {
13
+ return fetch(`${this.apiUrl}/api/${path}`, {
14
+ headers: {
15
+ Authorization: `Bearer ${this.accessToken}`,
16
+ },
17
+ });
18
+ }
19
+ }
20
+ exports.StrapiClient = StrapiClient;