@enonic/nextjs-adapter 0.13.0 → 1.0.0-RC2
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/ComponentRegistry.d.ts +2 -0
- package/ComponentRegistry.js +6 -0
- package/README.md +623 -8
- package/UrlProcessor.d.ts +2 -1
- package/UrlProcessor.js +26 -1
- package/guillotine/fetchContent.d.ts +1 -21
- package/guillotine/fetchContent.js +94 -41
- package/index.d.ts +3 -0
- package/index.js +3 -0
- package/package.json +15 -14
- package/server/ClearableFileCache.d.ts +26 -0
- package/server/ClearableFileCache.js +314 -0
- package/server/cache.d.ts +2 -0
- package/server/cache.js +129 -0
- package/server/index.d.ts +5 -0
- package/server/index.js +114 -0
- package/utils.d.ts +3 -12
- package/utils.js +10 -23
- package/views/RichTextView.jsx +11 -4
package/utils.js
CHANGED
|
@@ -12,9 +12,7 @@ export const APP_NAME_DASHED = (APP_NAME || '').replace(/\./g, '-');
|
|
|
12
12
|
export const SITE_KEY = (process.env.SITE_KEY || process.env.NEXT_PUBLIC_SITE_KEY);
|
|
13
13
|
// //////////////////////////////////////////////////////////////////////// Hardcode-able constants
|
|
14
14
|
// URI parameter marking that a request is for a preview for CS. MUST MATCH THE VALUE OF 'FROM_XP_PARAM' on XP side.
|
|
15
|
-
export const FROM_XP_PARAM = '__fromxp__';
|
|
16
15
|
export const XP_BASE_URL_HEADER = 'xpbaseurl';
|
|
17
|
-
export const COMPONENT_SUBPATH_HEADER = 'xp-component-path';
|
|
18
16
|
export const RENDER_MODE_HEADER = 'content-studio-mode';
|
|
19
17
|
export const JSESSIONID_HEADER = 'jsessionid';
|
|
20
18
|
export const PORTAL_COMPONENT_ATTRIBUTE = 'data-portal-component-type';
|
|
@@ -49,31 +47,25 @@ export var XP_COMPONENT_TYPE;
|
|
|
49
47
|
XP_COMPONENT_TYPE["FRAGMENT"] = "fragment";
|
|
50
48
|
XP_COMPONENT_TYPE["PAGE"] = "page";
|
|
51
49
|
})(XP_COMPONENT_TYPE || (XP_COMPONENT_TYPE = {}));
|
|
52
|
-
|
|
53
|
-
* False if no context, query or FROM_XP_PARAM param */
|
|
54
|
-
export const isRequestFromXP = (context) => {
|
|
55
|
-
return !!getXPRequestType(context);
|
|
56
|
-
};
|
|
57
|
-
export const getXPRequestType = (context) => {
|
|
58
|
-
var _a;
|
|
59
|
-
const headerValue = (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[FROM_XP_PARAM];
|
|
60
|
-
const enumValue = XP_REQUEST_TYPE[headerValue === null || headerValue === void 0 ? void 0 : headerValue.toUpperCase()];
|
|
61
|
-
return enumValue || XP_REQUEST_TYPE.PAGE; // need to have some defaults here in case of rendering without XP
|
|
62
|
-
};
|
|
63
|
-
const getRenderMode = (context) => {
|
|
50
|
+
export const getRenderMode = (context) => {
|
|
64
51
|
var _a;
|
|
65
52
|
const value = (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[RENDER_MODE_HEADER];
|
|
66
53
|
const enumValue = RENDER_MODE[value === null || value === void 0 ? void 0 : value.toUpperCase()];
|
|
67
54
|
return enumValue || RENDER_MODE[process.env.RENDER_MODE] || RENDER_MODE.NEXT;
|
|
68
55
|
};
|
|
69
|
-
const getSingleComponentPath = (context) => {
|
|
70
|
-
var _a;
|
|
71
|
-
return (((_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers) || {})[COMPONENT_SUBPATH_HEADER];
|
|
72
|
-
};
|
|
73
56
|
export function getContentApiUrl(context) {
|
|
74
57
|
const mode = getRenderMode(context);
|
|
75
58
|
return mode === RENDER_MODE.NEXT ? CONTENT_API_MASTER : CONTENT_API_DRAFT;
|
|
76
59
|
}
|
|
60
|
+
export function getJsessionHeaders(context) {
|
|
61
|
+
var _a;
|
|
62
|
+
const headers = {};
|
|
63
|
+
const jsessionid = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.headers[JSESSIONID_HEADER];
|
|
64
|
+
if (jsessionid) {
|
|
65
|
+
headers['Cookie'] = `${JSESSIONID_HEADER}=${jsessionid}`;
|
|
66
|
+
}
|
|
67
|
+
return headers;
|
|
68
|
+
}
|
|
77
69
|
/** For '<a href="..."' link values in props when clicking the link should navigate to an XP content item page
|
|
78
70
|
* and the query returns the XP _path to the target content item:
|
|
79
71
|
* When viewed directly, the header will have a `<base href='/' />` (see src/pages/_app.tsx), and when viewed through an
|
|
@@ -129,13 +121,8 @@ const adapterConstants = {
|
|
|
129
121
|
APP_NAME_UNDERSCORED,
|
|
130
122
|
APP_NAME_DASHED,
|
|
131
123
|
SITE_KEY,
|
|
132
|
-
FROM_XP_PARAM,
|
|
133
|
-
COMPONENT_SUBPATH_HEADER,
|
|
134
124
|
PORTAL_COMPONENT_ATTRIBUTE,
|
|
135
125
|
PORTAL_REGION_ATTRIBUTE,
|
|
136
|
-
getXPRequestType,
|
|
137
|
-
getSingleComponentPath,
|
|
138
|
-
getRenderMode,
|
|
139
126
|
};
|
|
140
127
|
// Verify required values
|
|
141
128
|
const NOT_REQUIRED = ['IS_DEV_MODE'];
|
package/views/RichTextView.jsx
CHANGED
|
@@ -14,10 +14,17 @@ export function createReplacer(allData, meta, renderMacroInEditMode = true, cust
|
|
|
14
14
|
switch (el.tagName) {
|
|
15
15
|
case UrlProcessor.IMG_TAG:
|
|
16
16
|
ref = el.attribs[UrlProcessor.IMG_ATTR];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
if (ref) {
|
|
18
|
+
if (UrlProcessor.isContentImage(ref, allData.images)) {
|
|
19
|
+
const src = el.attribs['src'];
|
|
20
|
+
if (src) {
|
|
21
|
+
el.attribs['src'] = getUrl(src, meta);
|
|
22
|
+
}
|
|
23
|
+
const srcset = el.attribs['srcset'];
|
|
24
|
+
if (srcset) {
|
|
25
|
+
el.attribs['srcset'] = UrlProcessor.processSrcSet(srcset, meta);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
29
|
break;
|
|
23
30
|
case UrlProcessor.LINK_TAG:
|