@prezly/theme-kit-nextjs 1.9.1 → 1.10.1

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.
Files changed (45) hide show
  1. package/build/adapter-nextjs/index.d.ts +1 -0
  2. package/build/adapter-nextjs/index.js +1 -0
  3. package/build/adapter-nextjs/index.js.map +1 -1
  4. package/build/adapter-nextjs/page-props/category.d.ts +14 -0
  5. package/build/adapter-nextjs/page-props/category.js +107 -0
  6. package/build/adapter-nextjs/page-props/category.js.map +1 -0
  7. package/build/adapter-nextjs/page-props/gallery.d.ts +13 -0
  8. package/build/adapter-nextjs/page-props/gallery.js +101 -0
  9. package/build/adapter-nextjs/page-props/gallery.js.map +1 -0
  10. package/build/adapter-nextjs/page-props/galleryAlbum.d.ts +7 -0
  11. package/build/adapter-nextjs/page-props/galleryAlbum.js +87 -0
  12. package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -0
  13. package/build/adapter-nextjs/page-props/home.d.ts +14 -0
  14. package/build/adapter-nextjs/page-props/home.js +101 -0
  15. package/build/adapter-nextjs/page-props/home.js.map +1 -0
  16. package/build/adapter-nextjs/page-props/index.d.ts +7 -0
  17. package/build/adapter-nextjs/page-props/index.js +18 -0
  18. package/build/adapter-nextjs/page-props/index.js.map +1 -0
  19. package/build/adapter-nextjs/page-props/lib/types.d.ts +3 -0
  20. package/build/adapter-nextjs/page-props/lib/types.js +3 -0
  21. package/build/adapter-nextjs/page-props/lib/types.js.map +1 -0
  22. package/build/adapter-nextjs/page-props/search.d.ts +3 -0
  23. package/build/adapter-nextjs/page-props/search.js +80 -0
  24. package/build/adapter-nextjs/page-props/search.js.map +1 -0
  25. package/build/adapter-nextjs/page-props/story.d.ts +3 -0
  26. package/build/adapter-nextjs/page-props/story.js +107 -0
  27. package/build/adapter-nextjs/page-props/story.js.map +1 -0
  28. package/build/adapter-nextjs/page-props/storyPreview.d.ts +3 -0
  29. package/build/adapter-nextjs/page-props/storyPreview.js +90 -0
  30. package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -0
  31. package/build/data-fetching/constants.d.ts +1 -0
  32. package/build/data-fetching/constants.js +2 -1
  33. package/build/data-fetching/constants.js.map +1 -1
  34. package/package.json +2 -5
  35. package/src/adapter-nextjs/index.ts +1 -0
  36. package/src/adapter-nextjs/page-props/category.ts +74 -0
  37. package/src/adapter-nextjs/page-props/gallery.ts +64 -0
  38. package/src/adapter-nextjs/page-props/galleryAlbum.ts +40 -0
  39. package/src/adapter-nextjs/page-props/home.ts +64 -0
  40. package/src/adapter-nextjs/page-props/index.ts +7 -0
  41. package/src/adapter-nextjs/page-props/lib/types.ts +8 -0
  42. package/src/adapter-nextjs/page-props/search.ts +27 -0
  43. package/src/adapter-nextjs/page-props/story.ts +47 -0
  44. package/src/adapter-nextjs/page-props/storyPreview.ts +35 -0
  45. package/src/data-fetching/constants.ts +1 -0
