@prezly/theme-kit-core 10.11.0 → 10.12.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.
@@ -130,8 +130,9 @@ function _generateCategoriesEntries() {
130
130
  categories = context.categories,
131
131
  generateUrl = context.generateUrl;
132
132
  var entries = categories.flatMap(category => _sdk.Category.translations(category).filter(_ref6 => {
133
- var locale = _ref6.locale;
134
- return locales.includes(locale);
133
+ var locale = _ref6.locale,
134
+ public_stories_number = _ref6.public_stories_number;
135
+ return locales.includes(locale) && public_stories_number !== 0;
135
136
  }).map(translation => {
136
137
  var params = _objectSpread(_objectSpread({}, translation), {}, {
137
138
  localeCode: translation.locale
@@ -119,8 +119,9 @@ function _generateCategoriesEntries() {
119
119
  categories = context.categories,
120
120
  generateUrl = context.generateUrl;
121
121
  var entries = categories.flatMap(category => Category.translations(category).filter(_ref6 => {
122
- var locale = _ref6.locale;
123
- return locales.includes(locale);
122
+ var locale = _ref6.locale,
123
+ public_stories_number = _ref6.public_stories_number;
124
+ return locales.includes(locale) && public_stories_number !== 0;
124
125
  }).map(translation => {
125
126
  var params = _objectSpread(_objectSpread({}, translation), {}, {
126
127
  localeCode: translation.locale
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _generate = require("./generate.cjs");
4
+ var _stringify = require("./stringify.cjs");
5
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
6
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
7
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
10
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
13
+ function category(japaneseStories) {
14
+ return {
15
+ id: 1,
16
+ display_name: 'Contacts',
17
+ display_description: null,
18
+ stories_number: 5 + japaneseStories,
19
+ public_stories_number: 5 + japaneseStories,
20
+ image: null,
21
+ is_featured: false,
22
+ i18n: Object.fromEntries([['en', 'contacts', 3], ['fr', 'contacter', 2], ['ja_JP', 'contacts-ja', japaneseStories]].map(_ref => {
23
+ var _ref2 = _slicedToArray(_ref, 3),
24
+ code = _ref2[0],
25
+ slug = _ref2[1],
26
+ count = _ref2[2];
27
+ return [code, {
28
+ locale: {
29
+ code
30
+ },
31
+ name: 'Contacts',
32
+ description: null,
33
+ slug,
34
+ public_stories_number: count
35
+ }];
36
+ }))
37
+ };
38
+ }
39
+ function sitemap(value) {
40
+ var locales = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['en', 'fr', 'ja_JP'];
41
+ return (0, _generate.generate)({
42
+ categories: [value],
43
+ locales,
44
+ newsroom: {
45
+ public_galleries_number: 0
46
+ },
47
+ stories: [],
48
+ generateUrl: (route, params) => route === 'category' && 'slug' in params ? "https://example.com/".concat(params.localeCode, "/category/").concat(params.slug) : undefined
49
+ }, {
50
+ baseUrl: 'https://example.com'
51
+ });
52
+ }
53
+ describe('category sitemap entries', () => {
54
+ it('omits empty translations from both URL entries and alternate links', /*#__PURE__*/_asyncToGenerator(function* () {
55
+ var result = yield sitemap(category(0));
56
+ expect(result).toEqual([{
57
+ url: 'https://example.com/en/category/contacts',
58
+ priority: 0.8,
59
+ changeFrequency: 'weekly',
60
+ alternate: [{
61
+ lang: 'fr',
62
+ url: 'https://example.com/fr/category/contacter'
63
+ }]
64
+ }, {
65
+ url: 'https://example.com/fr/category/contacter',
66
+ priority: 0.8,
67
+ changeFrequency: 'weekly',
68
+ alternate: [{
69
+ lang: 'en',
70
+ url: 'https://example.com/en/category/contacts'
71
+ }]
72
+ }]);
73
+ expect((0, _stringify.stringify)(result)).not.toContain('/ja_JP/category/');
74
+ }));
75
+ it('includes a translation once it has a public story', /*#__PURE__*/_asyncToGenerator(function* () {
76
+ var result = yield sitemap(category(1));
77
+ expect(result.map(_ref5 => {
78
+ var url = _ref5.url;
79
+ return url;
80
+ })).toContain('https://example.com/ja_JP/category/contacts-ja');
81
+ expect(result[0].alternate).toContainEqual({
82
+ lang: 'ja-JP',
83
+ url: 'https://example.com/ja_JP/category/contacts-ja'
84
+ });
85
+ }));
86
+ it('omits missing and disabled translations', /*#__PURE__*/_asyncToGenerator(function* () {
87
+ var result = yield sitemap(category(1), ['en', 'de']);
88
+ expect(result).toEqual([{
89
+ url: 'https://example.com/en/category/contacts',
90
+ priority: 0.8,
91
+ changeFrequency: 'weekly',
92
+ alternate: []
93
+ }]);
94
+ }));
95
+ it('omits a category when every enabled translation is empty', /*#__PURE__*/_asyncToGenerator(function* () {
96
+ expect(yield sitemap(category(0), ['ja_JP'])).toEqual([]);
97
+ }));
98
+ });
@@ -0,0 +1,96 @@
1
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
2
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
3
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ import { generate } from "./generate.mjs";
10
+ import { stringify } from "./stringify.mjs";
11
+ function category(japaneseStories) {
12
+ return {
13
+ id: 1,
14
+ display_name: 'Contacts',
15
+ display_description: null,
16
+ stories_number: 5 + japaneseStories,
17
+ public_stories_number: 5 + japaneseStories,
18
+ image: null,
19
+ is_featured: false,
20
+ i18n: Object.fromEntries([['en', 'contacts', 3], ['fr', 'contacter', 2], ['ja_JP', 'contacts-ja', japaneseStories]].map(_ref => {
21
+ var _ref2 = _slicedToArray(_ref, 3),
22
+ code = _ref2[0],
23
+ slug = _ref2[1],
24
+ count = _ref2[2];
25
+ return [code, {
26
+ locale: {
27
+ code
28
+ },
29
+ name: 'Contacts',
30
+ description: null,
31
+ slug,
32
+ public_stories_number: count
33
+ }];
34
+ }))
35
+ };
36
+ }
37
+ function sitemap(value) {
38
+ var locales = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['en', 'fr', 'ja_JP'];
39
+ return generate({
40
+ categories: [value],
41
+ locales,
42
+ newsroom: {
43
+ public_galleries_number: 0
44
+ },
45
+ stories: [],
46
+ generateUrl: (route, params) => route === 'category' && 'slug' in params ? "https://example.com/".concat(params.localeCode, "/category/").concat(params.slug) : undefined
47
+ }, {
48
+ baseUrl: 'https://example.com'
49
+ });
50
+ }
51
+ describe('category sitemap entries', () => {
52
+ it('omits empty translations from both URL entries and alternate links', /*#__PURE__*/_asyncToGenerator(function* () {
53
+ var result = yield sitemap(category(0));
54
+ expect(result).toEqual([{
55
+ url: 'https://example.com/en/category/contacts',
56
+ priority: 0.8,
57
+ changeFrequency: 'weekly',
58
+ alternate: [{
59
+ lang: 'fr',
60
+ url: 'https://example.com/fr/category/contacter'
61
+ }]
62
+ }, {
63
+ url: 'https://example.com/fr/category/contacter',
64
+ priority: 0.8,
65
+ changeFrequency: 'weekly',
66
+ alternate: [{
67
+ lang: 'en',
68
+ url: 'https://example.com/en/category/contacts'
69
+ }]
70
+ }]);
71
+ expect(stringify(result)).not.toContain('/ja_JP/category/');
72
+ }));
73
+ it('includes a translation once it has a public story', /*#__PURE__*/_asyncToGenerator(function* () {
74
+ var result = yield sitemap(category(1));
75
+ expect(result.map(_ref5 => {
76
+ var url = _ref5.url;
77
+ return url;
78
+ })).toContain('https://example.com/ja_JP/category/contacts-ja');
79
+ expect(result[0].alternate).toContainEqual({
80
+ lang: 'ja-JP',
81
+ url: 'https://example.com/ja_JP/category/contacts-ja'
82
+ });
83
+ }));
84
+ it('omits missing and disabled translations', /*#__PURE__*/_asyncToGenerator(function* () {
85
+ var result = yield sitemap(category(1), ['en', 'de']);
86
+ expect(result).toEqual([{
87
+ url: 'https://example.com/en/category/contacts',
88
+ priority: 0.8,
89
+ changeFrequency: 'weekly',
90
+ alternate: []
91
+ }]);
92
+ }));
93
+ it('omits a category when every enabled translation is empty', /*#__PURE__*/_asyncToGenerator(function* () {
94
+ expect(yield sitemap(category(0), ['ja_JP'])).toEqual([]);
95
+ }));
96
+ });
package/package.json CHANGED
@@ -1,73 +1,75 @@
1
1
  {
2
- "name": "@prezly/theme-kit-core",
3
- "version": "10.11.0",
4
- "description": "Data layer and utility library for developing Prezly themes with JavaScript",
5
- "main": "build/index.mjs",
6
- "type": "module",
7
- "types": "build/index.d.ts",
8
- "files": [
9
- "build",
10
- "README.md"
11
- ],
12
- "exports": {
13
- ".": {
14
- "types": "./build/index.d.ts",
15
- "require": "./build/index.cjs",
16
- "default": "./build/index.mjs"
17
- }
18
- },
19
- "peerDependencies": {
20
- "@prezly/sdk": "21.12.0 || ^23.x"
21
- },
22
- "dependencies": {
23
- "@prezly/uploadcare": "2.4.4",
24
- "@technically/is-not-undefined": "^1.0.0",
25
- "@technically/omit-undefined": "^1.0.4",
26
- "parse-data-url": "^6.0.0",
27
- "url-pattern": "^1.0.3",
28
- "@prezly/theme-kit-intl": "^10.9.1"
29
- },
30
- "devDependencies": {
31
- "@types/parse-data-url": "3.0.2"
32
- },
33
- "engines": {
34
- "node": ">= 16.x",
35
- "npm": ">= 8.x"
36
- },
37
- "keywords": [
38
- "prezly"
39
- ],
40
- "author": "Prezly Team",
41
- "license": "MIT",
42
- "bugs": {
43
- "url": "https://github.com/prezly/theme-kit-js/issues"
44
- },
45
- "homepage": "https://github.com/prezly/theme-kit-js/tree/main/packages/core#readme",
46
- "repository": {
47
- "type": "git",
48
- "url": "git+https://github.com/prezly/theme-kit-js.git",
49
- "directory": "packages/core"
50
- },
51
- "publishConfig": {
52
- "access": "public"
53
- },
54
- "scripts": {
55
- "prebuild": "rimraf --glob build/* *.tsbuildinfo",
56
- "build": "pnpm build:types && pnpm build:esm && pnpm build:cjs",
57
- "build:types": "tsc --project .",
58
- "build:esm": "babel --config-file=../../babel.esm.json src/ --extensions=.ts --out-dir=build/ --out-file-extension=.mjs",
59
- "build:cjs": "babel --config-file=../../babel.cjs.json src/ --extensions=.ts --out-dir=build/ --out-file-extension=.cjs",
60
- "dev": "tsc --watch --preserveWatchOutput --project .",
61
- "typecheck": "tsc --noEmit --emitDeclarationOnly false --incremental --project .",
62
- "lint": "biome lint src",
63
- "lint:fix": "biome lint --write src",
64
- "format": "biome format src",
65
- "format:fix": "biome format --write src",
66
- "test": "pnpm test:unit && pnpm test:build",
67
- "test:unit": "jest",
68
- "test:build": "pnpm test:build:cjs && pnpm test:build:esm && pnpm test:build:types",
69
- "test:build:types": "tsc --esModuleInterop --noEmit --target esnext --moduleResolution node build/index.d.ts",
70
- "test:build:esm": "node tests/test-build.mjs",
71
- "test:build:cjs": "node tests/test-build.cjs"
72
- }
73
- }
2
+ "name": "@prezly/theme-kit-core",
3
+ "version": "10.12.0",
4
+ "description": "Data layer and utility library for developing Prezly themes with JavaScript",
5
+ "main": "build/index.mjs",
6
+ "type": "module",
7
+ "types": "build/index.d.ts",
8
+ "files": [
9
+ "build",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./build/index.d.ts",
15
+ "require": "./build/index.cjs",
16
+ "default": "./build/index.mjs"
17
+ }
18
+ },
19
+ "scripts": {
20
+ "prepack": "pnpm test:build",
21
+ "prebuild": "rimraf --glob build/* *.tsbuildinfo",
22
+ "build": "pnpm build:types && pnpm build:esm && pnpm build:cjs",
23
+ "build:types": "tsc --project .",
24
+ "build:esm": "babel --config-file=../../babel.esm.json src/ --extensions=.ts --out-dir=build/ --out-file-extension=.mjs",
25
+ "build:cjs": "babel --config-file=../../babel.cjs.json src/ --extensions=.ts --out-dir=build/ --out-file-extension=.cjs",
26
+ "dev": "tsc --watch --preserveWatchOutput --project .",
27
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false --incremental --project .",
28
+ "lint": "biome lint src",
29
+ "lint:fix": "biome lint --write src",
30
+ "format": "biome format src",
31
+ "format:fix": "biome format --write src",
32
+ "test": "pnpm test:unit && pnpm test:build",
33
+ "test:unit": "jest",
34
+ "test:build": "pnpm test:build:cjs && pnpm test:build:esm && pnpm test:build:types",
35
+ "test:build:types": "tsc --esModuleInterop --noEmit --target esnext --moduleResolution node build/index.d.ts",
36
+ "test:build:esm": "node tests/test-build.mjs",
37
+ "test:build:cjs": "node tests/test-build.cjs"
38
+ },
39
+ "peerDependencies": {
40
+ "@prezly/sdk": "21.12.0 || ^23.x"
41
+ },
42
+ "dependencies": {
43
+ "@prezly/theme-kit-intl": "^10.12.0",
44
+ "@prezly/uploadcare": "2.4.4",
45
+ "@technically/is-not-undefined": "^1.0.0",
46
+ "@technically/omit-undefined": "^1.0.4",
47
+ "parse-data-url": "^6.0.0",
48
+ "url-pattern": "^1.0.3"
49
+ },
50
+ "devDependencies": {
51
+ "@types/parse-data-url": "3.0.2"
52
+ },
53
+ "engines": {
54
+ "node": ">= 16.x",
55
+ "npm": ">= 8.x"
56
+ },
57
+ "keywords": [
58
+ "prezly"
59
+ ],
60
+ "author": "Prezly Team",
61
+ "license": "MIT",
62
+ "bugs": {
63
+ "url": "https://github.com/prezly/theme-kit-js/issues"
64
+ },
65
+ "homepage": "https://github.com/prezly/theme-kit-js/tree/main/packages/core#readme",
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/prezly/theme-kit-js.git",
69
+ "directory": "packages/core"
70
+ },
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "gitHead": "aa8fe2c8311ddf0c5aa2329da15e086b12a81d96"
75
+ }