@prezly/theme-kit-core 10.11.0 → 10.13.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/build/content-delivery/sdk-compatibility.test.cjs +215 -0
- package/build/content-delivery/sdk-compatibility.test.mjs +213 -0
- package/build/sitemap/generate.cjs +3 -2
- package/build/sitemap/generate.mjs +3 -2
- package/build/sitemap/generate.test.cjs +98 -0
- package/build/sitemap/generate.test.mjs +96 -0
- package/package.json +74 -72
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _sdk = require("@prezly/sdk");
|
|
4
|
+
var _ContentDelivery = require("./ContentDelivery.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 setup(body) {
|
|
8
|
+
var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
|
|
9
|
+
var fetch = jest.fn(/*#__PURE__*/function () {
|
|
10
|
+
var _ref = _asyncToGenerator(function* (_url, _init) {
|
|
11
|
+
return new Response(JSON.stringify(body), {
|
|
12
|
+
status,
|
|
13
|
+
headers: {
|
|
14
|
+
'content-type': 'application/json'
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
return function (_x, _x2) {
|
|
19
|
+
return _ref.apply(this, arguments);
|
|
20
|
+
};
|
|
21
|
+
}());
|
|
22
|
+
var sdk = (0, _sdk.createPrezlyClient)({
|
|
23
|
+
accessToken: 'test-token',
|
|
24
|
+
fetch
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
client: (0, _ContentDelivery.createClient)(sdk, 'test-newsroom', undefined),
|
|
28
|
+
request: () => new URL(String(fetch.mock.calls[0][0])),
|
|
29
|
+
init: () => fetch.mock.calls[0][1]
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
describe('ContentDelivery with the installed SDK', () => {
|
|
33
|
+
it('unwraps newsroom, theme, language, category and gallery responses', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
34
|
+
var newsroom = {
|
|
35
|
+
uuid: 'test-newsroom'
|
|
36
|
+
};
|
|
37
|
+
var theme = {
|
|
38
|
+
id: 'test-theme',
|
|
39
|
+
settings: {
|
|
40
|
+
title: 'Theme'
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
var language = {
|
|
44
|
+
code: 'en',
|
|
45
|
+
is_default: true
|
|
46
|
+
};
|
|
47
|
+
var category = {
|
|
48
|
+
id: 7
|
|
49
|
+
};
|
|
50
|
+
var gallery = {
|
|
51
|
+
uuid: 'test-gallery'
|
|
52
|
+
};
|
|
53
|
+
var fetch = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
|
|
54
|
+
return new Response(JSON.stringify({
|
|
55
|
+
newsroom,
|
|
56
|
+
theme,
|
|
57
|
+
languages: [language],
|
|
58
|
+
categories: [category],
|
|
59
|
+
galleries: [gallery],
|
|
60
|
+
gallery
|
|
61
|
+
}), {
|
|
62
|
+
headers: {
|
|
63
|
+
'content-type': 'application/json'
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}));
|
|
67
|
+
var sdk = (0, _sdk.createPrezlyClient)({
|
|
68
|
+
accessToken: 'test-token',
|
|
69
|
+
fetch
|
|
70
|
+
});
|
|
71
|
+
var client = (0, _ContentDelivery.createClient)(sdk, 'test-newsroom', 'test-theme');
|
|
72
|
+
yield expect(client.newsroom()).resolves.toEqual(newsroom);
|
|
73
|
+
yield expect(client.themeSettings()).resolves.toEqual(theme.settings);
|
|
74
|
+
yield expect(client.languages()).resolves.toEqual([language]);
|
|
75
|
+
yield expect(client.categories()).resolves.toEqual([category]);
|
|
76
|
+
yield expect(client.galleries()).resolves.toMatchObject({
|
|
77
|
+
galleries: [gallery]
|
|
78
|
+
});
|
|
79
|
+
yield expect(client.gallery(gallery.uuid)).resolves.toEqual(gallery);
|
|
80
|
+
}));
|
|
81
|
+
it('preserves featured contact social profiles and filters by is_featured', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
82
|
+
var contact = {
|
|
83
|
+
uuid: '824b29da-97a1-44f2-ab45-f708ab268afc',
|
|
84
|
+
facebook: 'https://facebook.com/prezly',
|
|
85
|
+
twitter: 'https://twitter.com/prezly',
|
|
86
|
+
linkedin: 'https://linkedin.com/in/test-contact',
|
|
87
|
+
instagram: 'https://instagram.com/prezly'
|
|
88
|
+
};
|
|
89
|
+
var _setup = setup({
|
|
90
|
+
contacts: [contact]
|
|
91
|
+
}),
|
|
92
|
+
client = _setup.client,
|
|
93
|
+
request = _setup.request;
|
|
94
|
+
yield expect(client.featuredContacts()).resolves.toEqual([contact]);
|
|
95
|
+
expect(request().pathname).toBe('/v2/newsrooms/test-newsroom/contacts');
|
|
96
|
+
expect(JSON.parse(request().searchParams.get('query'))).toEqual({
|
|
97
|
+
is_featured: true
|
|
98
|
+
});
|
|
99
|
+
}));
|
|
100
|
+
it('serializes story filters, pagination, sort order, formats and extra fields', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
101
|
+
var result = {
|
|
102
|
+
stories: [],
|
|
103
|
+
pagination: {
|
|
104
|
+
total: 0
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var _setup2 = setup(result),
|
|
108
|
+
client = _setup2.client,
|
|
109
|
+
request = _setup2.request,
|
|
110
|
+
init = _setup2.init;
|
|
111
|
+
yield expect(client.stories({
|
|
112
|
+
limit: 10,
|
|
113
|
+
offset: 10,
|
|
114
|
+
highlighted: 2,
|
|
115
|
+
locale: 'en',
|
|
116
|
+
categories: [{
|
|
117
|
+
id: 7
|
|
118
|
+
}]
|
|
119
|
+
}, {
|
|
120
|
+
include: ['content']
|
|
121
|
+
})).resolves.toEqual(result);
|
|
122
|
+
expect(request().pathname).toBe('/v2/stories/search');
|
|
123
|
+
expect(init().method).toBe('POST');
|
|
124
|
+
var payload = JSON.parse(String(init().body));
|
|
125
|
+
expect(payload).toMatchObject({
|
|
126
|
+
limit: 10,
|
|
127
|
+
offset: 12,
|
|
128
|
+
sort: '-is_pinned,-published_at',
|
|
129
|
+
include: 'content'
|
|
130
|
+
});
|
|
131
|
+
expect(new Headers(init().headers).get('accept')).toContain('content-format=v4');
|
|
132
|
+
expect(payload.query).toEqual({
|
|
133
|
+
'category.id': {
|
|
134
|
+
$all: [7]
|
|
135
|
+
},
|
|
136
|
+
'newsroom.uuid': {
|
|
137
|
+
$in: ['test-newsroom']
|
|
138
|
+
},
|
|
139
|
+
locale: {
|
|
140
|
+
$in: ['en']
|
|
141
|
+
},
|
|
142
|
+
status: {
|
|
143
|
+
$in: [_sdk.Story.Status.PUBLISHED]
|
|
144
|
+
},
|
|
145
|
+
visibility: {
|
|
146
|
+
$in: [_sdk.Story.Visibility.PUBLIC]
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}));
|
|
150
|
+
it.each([{
|
|
151
|
+
uuid: 'test-story'
|
|
152
|
+
}, {
|
|
153
|
+
slug: 'test-story'
|
|
154
|
+
}])('retrieves story content and extended fields using %j', /*#__PURE__*/function () {
|
|
155
|
+
var _ref6 = _asyncToGenerator(function* (lookup) {
|
|
156
|
+
var story = {
|
|
157
|
+
uuid: 'test-story',
|
|
158
|
+
content: 'story content',
|
|
159
|
+
subtitle: 'Subtitle'
|
|
160
|
+
};
|
|
161
|
+
var _setup3 = setup({
|
|
162
|
+
story
|
|
163
|
+
}),
|
|
164
|
+
client = _setup3.client,
|
|
165
|
+
request = _setup3.request;
|
|
166
|
+
yield expect(client.story(lookup, {
|
|
167
|
+
include: ['content']
|
|
168
|
+
})).resolves.toEqual(story);
|
|
169
|
+
expect(request().searchParams.getAll('include[]')).toEqual(expect.arrayContaining(['content', 'header_image']));
|
|
170
|
+
});
|
|
171
|
+
return function (_x3) {
|
|
172
|
+
return _ref6.apply(this, arguments);
|
|
173
|
+
};
|
|
174
|
+
}());
|
|
175
|
+
it.each([403, 404, 410])('maps SDK HTTP %s errors to missing content', /*#__PURE__*/function () {
|
|
176
|
+
var _ref7 = _asyncToGenerator(function* (status) {
|
|
177
|
+
var _setup4 = setup({
|
|
178
|
+
message: 'Unavailable'
|
|
179
|
+
}, status),
|
|
180
|
+
client = _setup4.client;
|
|
181
|
+
yield expect(client.story({
|
|
182
|
+
uuid: 'test-story'
|
|
183
|
+
})).resolves.toBeNull();
|
|
184
|
+
yield expect(client.story({
|
|
185
|
+
slug: 'test-story'
|
|
186
|
+
})).resolves.toBeNull();
|
|
187
|
+
yield expect(client.gallery('test-gallery')).resolves.toBeNull();
|
|
188
|
+
});
|
|
189
|
+
return function (_x4) {
|
|
190
|
+
return _ref7.apply(this, arguments);
|
|
191
|
+
};
|
|
192
|
+
}());
|
|
193
|
+
it.each([401, 429, 500])('propagates SDK HTTP %s errors', /*#__PURE__*/function () {
|
|
194
|
+
var _ref8 = _asyncToGenerator(function* (status) {
|
|
195
|
+
var _setup5 = setup({
|
|
196
|
+
message: 'Failure'
|
|
197
|
+
}, status),
|
|
198
|
+
client = _setup5.client;
|
|
199
|
+
yield expect(client.story({
|
|
200
|
+
uuid: 'test-story'
|
|
201
|
+
})).rejects.toBeInstanceOf(_sdk.ApiError);
|
|
202
|
+
yield expect(client.story({
|
|
203
|
+
slug: 'test-story'
|
|
204
|
+
})).rejects.toMatchObject({
|
|
205
|
+
status
|
|
206
|
+
});
|
|
207
|
+
yield expect(client.gallery('test-gallery')).rejects.toMatchObject({
|
|
208
|
+
status
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return function (_x5) {
|
|
212
|
+
return _ref8.apply(this, arguments);
|
|
213
|
+
};
|
|
214
|
+
}());
|
|
215
|
+
});
|
|
@@ -0,0 +1,213 @@
|
|
|
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
|
+
import { ApiError, createPrezlyClient, Story } from '@prezly/sdk';
|
|
4
|
+
import { createClient } from "./ContentDelivery.mjs";
|
|
5
|
+
function setup(body) {
|
|
6
|
+
var status = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 200;
|
|
7
|
+
var fetch = jest.fn(/*#__PURE__*/function () {
|
|
8
|
+
var _ref = _asyncToGenerator(function* (_url, _init) {
|
|
9
|
+
return new Response(JSON.stringify(body), {
|
|
10
|
+
status,
|
|
11
|
+
headers: {
|
|
12
|
+
'content-type': 'application/json'
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return function (_x, _x2) {
|
|
17
|
+
return _ref.apply(this, arguments);
|
|
18
|
+
};
|
|
19
|
+
}());
|
|
20
|
+
var sdk = createPrezlyClient({
|
|
21
|
+
accessToken: 'test-token',
|
|
22
|
+
fetch
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
client: createClient(sdk, 'test-newsroom', undefined),
|
|
26
|
+
request: () => new URL(String(fetch.mock.calls[0][0])),
|
|
27
|
+
init: () => fetch.mock.calls[0][1]
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
describe('ContentDelivery with the installed SDK', () => {
|
|
31
|
+
it('unwraps newsroom, theme, language, category and gallery responses', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
32
|
+
var newsroom = {
|
|
33
|
+
uuid: 'test-newsroom'
|
|
34
|
+
};
|
|
35
|
+
var theme = {
|
|
36
|
+
id: 'test-theme',
|
|
37
|
+
settings: {
|
|
38
|
+
title: 'Theme'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var language = {
|
|
42
|
+
code: 'en',
|
|
43
|
+
is_default: true
|
|
44
|
+
};
|
|
45
|
+
var category = {
|
|
46
|
+
id: 7
|
|
47
|
+
};
|
|
48
|
+
var gallery = {
|
|
49
|
+
uuid: 'test-gallery'
|
|
50
|
+
};
|
|
51
|
+
var fetch = jest.fn(/*#__PURE__*/_asyncToGenerator(function* () {
|
|
52
|
+
return new Response(JSON.stringify({
|
|
53
|
+
newsroom,
|
|
54
|
+
theme,
|
|
55
|
+
languages: [language],
|
|
56
|
+
categories: [category],
|
|
57
|
+
galleries: [gallery],
|
|
58
|
+
gallery
|
|
59
|
+
}), {
|
|
60
|
+
headers: {
|
|
61
|
+
'content-type': 'application/json'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
var sdk = createPrezlyClient({
|
|
66
|
+
accessToken: 'test-token',
|
|
67
|
+
fetch
|
|
68
|
+
});
|
|
69
|
+
var client = createClient(sdk, 'test-newsroom', 'test-theme');
|
|
70
|
+
yield expect(client.newsroom()).resolves.toEqual(newsroom);
|
|
71
|
+
yield expect(client.themeSettings()).resolves.toEqual(theme.settings);
|
|
72
|
+
yield expect(client.languages()).resolves.toEqual([language]);
|
|
73
|
+
yield expect(client.categories()).resolves.toEqual([category]);
|
|
74
|
+
yield expect(client.galleries()).resolves.toMatchObject({
|
|
75
|
+
galleries: [gallery]
|
|
76
|
+
});
|
|
77
|
+
yield expect(client.gallery(gallery.uuid)).resolves.toEqual(gallery);
|
|
78
|
+
}));
|
|
79
|
+
it('preserves featured contact social profiles and filters by is_featured', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
80
|
+
var contact = {
|
|
81
|
+
uuid: '824b29da-97a1-44f2-ab45-f708ab268afc',
|
|
82
|
+
facebook: 'https://facebook.com/prezly',
|
|
83
|
+
twitter: 'https://twitter.com/prezly',
|
|
84
|
+
linkedin: 'https://linkedin.com/in/test-contact',
|
|
85
|
+
instagram: 'https://instagram.com/prezly'
|
|
86
|
+
};
|
|
87
|
+
var _setup = setup({
|
|
88
|
+
contacts: [contact]
|
|
89
|
+
}),
|
|
90
|
+
client = _setup.client,
|
|
91
|
+
request = _setup.request;
|
|
92
|
+
yield expect(client.featuredContacts()).resolves.toEqual([contact]);
|
|
93
|
+
expect(request().pathname).toBe('/v2/newsrooms/test-newsroom/contacts');
|
|
94
|
+
expect(JSON.parse(request().searchParams.get('query'))).toEqual({
|
|
95
|
+
is_featured: true
|
|
96
|
+
});
|
|
97
|
+
}));
|
|
98
|
+
it('serializes story filters, pagination, sort order, formats and extra fields', /*#__PURE__*/_asyncToGenerator(function* () {
|
|
99
|
+
var result = {
|
|
100
|
+
stories: [],
|
|
101
|
+
pagination: {
|
|
102
|
+
total: 0
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
var _setup2 = setup(result),
|
|
106
|
+
client = _setup2.client,
|
|
107
|
+
request = _setup2.request,
|
|
108
|
+
init = _setup2.init;
|
|
109
|
+
yield expect(client.stories({
|
|
110
|
+
limit: 10,
|
|
111
|
+
offset: 10,
|
|
112
|
+
highlighted: 2,
|
|
113
|
+
locale: 'en',
|
|
114
|
+
categories: [{
|
|
115
|
+
id: 7
|
|
116
|
+
}]
|
|
117
|
+
}, {
|
|
118
|
+
include: ['content']
|
|
119
|
+
})).resolves.toEqual(result);
|
|
120
|
+
expect(request().pathname).toBe('/v2/stories/search');
|
|
121
|
+
expect(init().method).toBe('POST');
|
|
122
|
+
var payload = JSON.parse(String(init().body));
|
|
123
|
+
expect(payload).toMatchObject({
|
|
124
|
+
limit: 10,
|
|
125
|
+
offset: 12,
|
|
126
|
+
sort: '-is_pinned,-published_at',
|
|
127
|
+
include: 'content'
|
|
128
|
+
});
|
|
129
|
+
expect(new Headers(init().headers).get('accept')).toContain('content-format=v4');
|
|
130
|
+
expect(payload.query).toEqual({
|
|
131
|
+
'category.id': {
|
|
132
|
+
$all: [7]
|
|
133
|
+
},
|
|
134
|
+
'newsroom.uuid': {
|
|
135
|
+
$in: ['test-newsroom']
|
|
136
|
+
},
|
|
137
|
+
locale: {
|
|
138
|
+
$in: ['en']
|
|
139
|
+
},
|
|
140
|
+
status: {
|
|
141
|
+
$in: [Story.Status.PUBLISHED]
|
|
142
|
+
},
|
|
143
|
+
visibility: {
|
|
144
|
+
$in: [Story.Visibility.PUBLIC]
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
}));
|
|
148
|
+
it.each([{
|
|
149
|
+
uuid: 'test-story'
|
|
150
|
+
}, {
|
|
151
|
+
slug: 'test-story'
|
|
152
|
+
}])('retrieves story content and extended fields using %j', /*#__PURE__*/function () {
|
|
153
|
+
var _ref6 = _asyncToGenerator(function* (lookup) {
|
|
154
|
+
var story = {
|
|
155
|
+
uuid: 'test-story',
|
|
156
|
+
content: 'story content',
|
|
157
|
+
subtitle: 'Subtitle'
|
|
158
|
+
};
|
|
159
|
+
var _setup3 = setup({
|
|
160
|
+
story
|
|
161
|
+
}),
|
|
162
|
+
client = _setup3.client,
|
|
163
|
+
request = _setup3.request;
|
|
164
|
+
yield expect(client.story(lookup, {
|
|
165
|
+
include: ['content']
|
|
166
|
+
})).resolves.toEqual(story);
|
|
167
|
+
expect(request().searchParams.getAll('include[]')).toEqual(expect.arrayContaining(['content', 'header_image']));
|
|
168
|
+
});
|
|
169
|
+
return function (_x3) {
|
|
170
|
+
return _ref6.apply(this, arguments);
|
|
171
|
+
};
|
|
172
|
+
}());
|
|
173
|
+
it.each([403, 404, 410])('maps SDK HTTP %s errors to missing content', /*#__PURE__*/function () {
|
|
174
|
+
var _ref7 = _asyncToGenerator(function* (status) {
|
|
175
|
+
var _setup4 = setup({
|
|
176
|
+
message: 'Unavailable'
|
|
177
|
+
}, status),
|
|
178
|
+
client = _setup4.client;
|
|
179
|
+
yield expect(client.story({
|
|
180
|
+
uuid: 'test-story'
|
|
181
|
+
})).resolves.toBeNull();
|
|
182
|
+
yield expect(client.story({
|
|
183
|
+
slug: 'test-story'
|
|
184
|
+
})).resolves.toBeNull();
|
|
185
|
+
yield expect(client.gallery('test-gallery')).resolves.toBeNull();
|
|
186
|
+
});
|
|
187
|
+
return function (_x4) {
|
|
188
|
+
return _ref7.apply(this, arguments);
|
|
189
|
+
};
|
|
190
|
+
}());
|
|
191
|
+
it.each([401, 429, 500])('propagates SDK HTTP %s errors', /*#__PURE__*/function () {
|
|
192
|
+
var _ref8 = _asyncToGenerator(function* (status) {
|
|
193
|
+
var _setup5 = setup({
|
|
194
|
+
message: 'Failure'
|
|
195
|
+
}, status),
|
|
196
|
+
client = _setup5.client;
|
|
197
|
+
yield expect(client.story({
|
|
198
|
+
uuid: 'test-story'
|
|
199
|
+
})).rejects.toBeInstanceOf(ApiError);
|
|
200
|
+
yield expect(client.story({
|
|
201
|
+
slug: 'test-story'
|
|
202
|
+
})).rejects.toMatchObject({
|
|
203
|
+
status
|
|
204
|
+
});
|
|
205
|
+
yield expect(client.gallery('test-gallery')).rejects.toMatchObject({
|
|
206
|
+
status
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
return function (_x5) {
|
|
210
|
+
return _ref8.apply(this, arguments);
|
|
211
|
+
};
|
|
212
|
+
}());
|
|
213
|
+
});
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
}
|
|
2
|
+
"name": "@prezly/theme-kit-core",
|
|
3
|
+
"version": "10.13.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.0.1 || ^26.16.0"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@prezly/theme-kit-intl": "^10.13.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": "455f8c5db29b21db0791ee7f6e9fd60a08bd840e"
|
|
75
|
+
}
|