@@ -0,0 +1,3 @@
1
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
2
+ import type { PropsFunction } from './lib/types';
3
+ export declare function getStoryPageServerSideProps<CustomProps extends Record<string, any>>(customProps: CustomProps | PropsFunction<CustomProps>): (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<CustomProps>>;
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.getStoryPageServerSideProps = void 0;
51
+ var data_fetching_1 = require("../../data-fetching");
52
+ var intl_1 = require("../../intl");
53
+ var getNewsroomServerSideProps_1 = require("../getNewsroomServerSideProps");
54
+ var processRequest_1 = require("../processRequest");
55
+ function getStoryPageServerSideProps(customProps) {
56
+ return function getServerSideProps(context) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var api, slug, story, _a, serverSideProps, locale, _b, _c, _d, _e;
59
+ return __generator(this, function (_f) {
60
+ switch (_f.label) {
61
+ case 0:
62
+ api = (0, data_fetching_1.getPrezlyApi)(context.req);
63
+ slug = context.params.slug;
64
+ if (!slug) return [3 /*break*/, 2];
65
+ return [4 /*yield*/, api.getStoryBySlug(slug)];
66
+ case 1:
67
+ _a = _f.sent();
68
+ return [3 /*break*/, 3];
69
+ case 2:
70
+ _a = null;
71
+ _f.label = 3;
72
+ case 3:
73
+ story = _a;
74
+ if (!story) {
75
+ return [2 /*return*/, { notFound: true }];
76
+ }
77
+ return [4 /*yield*/, (0, getNewsroomServerSideProps_1.getNewsroomServerSideProps)(context, { story: story })];
78
+ case 4:
79
+ serverSideProps = (_f.sent()).serverSideProps;
80
+ locale = context.locale;
81
+ if (locale && locale !== intl_1.DUMMY_DEFAULT_LOCALE) {
82
+ return [2 /*return*/, {
83
+ redirect: {
84
+ destination: "/".concat(slug),
85
+ permanent: true,
86
+ },
87
+ }];
88
+ }
89
+ _b = processRequest_1.processRequest;
90
+ _c = [context];
91
+ _d = [__assign(__assign({}, serverSideProps), { newsroomContextProps: __assign(__assign({}, serverSideProps.newsroomContextProps), { currentStory: story }) })];
92
+ if (!(typeof customProps === 'function')) return [3 /*break*/, 6];
93
+ return [4 /*yield*/, customProps(context, serverSideProps)];
94
+ case 5:
95
+ _e = _f.sent();
96
+ return [3 /*break*/, 7];
97
+ case 6:
98
+ _e = customProps;
99
+ _f.label = 7;
100
+ case 7: return [2 /*return*/, _b.apply(void 0, _c.concat([__assign.apply(void 0, _d.concat([(_e)]))]))];
101
+ }
102
+ });
103
+ });
104
+ };
105
+ }
106
+ exports.getStoryPageServerSideProps = getStoryPageServerSideProps;
107
+ //# sourceMappingURL=story.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"story.js","sourceRoot":"","sources":["../../../src/adapter-nextjs/page-props/story.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qDAAmD;AACnD,mCAAkD;AAClD,4EAA2E;AAC3E,oDAAmD;AAInD,SAAgB,2BAA2B,CACvC,WAAqD;IAErD,OAAO,SAAe,kBAAkB,CACpC,OAAkC;;;;;;wBAE5B,GAAG,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBAE9B,IAAI,GAAK,OAAO,CAAC,MAA2B,KAAxC,CAAyC;6BACvC,IAAI,EAAJ,wBAAI;wBAAG,qBAAM,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,EAAA;;wBAA9B,KAAA,SAA8B,CAAA;;;wBAAG,KAAA,IAAI,CAAA;;;wBAApD,KAAK,KAA+C;wBAC1D,IAAI,CAAC,KAAK,EAAE;4BACR,sBAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAC;yBAC7B;wBAE2B,qBAAM,IAAA,uDAA0B,EAAC,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,EAAA;;wBAAxE,eAAe,GAAK,CAAA,SAAoD,CAAA,gBAAzD;wBAEf,MAAM,GAAK,OAAO,OAAZ,CAAa;wBAC3B,IAAI,MAAM,IAAI,MAAM,KAAK,2BAAoB,EAAE;4BAC3C,sBAAO;oCACH,QAAQ,EAAE;wCACN,WAAW,EAAE,WAAI,IAAI,CAAE;wCACvB,SAAS,EAAE,IAAI;qCAClB;iCACJ,EAAC;yBACL;wBAEM,KAAA,+BAAc,CAAA;8BAAC,OAAO;oDACtB,eAAe,KAClB,oBAAoB,wBACb,eAAe,CAAC,oBAAoB,KACvC,YAAY,EAAE,KAAK;6BAEnB,CAAA,OAAO,WAAW,KAAK,UAAU,CAAA,EAAjC,wBAAiC;wBAC/B,qBAAO,WAA0C,CAAC,OAAO,EAAE,eAAe,CAAC,EAAA;;wBAA3E,KAAA,SAA2E,CAAA;;;wBAC3E,KAAA,WAAW,CAAA;;4BARrB,sBAAO,8DAMA,IAEe,MACpB,EAAC;;;;KACN,CAAC;AACN,CAAC;AArCD,kEAqCC"}
@@ -0,0 +1,3 @@
1
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
2
+ import type { PropsFunction } from './lib/types';
3
+ export declare function getStoryPreviewPageServerSideProps<CustomProps extends Record<string, any>>(customProps: CustomProps | PropsFunction<CustomProps>): (context: GetServerSidePropsContext) => Promise<GetServerSidePropsResult<CustomProps>>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (_) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.getStoryPreviewPageServerSideProps = void 0;
51
+ var data_fetching_1 = require("../../data-fetching");
52
+ var getNewsroomServerSideProps_1 = require("../getNewsroomServerSideProps");
53
+ var processRequest_1 = require("../processRequest");
54
+ function getStoryPreviewPageServerSideProps(customProps) {
55
+ return function getServerSideProps(context) {
56
+ return __awaiter(this, void 0, void 0, function () {
57
+ var api, uuid, story, serverSideProps, _a, _b, _c, _d;
58
+ return __generator(this, function (_e) {
59
+ switch (_e.label) {
60
+ case 0:
61
+ api = (0, data_fetching_1.getPrezlyApi)(context.req);
62
+ uuid = context.params.uuid;
63
+ return [4 /*yield*/, api.getStory(uuid)];
64
+ case 1:
65
+ story = _e.sent();
66
+ if (!story) {
67
+ return [2 /*return*/, { notFound: true }];
68
+ }
69
+ return [4 /*yield*/, (0, getNewsroomServerSideProps_1.getNewsroomServerSideProps)(context, { story: story })];
70
+ case 2:
71
+ serverSideProps = (_e.sent()).serverSideProps;
72
+ _a = processRequest_1.processRequest;
73
+ _b = [context];
74
+ _c = [__assign(__assign({}, serverSideProps), { newsroomContextProps: __assign(__assign({}, serverSideProps.newsroomContextProps), { currentStory: story }) })];
75
+ if (!(typeof customProps === 'function')) return [3 /*break*/, 4];
76
+ return [4 /*yield*/, customProps(context, serverSideProps)];
77
+ case 3:
78
+ _d = _e.sent();
79
+ return [3 /*break*/, 5];
80
+ case 4:
81
+ _d = customProps;
82
+ _e.label = 5;
83
+ case 5: return [2 /*return*/, _a.apply(void 0, _b.concat([__assign.apply(void 0, _c.concat([(_d)]))]))];
84
+ }
85
+ });
86
+ });
87
+ };
88
+ }
89
+ exports.getStoryPreviewPageServerSideProps = getStoryPreviewPageServerSideProps;
90
+ //# sourceMappingURL=storyPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storyPreview.js","sourceRoot":"","sources":["../../../src/adapter-nextjs/page-props/storyPreview.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,qDAAmD;AACnD,4EAA2E;AAC3E,oDAAmD;AAInD,SAAgB,kCAAkC,CAC9C,WAAqD;IAErD,OAAO,SAAe,kBAAkB,CACpC,OAAkC;;;;;;wBAE5B,GAAG,GAAG,IAAA,4BAAY,EAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBAC9B,IAAI,GAAK,OAAO,CAAC,MAA0B,KAAvC,CAAwC;wBACtC,qBAAM,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAA;;wBAAhC,KAAK,GAAG,SAAwB;wBACtC,IAAI,CAAC,KAAK,EAAE;4BACR,sBAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAC;yBAC7B;wBAE2B,qBAAM,IAAA,uDAA0B,EAAC,OAAO,EAAE,EAAE,KAAK,OAAA,EAAE,CAAC,EAAA;;wBAAxE,eAAe,GAAK,CAAA,SAAoD,CAAA,gBAAzD;wBAEhB,KAAA,+BAAc,CAAA;8BAAC,OAAO;oDACtB,eAAe,KAClB,oBAAoB,wBACb,eAAe,CAAC,oBAAoB,KACvC,YAAY,EAAE,KAAK;6BAEnB,CAAA,OAAO,WAAW,KAAK,UAAU,CAAA,EAAjC,wBAAiC;wBAC/B,qBAAO,WAA0C,CAAC,OAAO,EAAE,eAAe,CAAC,EAAA;;wBAA3E,KAAA,SAA2E,CAAA;;;wBAC3E,KAAA,WAAW,CAAA;;4BARrB,sBAAO,8DAMA,IAEe,MACpB,EAAC;;;;KACN,CAAC;AACN,CAAC;AA1BD,gFA0BC"}
@@ -1,2 +1,3 @@
1
1
  export declare const ASSETS_URL = "https://cdn.uc.assets.prezly.com";
