@webbio/strapi-plugin-page-builder 0.11.10-platform → 0.11.12-platform

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webbio/strapi-plugin-page-builder",
3
- "version": "0.11.10-platform",
3
+ "version": "0.11.12-platform",
4
4
  "description": "This is the description of the plugin.",
5
5
  "scripts": {
6
6
  "develop": "tsc -p tsconfig.server.json -w",
@@ -32,8 +32,8 @@
32
32
  "aws-sdk": "^2.1528.0",
33
33
  "handlebars": "^4.7.8",
34
34
  "react-select": "^5.7.4",
35
- "slugify": "^1.6.6",
36
- "yarn": "^1.22.21"
35
+ "sitemap": "^7.1.1",
36
+ "slugify": "^1.6.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/react": "^18.2.21",
@@ -8,6 +8,7 @@ const page_type_1 = __importDefault(require("./page-type"));
8
8
  const collection_types_1 = __importDefault(require("./collection-types"));
9
9
  const template_1 = __importDefault(require("./template"));
10
10
  const platform_1 = __importDefault(require("./platform"));
11
+ const sitemap_1 = __importDefault(require("./sitemap"));
11
12
  const private_content_1 = __importDefault(require("./private-content"));
12
13
  exports.default = {
13
14
  page: page_1.default,
@@ -15,5 +16,6 @@ exports.default = {
15
16
  'collection-types': collection_types_1.default,
16
17
  template: template_1.default,
17
18
  platform: platform_1.default,
19
+ sitemap: sitemap_1.default,
18
20
  'private-content': private_content_1.default
19
21
  };
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const sitemap_1 = require("sitemap");
4
- const stream_1 = require("stream");
3
+ const utils_1 = require("@strapi/utils");
4
+ const constants_1 = require("../../shared/utils/constants");
5
5
  exports.default = {
6
6
  async generate(ctx) {
7
- const domain = 'http://localhost:3000/ketenafspraken';
8
- ctx.set('Content-Type', 'text/xml');
9
- const entities = await strapi.service('plugin::page-builder.sitemap').generateSitemap(domain);
10
- const links = entities.map(({ path }) => ({
11
- url: `/${path}`,
12
- changefreq: 'daily',
13
- priority: 0.7
14
- }));
15
- const stream = new sitemap_1.SitemapStream({ hostname: 'http://localhost:3000/ketenafspraken' });
16
- const sitemap = await (0, sitemap_1.streamToPromise)(stream_1.Readable.from(links).pipe(stream)).then((data) => data.toString());
17
- console.log(sitemap);
18
- return sitemap;
7
+ var _a;
8
+ try {
9
+ ctx.set('Content-Type', 'text/xml');
10
+ const domain = (_a = ctx.query) === null || _a === void 0 ? void 0 : _a.domain;
11
+ if (domain == null) {
12
+ return ctx.badRequest('Domain is required.');
13
+ }
14
+ const platform = await strapi.query(constants_1.PLATFORM_UID).findOne({
15
+ select: ['domain'],
16
+ where: {
17
+ domain
18
+ }
19
+ });
20
+ if (platform == null) {
21
+ return ctx.notFound('No platform found for specified domain.');
22
+ }
23
+ return strapi.service('plugin::page-builder.sitemap').generateSitemap(domain);
24
+ }
25
+ catch (error) {
26
+ throw new utils_1.errors.ApplicationError('Unknown error while generating the sitemap.');
27
+ }
19
28
  }
20
29
  };
@@ -97,6 +97,17 @@ const routes = {
97
97
  handler: 'platform.findPageTypesByPlatform'
98
98
  }
99
99
  ]
100
+ },
101
+ sitemap: {
102
+ type: 'content-api',
103
+ prefix: undefined,
104
+ routes: [
105
+ {
106
+ method: 'GET',
107
+ path: '/sitemap',
108
+ handler: 'sitemap.generate'
109
+ }
110
+ ]
100
111
  }
101
112
  };
102
113
  exports.default = routes;
@@ -16,11 +16,6 @@
16
16
  },
17
17
  "domain": {
18
18
  "type": "string"
19
- },
20
- "platformEmails": {
21
- "type": "component",
22
- "repeatable": false,
23
- "component": "internal.platform-email"
24
19
  }
25
20
  }
26
21
  }
@@ -9,6 +9,7 @@ const page_type_1 = __importDefault(require("./page-type"));
9
9
  const collection_types_1 = __importDefault(require("./collection-types"));
10
10
  const template_1 = __importDefault(require("./template"));
11
11
  const platform_1 = __importDefault(require("./platform"));
12
+ const sitemap_1 = __importDefault(require("./sitemap"));
12
13
  const email_1 = __importDefault(require("./email"));
13
14
  const private_content_1 = __importDefault(require("./private-content"));
14
15
  exports.default = {
@@ -18,6 +19,7 @@ exports.default = {
18
19
  'collection-types': collection_types_1.default,
19
20
  template: template_1.default,
20
21
  platform: platform_1.default,
22
+ sitemap: sitemap_1.default,
21
23
  email: email_1.default,
22
24
  'private-content': private_content_1.default
23
25
  };
@@ -10,6 +10,11 @@ const extendPlatform = () => {
10
10
  type: 'boolean',
11
11
  required: false,
12
12
  default: false
13
+ },
14
+ platformEmails: {
15
+ type: 'component',
16
+ repeatable: false,
17
+ component: 'internal.platform-email'
13
18
  }
14
19
  };
15
20
  delete platformContentType.attributes.username;
@@ -1,17 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const sitemap_1 = require("sitemap");
4
+ const constants_1 = require("../../shared/utils/constants");
3
5
  exports.default = {
4
6
  async generateSitemap(domain) {
5
- const paths = await strapi.entityService.findMany('api::page.page', {
6
- fields: ['path'],
7
- filters: {
8
- platform: {
9
- domain: {
10
- $eq: domain
11
- }
7
+ try {
8
+ const entities = await strapi.query(constants_1.PAGE_UID).findMany({
9
+ select: ['path', 'updatedAt'],
10
+ filters: {
11
+ $and: [
12
+ {
13
+ platform: {
14
+ domain
15
+ }
16
+ },
17
+ {
18
+ path: {
19
+ $notNull: true
20
+ }
21
+ },
22
+ {
23
+ publishedAt: {
24
+ $notNull: true
25
+ }
26
+ }
27
+ ]
12
28
  }
29
+ });
30
+ const sitemapStream = new sitemap_1.SitemapStream();
31
+ for (const entity of entities) {
32
+ const { path, updatedAt } = entity;
33
+ sitemapStream.write({
34
+ url: `${domain}${path}`,
35
+ changefreq: 'always',
36
+ lastmod: updatedAt,
37
+ priority: 1
38
+ });
13
39
  }
14
- });
15
- return paths;
40
+ sitemapStream.end();
41
+ const sitemapPromise = await (0, sitemap_1.streamToPromise)(sitemapStream);
42
+ const sitemap = sitemapPromise.toString();
43
+ return sitemap;
44
+ }
45
+ catch (error) {
46
+ console.error(error);
47
+ throw new Error(`Error generating sitemap for domain ${domain}`);
48
+ }
16
49
  }
17
50
  };