2
2
  export declare const DEFAULT_PAGE_SIZE = 12;
3
+ export declare const DEFAULT_GALLERY_PAGE_SIZE = 6;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_PAGE_SIZE = exports.ASSETS_URL = void 0;
3
+ exports.DEFAULT_GALLERY_PAGE_SIZE = exports.DEFAULT_PAGE_SIZE = exports.ASSETS_URL = void 0;
4
4
  exports.ASSETS_URL = 'https://cdn.uc.assets.prezly.com';
5
5
  exports.DEFAULT_PAGE_SIZE = 12;
6
+ exports.DEFAULT_GALLERY_PAGE_SIZE = 6;
6
7
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/data-fetching/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,kCAAkC,CAAC;AAChD,QAAA,iBAAiB,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/data-fetching/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,kCAAkC,CAAC;AAChD,QAAA,iBAAiB,GAAG,EAAE,CAAC;AACvB,QAAA,yBAAyB,GAAG,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-nextjs",
3
- "version": "1.9.1",
3
+ "version": "1.10.1",
4
4
  "description": "Data layer and utility library for developing Prezly themes with NextJS",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  "react-dom": "^17.x"
49
49
  },
50
50
  "dependencies": {
51
- "@prezly/sdk": "^6.21.0",
51
+ "@prezly/sdk": "^6.23.0",
52
52
  "@react-hookz/web": "^13.2.1",
53
53
  "next-seo": "^5.4.0",
54
54
  "parse-data-url": "^4.0.1",
@@ -61,11 +61,8 @@
61
61
  "@types/react": "^17.0.38",
62
62
  "@types/react-dom": "^17.0.11",
63
63
  "eslint": "^8.8.0",
64
- "next": "^12.x",
65
64
  "np": "^7.6.0",
66
65
  "prettier": "^2.5.1",
67
- "react": "^17.x",
68
- "react-dom": "^17.x",
69
66
  "rimraf": "^3.0.2",
70
67
  "typescript": "^4.5.5"
71
68
  },
@@ -1,2 +1,3 @@
1
1
  export * from './getNewsroomServerSideProps';
2
+ export * from './page-props';
2
3
  export * from './processRequest';
@@ -0,0 +1,74 @@
1
+ import type { ExtraStoryFields, Story } from '@prezly/sdk';
2
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
3
+
4
+ import { DEFAULT_PAGE_SIZE } from '../../data-fetching';
5
+ import type { PaginationProps } from '../../infinite-loading/types';
6
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
7
+ import { processRequest } from '../processRequest';
8
+
9
+ import type { PropsFunction } from './lib/types';
10
+
11
+ export interface CategoryPageProps<StoryType extends Story = Story> {
12
+ stories: StoryType[];
13
+ pagination: PaginationProps;
14
+ }
15
+
16
+ interface Options {
17
+ extraStoryFields?: (keyof ExtraStoryFields)[];
18
+ pageSize?: number;
19
+ }
20
+
21
+ export function getCategoryPageServerSideProps<
22
+ CustomProps extends Record<string, any>,
23
+ StoryType extends Story = Story,
24
+ >(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
25
+ const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
26
+
27
+ return async function getServerSideProps(
28
+ context: GetServerSidePropsContext,
29
+ ): Promise<GetServerSidePropsResult<CategoryPageProps<StoryType> & CustomProps>> {
30
+ const { api, serverSideProps } = await getNewsroomServerSideProps(context);
31
+
32
+ const { slug } = context.params as { slug: string };
33
+ const category = await api.getCategoryBySlug(slug);
34
+
35
+ if (!category) {
36
+ return {
37
+ notFound: true,
38
+ };
39
+ }
40
+
41
+ const { query } = context;
42
+ const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
43
+
44
+ const { localeCode } = serverSideProps.newsroomContextProps;
45
+
46
+ const { stories, storiesTotal } = await api.getStoriesFromCategory(category, {
47
+ page,
48
+ include: extraStoryFields,
49
+ localeCode,
50
+ });
51
+
52
+ return processRequest(
53
+ context,
54
+ {
55
+ ...serverSideProps,
56
+ newsroomContextProps: {
57
+ ...serverSideProps.newsroomContextProps,
58
+ currentCategory: category,
59
+ },
60
+ // TODO: This is temporary until return types from API are figured out
61
+ stories: stories as StoryType[],
62
+ pagination: {
63
+ itemsTotal: storiesTotal,
64
+ currentPage: page ?? 1,
65
+ pageSize,
66
+ },
67
+ ...(typeof customProps === 'function'
68
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
69
+ : customProps),
70
+ },
71
+ `/category/${slug}`,
72
+ );
73
+ };
74
+ }
@@ -0,0 +1,64 @@
1
+ import type { NewsroomGallery } from '@prezly/sdk';
2
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
3
+
4
+ import { DEFAULT_GALLERY_PAGE_SIZE } from '../../data-fetching';
5
+ import type { PaginationProps } from '../../infinite-loading/types';
6
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
7
+ import { processRequest } from '../processRequest';
8
+
9
+ import type { PropsFunction } from './lib/types';
10
+
11
+ export interface GalleryPageProps {
12
+ galleries: NewsroomGallery[];
13
+ pagination: PaginationProps;
14
+ }
15
+
16
+ interface Options {
17
+ pageSize?: number;
18
+ }
19
+
20
+ export function getGalleryPageServerSideProps<CustomProps extends Record<string, any>>(
21
+ customProps: CustomProps | PropsFunction<CustomProps>,
22
+ options?: Options,
23
+ ) {
24
+ const { pageSize = DEFAULT_GALLERY_PAGE_SIZE } = options || {};
25
+
26
+ return async function getServerSideProps(
27
+ context: GetServerSidePropsContext,
28
+ ): Promise<GetServerSidePropsResult<GalleryPageProps & CustomProps>> {
29
+ const { api, serverSideProps } = await getNewsroomServerSideProps(context);
30
+ const { query } = context;
31
+
32
+ const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
33
+ const { galleries, pagination } = await api.getGalleries({ page, pageSize });
34
+
35
+ // If there's only one gallery, redirect to it immediately
36
+ if (galleries.length === 1) {
37
+ const { uuid } = galleries[0];
38
+
39
+ return {
40
+ redirect: {
41
+ destination: `/media/album/${uuid}`,
42
+ permanent: false,
43
+ },
44
+ };
45
+ }
46
+
47
+ return processRequest(
48
+ context,
49
+ {
50
+ ...serverSideProps,
51
+ galleries,
52
+ pagination: {
53
+ itemsTotal: pagination.matched_records_number,
54
+ currentPage: page ?? 1,
55
+ pageSize,
56
+ },
57
+ ...(typeof customProps === 'function'
58
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
59
+ : customProps),
60
+ },
61
+ '/media',
62
+ );
63
+ };
64
+ }
@@ -0,0 +1,40 @@
1
+ import type { NewsroomGallery } from '@prezly/sdk';
2
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
3
+
4
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
5
+ import { processRequest } from '../processRequest';
6
+
7
+ import type { PropsFunction } from './lib/types';
8
+
9
+ export interface GalleryAlbumPageProps {
10
+ gallery: NewsroomGallery;
11
+ }
12
+
13
+ export function getGalleryAlbumPageServerSideProps<CustomProps extends Record<string, any>>(
14
+ customProps: CustomProps | PropsFunction<CustomProps>,
15
+ ) {
16
+ return async function getServerSideProps(
17
+ context: GetServerSidePropsContext,
18
+ ): Promise<GetServerSidePropsResult<GalleryAlbumPageProps & CustomProps>> {
19
+ const { api, serverSideProps } = await getNewsroomServerSideProps(context);
20
+
21
+ const { uuid } = context.params as { uuid: string };
22
+ const gallery = await api.getGallery(uuid);
23
+
24
+ if (!gallery || !gallery.images_number) {
25
+ return { notFound: true };
26
+ }
27
+
28
+ return processRequest(
29
+ context,
30
+ {
31
+ ...serverSideProps,
32
+ gallery,
33
+ ...(typeof customProps === 'function'
34
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
35
+ : customProps),
36
+ },
37
+ `/media/album/${uuid}`,
38
+ );
39
+ };
40
+ }
@@ -0,0 +1,64 @@
1
+ import type { ExtraStoryFields, Story } from '@prezly/sdk';
2
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
3
+
4
+ import { DEFAULT_PAGE_SIZE } from '../../data-fetching';
5
+ import type { PaginationProps } from '../../infinite-loading/types';
6
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
7
+ import { processRequest } from '../processRequest';
8
+
9
+ import type { PropsFunction } from './lib/types';
10
+
11
+ export interface HomePageProps<StoryType extends Story = Story> {
12
+ stories: StoryType[];
13
+ pagination: PaginationProps;
14
+ }
15
+
16
+ interface Options {
17
+ extraStoryFields?: (keyof ExtraStoryFields)[];
18
+ pageSize?: number;
19
+ }
20
+
21
+ export function getHomepageServerSideProps<
22
+ CustomProps extends Record<string, any>,
23
+ StoryType extends Story = Story,
24
+ >(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
25
+ const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
26
+
27
+ return async function getServerSideProps(
28
+ context: GetServerSidePropsContext,
29
+ ): Promise<GetServerSidePropsResult<HomePageProps<StoryType> & CustomProps>> {
30
+ const { api, serverSideProps } = await getNewsroomServerSideProps(context, {
31
+ loadHomepageContacts: true,
32
+ });
33
+
34
+ const { query } = context;
35
+ const page = query.page && typeof query.page === 'string' ? Number(query.page) : undefined;
36
+
37
+ const { localeCode } = serverSideProps.newsroomContextProps;
38
+
39
+ const storiesPaginated = await api.getStories({
40
+ page,
41
+ include: extraStoryFields,
42
+ localeCode,
43
+ });
44
+ const { stories, storiesTotal } = storiesPaginated;
45
+
46
+ return processRequest(
47
+ context,
48
+ {
49
+ ...serverSideProps,
50
+ // TODO: This is temporary until return types from API are figured out
51
+ stories: stories as StoryType[],
52
+ pagination: {
53
+ itemsTotal: storiesTotal,
54
+ currentPage: page ?? 1,
55
+ pageSize,
56
+ },
57
+ ...(typeof customProps === 'function'
58
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
59
+ : customProps),
60
+ },
61
+ '/',
62
+ );
63
+ };
64
+ }
@@ -0,0 +1,7 @@
1
+ export { getCategoryPageServerSideProps, type CategoryPageProps } from './category';
2
+ export { getGalleryPageServerSideProps, type GalleryPageProps } from './gallery';
3
+ export { getGalleryAlbumPageServerSideProps, type GalleryAlbumPageProps } from './galleryAlbum';
4
+ export { getHomepageServerSideProps, type HomePageProps } from './home';
5
+ export { getSearchPageServerSideProps } from './search';
6
+ export { getStoryPageServerSideProps } from './story';
7
+ export { getStoryPreviewPageServerSideProps } from './storyPreview';
@@ -0,0 +1,8 @@
1
+ import type { GetServerSidePropsContext } from 'next';
2
+
3
+ import type { PageProps } from '../../../types';
4
+
5
+ export type PropsFunction<CustomProps> = (
6
+ context: GetServerSidePropsContext,
7
+ props: PageProps,
8
+ ) => CustomProps | Promise<CustomProps>;
@@ -0,0 +1,27 @@
1
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
2
+
3
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
4
+ import { processRequest } from '../processRequest';
5
+
6
+ import type { PropsFunction } from './lib/types';
7
+
8
+ export function getSearchPageServerSideProps<CustomProps extends Record<string, any>>(
9
+ customProps: CustomProps | PropsFunction<CustomProps>,
10
+ ) {
11
+ return async function getServerSideProps(
12
+ context: GetServerSidePropsContext,
13
+ ): Promise<GetServerSidePropsResult<CustomProps>> {
14
+ const { serverSideProps } = await getNewsroomServerSideProps(context);
15
+
16
+ return processRequest(
17
+ context,
18
+ {
19
+ ...serverSideProps,
20
+ ...(typeof customProps === 'function'
21
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
22
+ : customProps),
23
+ },
24
+ '/search',
25
+ );
26
+ };
27
+ }
@@ -0,0 +1,47 @@
1
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
2
+
3
+ import { getPrezlyApi } from '../../data-fetching';
4
+ import { DUMMY_DEFAULT_LOCALE } from '../../intl';
5
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
6
+ import { processRequest } from '../processRequest';
7
+
8
+ import type { PropsFunction } from './lib/types';
9
+
10
+ export function getStoryPageServerSideProps<CustomProps extends Record<string, any>>(
11
+ customProps: CustomProps | PropsFunction<CustomProps>,
12
+ ) {
13
+ return async function getServerSideProps(
14
+ context: GetServerSidePropsContext,
15
+ ): Promise<GetServerSidePropsResult<CustomProps>> {
16
+ const api = getPrezlyApi(context.req);
17
+
18
+ const { slug } = context.params as { slug?: string };
19
+ const story = slug ? await api.getStoryBySlug(slug) : null;
20
+ if (!story) {
21
+ return { notFound: true };
22
+ }
23
+
24
+ const { serverSideProps } = await getNewsroomServerSideProps(context, { story });
25
+
26
+ const { locale } = context;
27
+ if (locale && locale !== DUMMY_DEFAULT_LOCALE) {
28
+ return {
29
+ redirect: {
30
+ destination: `/${slug}`,
31
+ permanent: true,
32
+ },
33
+ };
34
+ }
35
+
36
+ return processRequest(context, {
37
+ ...serverSideProps,
38
+ newsroomContextProps: {
39
+ ...serverSideProps.newsroomContextProps,
40
+ currentStory: story,
41
+ },
42
+ ...(typeof customProps === 'function'
43
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
44
+ : customProps),
45
+ });
46
+ };
47
+ }
@@ -0,0 +1,35 @@
1
+ import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
2
+
3
+ import { getPrezlyApi } from '../../data-fetching';
4
+ import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
5
+ import { processRequest } from '../processRequest';
6
+
7
+ import type { PropsFunction } from './lib/types';
8
+
9
+ export function getStoryPreviewPageServerSideProps<CustomProps extends Record<string, any>>(
10
+ customProps: CustomProps | PropsFunction<CustomProps>,
11
+ ) {
12
+ return async function getServerSideProps(
13
+ context: GetServerSidePropsContext,
14
+ ): Promise<GetServerSidePropsResult<CustomProps>> {
15
+ const api = getPrezlyApi(context.req);
16
+ const { uuid } = context.params as { uuid: string };
17
+ const story = await api.getStory(uuid);
18
+ if (!story) {
19
+ return { notFound: true };
20
+ }
21
+
22
+ const { serverSideProps } = await getNewsroomServerSideProps(context, { story });
23
+
24
+ return processRequest(context, {
25
+ ...serverSideProps,
26
+ newsroomContextProps: {
27
+ ...serverSideProps.newsroomContextProps,
28
+ currentStory: story,
29
+ },
30
+ ...(typeof customProps === 'function'
31
+ ? await (customProps as PropsFunction<CustomProps>)(context, serverSideProps)
32
+ : customProps),
33
+ });
34
+ };
35
+ }
@@ -1,2 +1,3 @@
1
1
  export const ASSETS_URL = 'https://cdn.uc.assets.prezly.com';
2
2
  export const DEFAULT_PAGE_SIZE = 12;
3
+ export const DEFAULT_GALLERY_PAGE_SIZE = 6;