@blaze-cms/nextjs-tools 0.146.0-node18.1 → 0.146.0-rc-eagle.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/CHANGELOG.md +20 -13
- package/README.md +6 -0
- package/lib/application/query/index.js +68 -15
- package/lib/application/query/index.js.map +1 -1
- package/lib/blaze.config.js +16 -18
- package/lib/blaze.config.js.map +1 -1
- package/lib/components/DebugSidebar/DebugSidebar.js +115 -0
- package/lib/components/DebugSidebar/DebugSidebar.js.map +1 -0
- package/lib/components/DebugSidebar/DebugSidebarRender.js +65 -0
- package/lib/components/DebugSidebar/DebugSidebarRender.js.map +1 -0
- package/lib/components/DebugSidebar/index.js +3 -73
- package/lib/components/DebugSidebar/index.js.map +1 -1
- package/lib/components/HashObserver.js +14 -0
- package/lib/components/HashObserver.js.map +1 -0
- package/lib/components/index.js +9 -3
- package/lib/components/index.js.map +1 -1
- package/lib/constants.js +68 -61
- package/lib/constants.js.map +1 -1
- package/lib/containers/ContentContainer.js +65 -74
- package/lib/containers/ContentContainer.js.map +1 -1
- package/lib/containers/index.js +2 -3
- package/lib/containers/index.js.map +1 -1
- package/lib/helpers/build-admin-href.js +8 -11
- package/lib/helpers/build-admin-href.js.map +1 -1
- package/lib/helpers/check-for-gtm.js +10 -17
- package/lib/helpers/check-for-gtm.js.map +1 -1
- package/lib/helpers/check-parent.js +3 -5
- package/lib/helpers/check-parent.js.map +1 -1
- package/lib/helpers/check-preview-url.js +3 -6
- package/lib/helpers/check-preview-url.js.map +1 -1
- package/lib/helpers/check-url.js +197 -217
- package/lib/helpers/check-url.js.map +1 -1
- package/lib/helpers/get-entitys-actions.js +11 -11
- package/lib/helpers/get-entitys-actions.js.map +1 -1
- package/lib/helpers/get-error-message.js +4 -6
- package/lib/helpers/get-error-message.js.map +1 -1
- package/lib/helpers/get-from-local.js +17 -0
- package/lib/helpers/get-from-local.js.map +1 -0
- package/lib/helpers/get-page-data.js +34 -59
- package/lib/helpers/get-page-data.js.map +1 -1
- package/lib/helpers/get-root-selector-classes.js +8 -18
- package/lib/helpers/get-root-selector-classes.js.map +1 -1
- package/lib/helpers/get-search-filter.js +8 -12
- package/lib/helpers/get-search-filter.js.map +1 -1
- package/lib/helpers/handle-static-routes.js +5 -35
- package/lib/helpers/handle-static-routes.js.map +1 -1
- package/lib/helpers/index.js +29 -23
- package/lib/helpers/index.js.map +1 -1
- package/lib/helpers/render-apple-tags.js +11 -17
- package/lib/helpers/render-apple-tags.js.map +1 -1
- package/lib/helpers/set-blaze-debug.js +30 -21
- package/lib/helpers/set-blaze-debug.js.map +1 -1
- package/lib/helpers/static-route-handlers/generic-file-handler.js +35 -66
- package/lib/helpers/static-route-handlers/generic-file-handler.js.map +1 -1
- package/lib/helpers/static-route-handlers/index.js +22 -20
- package/lib/helpers/static-route-handlers/index.js.map +1 -1
- package/lib/helpers/static-route-handlers/llms.js +26 -0
- package/lib/helpers/static-route-handlers/llms.js.map +1 -0
- package/lib/helpers/static-route-handlers/robots-txt.js +15 -10
- package/lib/helpers/static-route-handlers/robots-txt.js.map +1 -1
- package/lib/helpers/static-route-handlers/sitemap-file.js +17 -13
- package/lib/helpers/static-route-handlers/sitemap-file.js.map +1 -1
- package/lib/helpers/static-route-handlers/sitemap.js +14 -9
- package/lib/helpers/static-route-handlers/sitemap.js.map +1 -1
- package/lib/hoc/withBlaze.js +117 -209
- package/lib/hoc/withBlaze.js.map +1 -1
- package/lib/hooks/use-get-page.js +14 -15
- package/lib/hooks/use-get-page.js.map +1 -1
- package/lib/hooks/use-hash-observer.js +101 -0
- package/lib/hooks/use-hash-observer.js.map +1 -0
- package/lib/index.js +10 -19
- package/lib/index.js.map +1 -1
- package/lib/pages/Resolver.js +43 -70
- package/lib/pages/Resolver.js.map +1 -1
- package/lib/pages/document/DocumentBody.js +6 -8
- package/lib/pages/document/DocumentBody.js.map +1 -1
- package/lib/pages/document/_document.js +21 -23
- package/lib/pages/document/_document.js.map +1 -1
- package/lib/server/index.js +13 -35
- package/lib/server/index.js.map +1 -1
- package/package.json +24 -26
- package/src/application/query/index.js +5 -0
- package/src/blaze.config.js +5 -1
- package/src/components/DebugSidebar/DebugSidebar.js +110 -0
- package/src/components/DebugSidebar/DebugSidebarRender.js +64 -0
- package/src/components/DebugSidebar/index.js +2 -61
- package/src/components/HashObserver.js +8 -0
- package/src/components/index.js +2 -1
- package/src/constants.js +12 -1
- package/src/containers/ContentContainer.js +16 -1
- package/src/helpers/check-url.js +76 -33
- package/src/helpers/get-from-local.js +12 -0
- package/src/helpers/index.js +2 -0
- package/src/helpers/set-blaze-debug.js +25 -15
- package/src/helpers/static-route-handlers/index.js +3 -0
- package/{lib-es/helpers/static-route-handlers/robots-txt.js → src/helpers/static-route-handlers/llms.js} +7 -4
- package/src/hoc/withBlaze.js +2 -0
- package/src/hooks/use-hash-observer.js +116 -0
- package/src/index.js +0 -1
- package/src/pages/Resolver.js +7 -4
- package/src/pages/document/_document.js +11 -5
- package/tests/unit/src/__snapshots__/constants.test.js.snap +6 -0
- package/tests/unit/src/application/query/__snapshots__/index.test.js.snap +98 -2
- package/tests/unit/src/components/DebugSidebar/DebugSidebar.test.js +14 -5
- package/tests/unit/src/components/DebugSidebar/__snapshots__/DebugSidebar.test.js.snap +23 -0
- package/tests/unit/src/containers/ContentContainer.test.js +2 -0
- package/tests/unit/src/containers/__snapshots__/ContentContainer.test.js.snap +7 -2
- package/tests/unit/src/helpers/check-url.test.js +55 -12
- package/tests/unit/src/helpers/static-route-handlers/__snapshots__/index.test.js.snap +1 -0
- package/tests/unit/src/helpers/static-route-handlers/__snapshots__/llms.test.js.snap +158 -0
- package/tests/unit/src/helpers/static-route-handlers/llms.test.js +4 -0
- package/tests/unit/src/hooks/use-hash-observer.test.js +260 -0
- package/tests/unit/src/pages/Resolver.test.js +5 -1
- package/tests/unit/src/pages/__snapshots__/Resolver.test.js.snap +5 -1
- package/build/next.base.config.js +0 -185
- package/lib/server/routes.js +0 -37
- package/lib/server/routes.js.map +0 -1
- package/lib-es/application/query/index.js +0 -66
- package/lib-es/application/query/index.js.map +0 -1
- package/lib-es/blaze.config.js +0 -24
- package/lib-es/blaze.config.js.map +0 -1
- package/lib-es/components/DebugSidebar/index.js +0 -55
- package/lib-es/components/DebugSidebar/index.js.map +0 -1
- package/lib-es/components/index.js +0 -3
- package/lib-es/components/index.js.map +0 -1
- package/lib-es/constants.js +0 -92
- package/lib-es/constants.js.map +0 -1
- package/lib-es/containers/ContentContainer.js +0 -81
- package/lib-es/containers/ContentContainer.js.map +0 -1
- package/lib-es/containers/index.js +0 -3
- package/lib-es/containers/index.js.map +0 -1
- package/lib-es/helpers/build-admin-href.js +0 -11
- package/lib-es/helpers/build-admin-href.js.map +0 -1
- package/lib-es/helpers/check-for-gtm.js +0 -11
- package/lib-es/helpers/check-for-gtm.js.map +0 -1
- package/lib-es/helpers/check-parent.js +0 -8
- package/lib-es/helpers/check-parent.js.map +0 -1
- package/lib-es/helpers/check-preview-url.js +0 -9
- package/lib-es/helpers/check-preview-url.js.map +0 -1
- package/lib-es/helpers/check-url.js +0 -190
- package/lib-es/helpers/check-url.js.map +0 -1
- package/lib-es/helpers/get-entitys-actions.js +0 -16
- package/lib-es/helpers/get-entitys-actions.js.map +0 -1
- package/lib-es/helpers/get-error-message.js +0 -13
- package/lib-es/helpers/get-error-message.js.map +0 -1
- package/lib-es/helpers/get-page-data.js +0 -39
- package/lib-es/helpers/get-page-data.js.map +0 -1
- package/lib-es/helpers/get-root-selector-classes.js +0 -14
- package/lib-es/helpers/get-root-selector-classes.js.map +0 -1
- package/lib-es/helpers/get-search-filter.js +0 -14
- package/lib-es/helpers/get-search-filter.js.map +0 -1
- package/lib-es/helpers/handle-static-routes.js +0 -12
- package/lib-es/helpers/handle-static-routes.js.map +0 -1
- package/lib-es/helpers/index.js +0 -13
- package/lib-es/helpers/index.js.map +0 -1
- package/lib-es/helpers/render-apple-tags.js +0 -13
- package/lib-es/helpers/render-apple-tags.js.map +0 -1
- package/lib-es/helpers/set-blaze-debug.js +0 -22
- package/lib-es/helpers/set-blaze-debug.js.map +0 -1
- package/lib-es/helpers/static-route-handlers/generic-file-handler.js +0 -43
- package/lib-es/helpers/static-route-handlers/generic-file-handler.js.map +0 -1
- package/lib-es/helpers/static-route-handlers/index.js +0 -21
- package/lib-es/helpers/static-route-handlers/index.js.map +0 -1
- package/lib-es/helpers/static-route-handlers/robots-txt.js.map +0 -1
- package/lib-es/helpers/static-route-handlers/sitemap-file.js +0 -27
- package/lib-es/helpers/static-route-handlers/sitemap-file.js.map +0 -1
- package/lib-es/helpers/static-route-handlers/sitemap.js +0 -19
- package/lib-es/helpers/static-route-handlers/sitemap.js.map +0 -1
- package/lib-es/hoc/withBlaze.js +0 -152
- package/lib-es/hoc/withBlaze.js.map +0 -1
- package/lib-es/hooks/use-get-page.js +0 -19
- package/lib-es/hooks/use-get-page.js.map +0 -1
- package/lib-es/index.js +0 -9
- package/lib-es/index.js.map +0 -1
- package/lib-es/pages/Resolver.js +0 -88
- package/lib-es/pages/Resolver.js.map +0 -1
- package/lib-es/pages/document/DocumentBody.js +0 -11
- package/lib-es/pages/document/DocumentBody.js.map +0 -1
- package/lib-es/pages/document/_document.js +0 -18
- package/lib-es/pages/document/_document.js.map +0 -1
- package/lib-es/server/index.js +0 -16
- package/lib-es/server/index.js.map +0 -1
- package/lib-es/server/routes.js +0 -36
- package/lib-es/server/routes.js.map +0 -1
- package/src/server/routes.js +0 -42
- package/tests/unit/src/server/__snapshots__/routes.test.js.snap +0 -31
- package/tests/unit/src/server/routes.test.js +0 -11
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { useState } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { IoCloseOutline } from 'react-icons/io5';
|
|
6
|
+
import { useRouter } from 'next/router';
|
|
7
|
+
import { MdKeyboardArrowLeft, MdEdit } from 'react-icons/md';
|
|
8
|
+
import { Link } from '@blaze-cms/nextjs-components';
|
|
9
|
+
import Switches from '@blaze-react/switches';
|
|
10
|
+
import { buildAdminHref, setBlazeDebug } from '../../helpers';
|
|
11
|
+
import { DEBUG_LOGO, BLAZE_DEBUG } from '../../constants';
|
|
12
|
+
|
|
13
|
+
const DebugSidebar = ({ itemEntity, itemId, updatedDebugOptions, debugMode, setIsDebugMode }) => {
|
|
14
|
+
const router = useRouter();
|
|
15
|
+
const [isEditorMode, setIsEditorMode] = useState(false);
|
|
16
|
+
const [isOpen, setIsOpen] = useState(true);
|
|
17
|
+
|
|
18
|
+
const divClass = classnames('debug-sidebar', {
|
|
19
|
+
'debug-sidebar--open': isOpen,
|
|
20
|
+
'debug-sidebar--close': !isOpen
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const toggleEditorMode = () => {
|
|
24
|
+
// todo: persist editor mode in local storage
|
|
25
|
+
// const currentEditorMode = getFromLocal(BLAZE_PB_EDITOR_MODE);
|
|
26
|
+
// if (currentEditorMode) {
|
|
27
|
+
// window.localStorage.removeItem(BLAZE_PB_EDITOR_MODE);
|
|
28
|
+
// } else {
|
|
29
|
+
// window.localStorage.setItem(BLAZE_PB_EDITOR_MODE, true);
|
|
30
|
+
// }
|
|
31
|
+
updatedDebugOptions('editorModeEnabled', !isEditorMode);
|
|
32
|
+
updatedDebugOptions({
|
|
33
|
+
editorModeEnabled: !isEditorMode,
|
|
34
|
+
adminHref: buildAdminHref({ itemEntity, itemId })
|
|
35
|
+
});
|
|
36
|
+
setIsEditorMode(!isEditorMode);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const href = buildAdminHref({ itemEntity, itemId });
|
|
40
|
+
|
|
41
|
+
const closeDebug = () => {
|
|
42
|
+
setBlazeDebug(setIsDebugMode);
|
|
43
|
+
window.blaze.debug();
|
|
44
|
+
|
|
45
|
+
const [pathname, search = ''] = router.asPath.split('?');
|
|
46
|
+
const params = new URLSearchParams(search);
|
|
47
|
+
params.delete(BLAZE_DEBUG);
|
|
48
|
+
const newUrl = params.toString() ? `${pathname}?${params.toString()}` : pathname;
|
|
49
|
+
|
|
50
|
+
router.push('/Resolver', newUrl, {
|
|
51
|
+
shallow: true
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return createPortal(
|
|
56
|
+
<div className={divClass} data-testid="debug-sidebar">
|
|
57
|
+
<Link href={href} target="_blank">
|
|
58
|
+
<img src={DEBUG_LOGO.SRC} alt={DEBUG_LOGO.ALT} />
|
|
59
|
+
</Link>
|
|
60
|
+
<div
|
|
61
|
+
role="button"
|
|
62
|
+
className="debug-sidebar__button debug-sidebar__button--close"
|
|
63
|
+
data-testid="debug-sidebar-close"
|
|
64
|
+
aria-label="Close debug sidebar"
|
|
65
|
+
onClick={closeDebug}>
|
|
66
|
+
<IoCloseOutline />
|
|
67
|
+
</div>
|
|
68
|
+
<Switches
|
|
69
|
+
onChange={toggleEditorMode}
|
|
70
|
+
name="debug-sidebar-switch"
|
|
71
|
+
icon={<MdEdit />}
|
|
72
|
+
alignVertically
|
|
73
|
+
returnBoolean
|
|
74
|
+
onText="ON"
|
|
75
|
+
offText="OFF"
|
|
76
|
+
options={{
|
|
77
|
+
id: 'debug-sidebar-switch',
|
|
78
|
+
checked: isEditorMode
|
|
79
|
+
}}
|
|
80
|
+
/>
|
|
81
|
+
<div
|
|
82
|
+
role="button"
|
|
83
|
+
className="debug-sidebar__button open"
|
|
84
|
+
data-testid="debug-sidebar-button"
|
|
85
|
+
id="debug-sidebar-button"
|
|
86
|
+
onClick={() => setIsOpen(!isOpen)}>
|
|
87
|
+
<i>
|
|
88
|
+
<MdKeyboardArrowLeft />
|
|
89
|
+
</i>
|
|
90
|
+
</div>
|
|
91
|
+
</div>,
|
|
92
|
+
document.body
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
DebugSidebar.propTypes = {
|
|
97
|
+
updatedDebugOptions: PropTypes.func.isRequired,
|
|
98
|
+
itemEntity: PropTypes.string,
|
|
99
|
+
itemId: PropTypes.string,
|
|
100
|
+
debugMode: PropTypes.bool,
|
|
101
|
+
setIsDebugMode: PropTypes.func.isRequired
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
DebugSidebar.defaultProps = {
|
|
105
|
+
itemEntity: '',
|
|
106
|
+
itemId: '',
|
|
107
|
+
debugMode: false
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default DebugSidebar;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import dynamic from 'next/dynamic';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
5
|
+
import { setBlazeDebug, getFromLocal } from '../../helpers';
|
|
6
|
+
import { BLAZE_DEBUG } from '../../constants';
|
|
7
|
+
|
|
8
|
+
const DebugSidebar = dynamic(() => import('./DebugSidebar'));
|
|
9
|
+
|
|
10
|
+
const DebugSidebarRender = ({ itemEntity, itemId, updatedDebugOptions, debugMode }) => {
|
|
11
|
+
const [isDebugMode, setIsDebugMode] = useState(debugMode);
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const currentDebugValue = getFromLocal(BLAZE_DEBUG);
|
|
16
|
+
setIsDebugMode(currentDebugValue);
|
|
17
|
+
setBlazeDebug(setIsDebugMode);
|
|
18
|
+
}, []);
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const handleRouteChange = url => {
|
|
22
|
+
const hasDebug = url.includes(`${BLAZE_DEBUG}=1`);
|
|
23
|
+
if (hasDebug) {
|
|
24
|
+
setBlazeDebug(setIsDebugMode);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (router.asPath.includes(`${BLAZE_DEBUG}=1`)) {
|
|
29
|
+
handleRouteChange(router.asPath);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
router.events.on('routeChangeComplete', handleRouteChange);
|
|
33
|
+
return () => {
|
|
34
|
+
router.events.off('routeChangeComplete', handleRouteChange);
|
|
35
|
+
};
|
|
36
|
+
}, [router.events, router.asPath]);
|
|
37
|
+
|
|
38
|
+
if (!isDebugMode) return null;
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<DebugSidebar
|
|
42
|
+
itemEntity={itemEntity}
|
|
43
|
+
itemId={itemId}
|
|
44
|
+
updatedDebugOptions={updatedDebugOptions}
|
|
45
|
+
debugMode={debugMode}
|
|
46
|
+
setIsDebugMode={setIsDebugMode}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
DebugSidebarRender.propTypes = {
|
|
52
|
+
updatedDebugOptions: PropTypes.func.isRequired,
|
|
53
|
+
itemEntity: PropTypes.string,
|
|
54
|
+
itemId: PropTypes.string,
|
|
55
|
+
debugMode: PropTypes.bool
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
DebugSidebarRender.defaultProps = {
|
|
59
|
+
itemEntity: '',
|
|
60
|
+
itemId: '',
|
|
61
|
+
debugMode: false
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default DebugSidebarRender;
|
|
@@ -1,62 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import classnames from 'classnames';
|
|
4
|
-
import { Link } from '@blaze-cms/nextjs-components';
|
|
5
|
-
import { MdKeyboardArrowLeft } from 'react-icons/md';
|
|
6
|
-
import { buildAdminHref, setBlazeDebug } from '../../helpers';
|
|
7
|
-
import { DEBUG_LOGO } from '../../constants';
|
|
1
|
+
import DebugSidebarRender from './DebugSidebarRender';
|
|
8
2
|
|
|
9
|
-
|
|
10
|
-
const [isDebugMode, setIsDebugMode] = useState(debugMode);
|
|
11
|
-
const [isOpen, setIsOpen] = useState(true);
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (debugMode === true) {
|
|
15
|
-
setIsDebugMode(debugMode);
|
|
16
|
-
} else setBlazeDebug(setIsDebugMode);
|
|
17
|
-
}, [debugMode]);
|
|
18
|
-
|
|
19
|
-
const divClass = classnames('debug-sidebar', {
|
|
20
|
-
'debug-sidebar--open': isOpen,
|
|
21
|
-
'debug-sidebar--close': !isOpen
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const href = buildAdminHref({ itemEntity, itemId });
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<>
|
|
28
|
-
{isDebugMode ? (
|
|
29
|
-
<div className={divClass} data-testid="debug-sidebar">
|
|
30
|
-
<Link href={href}>
|
|
31
|
-
<img src={DEBUG_LOGO.SRC} alt={DEBUG_LOGO.ALT} />
|
|
32
|
-
<span>Blaze admin</span>
|
|
33
|
-
</Link>
|
|
34
|
-
<div
|
|
35
|
-
role="button"
|
|
36
|
-
className="debug-sidebar__button open"
|
|
37
|
-
data-testid="debug-sidebar-button"
|
|
38
|
-
id="debug-sidebar-button"
|
|
39
|
-
onClick={() => setIsOpen(!isOpen)}>
|
|
40
|
-
<i>
|
|
41
|
-
<MdKeyboardArrowLeft />
|
|
42
|
-
</i>
|
|
43
|
-
</div>
|
|
44
|
-
</div>
|
|
45
|
-
) : null}
|
|
46
|
-
</>
|
|
47
|
-
);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
DebugSidebar.propTypes = {
|
|
51
|
-
itemEntity: PropTypes.string,
|
|
52
|
-
itemId: PropTypes.string,
|
|
53
|
-
debugMode: PropTypes.bool
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
DebugSidebar.defaultProps = {
|
|
57
|
-
itemEntity: '',
|
|
58
|
-
itemId: '',
|
|
59
|
-
debugMode: false
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export default DebugSidebar;
|
|
3
|
+
export default DebugSidebarRender;
|
package/src/components/index.js
CHANGED
package/src/constants.js
CHANGED
|
@@ -32,6 +32,8 @@ const PREVIEW_REGEX = /^(\/_preview)/;
|
|
|
32
32
|
const PREVIEW_MODE = 'Preview Mode';
|
|
33
33
|
const GTM_STRING = 'gtm';
|
|
34
34
|
|
|
35
|
+
const BLAZE_DEBUG = 'blaze_debug';
|
|
36
|
+
const BLAZE_PB_EDITOR_MODE = 'blaze_pb_editor_mode';
|
|
35
37
|
const DEBUG_LOGO = {
|
|
36
38
|
SRC: 'https://images.thisisblaze.com/logo-small-27-40.png',
|
|
37
39
|
ALT: 'blaze-logo'
|
|
@@ -46,6 +48,8 @@ const ROUTE_PATTERN_SITEMAP = process.env.BLAZE_ROUTE_PATTERN_SITEMAP || '/sitem
|
|
|
46
48
|
const sitemapFilePrefix = process.env.BLAZE_CONTENT_SITEMAP_URL_PREFIX || 'sitemap';
|
|
47
49
|
const ROUTE_PATTERN_SITEMAP_FILE_REGEX = new RegExp(`/${sitemapFilePrefix}/.*\.xml`);
|
|
48
50
|
const ROUTE_PATTERN_ROBOTS_TXT = '/robots.txt';
|
|
51
|
+
const ROUTE_PATTERN_LLMS_TXT = '/llms.txt';
|
|
52
|
+
|
|
49
53
|
const BLAZE_STATIC_ROUTE_STORE_KEY = 'default';
|
|
50
54
|
|
|
51
55
|
const STATIC_FILE_FORWARD_HEADERS = ['content-length', 'last-modified', 'etag'];
|
|
@@ -62,6 +66,9 @@ const NOT_FOUND_STATUS_CODE = 404;
|
|
|
62
66
|
const ROOT_SELECTOR_CLASS_PREFIX = 'root-selector';
|
|
63
67
|
const ROOT_SELECTOR_SEPARATOR = '--';
|
|
64
68
|
const RESOLVER_CONTAINER_CLASS = 'resolver-container';
|
|
69
|
+
const ERROR_URLS = {
|
|
70
|
+
custom404: '/custom-error-404'
|
|
71
|
+
};
|
|
65
72
|
|
|
66
73
|
module.exports = {
|
|
67
74
|
APPLE_TAGS,
|
|
@@ -78,6 +85,8 @@ module.exports = {
|
|
|
78
85
|
PREVIEW_MODE,
|
|
79
86
|
ROUTE_REGEX,
|
|
80
87
|
PREVIEW_REGEX,
|
|
88
|
+
BLAZE_DEBUG,
|
|
89
|
+
BLAZE_PB_EDITOR_MODE,
|
|
81
90
|
DEBUG_LOGO,
|
|
82
91
|
PUBLISHED_,
|
|
83
92
|
RESPONSE_404,
|
|
@@ -86,10 +95,12 @@ module.exports = {
|
|
|
86
95
|
ROUTE_PATTERN_SITEMAP,
|
|
87
96
|
ROUTE_PATTERN_SITEMAP_FILE_REGEX,
|
|
88
97
|
ROUTE_PATTERN_ROBOTS_TXT,
|
|
98
|
+
ROUTE_PATTERN_LLMS_TXT,
|
|
89
99
|
BLAZE_STATIC_ROUTE_STORE_KEY,
|
|
90
100
|
STATIC_FILE_FORWARD_HEADERS,
|
|
91
101
|
ROOT_SELECTOR_CLASS_PREFIX,
|
|
92
102
|
ROOT_SELECTOR_SEPARATOR,
|
|
93
103
|
RESOLVER_CONTAINER_CLASS,
|
|
94
|
-
BLAZE_X_FRAME_OPTIONS_DEFAULT
|
|
104
|
+
BLAZE_X_FRAME_OPTIONS_DEFAULT,
|
|
105
|
+
ERROR_URLS
|
|
95
106
|
};
|
|
@@ -4,9 +4,11 @@ import { buildPBComponents, getLightboxImages } from '@blaze-cms/plugin-page-bui
|
|
|
4
4
|
import { Header, MainContextProvider } from '@blaze-cms/nextjs-components';
|
|
5
5
|
import { getSearchFilter, checkForGtm } from '../helpers';
|
|
6
6
|
import { PREVIEW_MODE } from '../constants';
|
|
7
|
+
import { DebugSidebar } from '../components';
|
|
7
8
|
|
|
8
9
|
const ContentContainer = ({ fullUrl, pageData, isPreview, itemId, itemEntity }) => {
|
|
9
10
|
const [open, setOpen] = useState(false);
|
|
11
|
+
const [debugOptions, setDebugOptions] = useState({ editorModeEnabled: false });
|
|
10
12
|
const [selectedImage, setSelectedImage] = useState(0);
|
|
11
13
|
const toggleModal = () => setOpen(!open);
|
|
12
14
|
|
|
@@ -38,6 +40,7 @@ const ContentContainer = ({ fullUrl, pageData, isPreview, itemId, itemEntity })
|
|
|
38
40
|
lightboxImages,
|
|
39
41
|
setSelectedImage
|
|
40
42
|
};
|
|
43
|
+
|
|
41
44
|
const buildPBComponentsOptions = {
|
|
42
45
|
...options,
|
|
43
46
|
...metaProps,
|
|
@@ -45,9 +48,21 @@ const ContentContainer = ({ fullUrl, pageData, isPreview, itemId, itemEntity })
|
|
|
45
48
|
hasGTM
|
|
46
49
|
};
|
|
47
50
|
|
|
51
|
+
const updatedDebugOptions = (newOptions = {}) => {
|
|
52
|
+
setDebugOptions({
|
|
53
|
+
...debugOptions,
|
|
54
|
+
...newOptions
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
48
58
|
return (
|
|
49
|
-
<MainContextProvider value={{ fullUrl, isPreview, itemId, hasGTM }}>
|
|
59
|
+
<MainContextProvider value={{ fullUrl, isPreview, itemId, itemEntity, hasGTM, debugOptions }}>
|
|
50
60
|
<Header {...metaProps} />
|
|
61
|
+
<DebugSidebar
|
|
62
|
+
itemId={itemId}
|
|
63
|
+
itemEntity={itemEntity}
|
|
64
|
+
updatedDebugOptions={updatedDebugOptions}
|
|
65
|
+
/>
|
|
51
66
|
{isPreview && <div className="preview-header">{PREVIEW_MODE}</div>}
|
|
52
67
|
{!!pageBuilder.length && buildPBComponents(pageBuilder, buildPBComponentsOptions, true)}
|
|
53
68
|
</MainContextProvider>
|
package/src/helpers/check-url.js
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
COLON,
|
|
8
8
|
NOT_FOUND_STATUS_CODE,
|
|
9
9
|
BLAZE_X_FRAME_OPTIONS_DEFAULT,
|
|
10
|
-
ROUTE_REGEX
|
|
10
|
+
ROUTE_REGEX,
|
|
11
|
+
ERROR_URLS
|
|
11
12
|
} from '../constants';
|
|
12
13
|
import { checkUrlQuery } from '../application/query';
|
|
13
14
|
import checkParent from './check-parent';
|
|
@@ -36,7 +37,7 @@ const checkUrl = async props => {
|
|
|
36
37
|
);
|
|
37
38
|
|
|
38
39
|
if (!res.getHeader('Cache-Control')) {
|
|
39
|
-
res.setHeader('Cache-Control', process.env.BLAZE_CACHE_CONTROL_HEADER || '');
|
|
40
|
+
res.setHeader('Cache-Control', process.env.BLAZE_CACHE_CONTROL_HEADER || ' ');
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
if (handler) {
|
|
@@ -88,37 +89,30 @@ const getFullUrl = (req, asPath) => {
|
|
|
88
89
|
return `${protocol}${DOUBLE_SLASH}${hostname}${urlPort}${asPath}`;
|
|
89
90
|
};
|
|
90
91
|
|
|
91
|
-
const doUrlCheck = async
|
|
92
|
+
const doUrlCheck = async args => {
|
|
93
|
+
const { asPath, url, apolloClient, res, blazeApp, errorCheckCode = false } = args;
|
|
92
94
|
try {
|
|
93
95
|
if (!ROUTE_REGEX.test(url)) {
|
|
94
96
|
throw Error('Invalid URL');
|
|
95
97
|
}
|
|
96
|
-
const {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
query: checkUrlQuery,
|
|
102
|
-
variables: {
|
|
103
|
-
url
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
const { cacheControlMaxAge = null } = pageData || {}; // pageData can be null when there is no page
|
|
107
|
-
if (res && cacheControlMaxAge !== null && cacheControlMaxAge >= 0) {
|
|
108
|
-
res.setHeader('Cache-Control', `max-age=${cacheControlMaxAge}`);
|
|
109
|
-
}
|
|
98
|
+
const { data: { checkUrl: { itemId, itemEntity, urlTo, pageData = {} } = {} } = {} } =
|
|
99
|
+
await apolloClient.query({
|
|
100
|
+
query: checkUrlQuery,
|
|
101
|
+
variables: { url }
|
|
102
|
+
});
|
|
110
103
|
|
|
111
|
-
|
|
112
|
-
let redirectUrl = urlTo;
|
|
113
|
-
if (process.env.BLAZE_DISABLE_REDIRECT_WITH_QUERY !== 'true') {
|
|
114
|
-
const queryString = asPath.split('?')[1];
|
|
115
|
-
redirectUrl = queryString ? `${urlTo}?${queryString}` : urlTo;
|
|
116
|
-
}
|
|
104
|
+
setCustomCacheControlHeaders(pageData, res);
|
|
117
105
|
|
|
118
|
-
|
|
119
|
-
return {
|
|
106
|
+
if (urlTo && (urlTo !== url || errorCheckCode)) {
|
|
107
|
+
return handleRedirect({ errorCheckCode, url, urlTo, asPath, res });
|
|
120
108
|
}
|
|
121
109
|
const rootSelectorClasses = getRootSelectorClasses(url, getRootClassesLimit());
|
|
110
|
+
|
|
111
|
+
if (errorCheckCode) {
|
|
112
|
+
blazeApp.events.emit('monitor:log', { message: `Serving custom ${errorCheckCode} page` });
|
|
113
|
+
if (res) res.statusCode = errorCheckCode;
|
|
114
|
+
}
|
|
115
|
+
|
|
122
116
|
return {
|
|
123
117
|
pageData,
|
|
124
118
|
rootSelectorClasses,
|
|
@@ -126,14 +120,7 @@ const doUrlCheck = async ({ asPath, url, apolloClient, res, handle404Error, blaz
|
|
|
126
120
|
itemEntity: getUnpublishedEntityName(itemEntity)
|
|
127
121
|
};
|
|
128
122
|
} catch (err) {
|
|
129
|
-
|
|
130
|
-
if (handle404Error && parentPATH) {
|
|
131
|
-
doRedirect(res, parentPATH);
|
|
132
|
-
} else {
|
|
133
|
-
return handleError(err, res, handle404Error, blazeApp);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return handle404Error ? {} : null;
|
|
123
|
+
return handleUrlError(err, args);
|
|
137
124
|
}
|
|
138
125
|
};
|
|
139
126
|
|
|
@@ -152,6 +139,30 @@ const handleError = (err, res, handle404Error, blazeApp) => {
|
|
|
152
139
|
return {};
|
|
153
140
|
};
|
|
154
141
|
|
|
142
|
+
function handleRedirect({ errorCheckCode, url, urlTo, asPath, res }) {
|
|
143
|
+
if (errorCheckCode) {
|
|
144
|
+
const errorMessage = `Cannot redirect ${url}`;
|
|
145
|
+
const customError = new Error(errorMessage);
|
|
146
|
+
customError.graphQLErrors = [errorMessage];
|
|
147
|
+
throw customError;
|
|
148
|
+
}
|
|
149
|
+
let redirectUrl = urlTo;
|
|
150
|
+
if (process.env.BLAZE_DISABLE_REDIRECT_WITH_QUERY !== 'true') {
|
|
151
|
+
const queryString = asPath.split('?')[1];
|
|
152
|
+
redirectUrl = queryString ? `${urlTo}?${queryString}` : urlTo;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return doRedirect(res, redirectUrl);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function setCustomCacheControlHeaders(pageData, res) {
|
|
159
|
+
const { cacheControlMaxAge = null } = pageData || {};
|
|
160
|
+
|
|
161
|
+
if (res && cacheControlMaxAge !== null && cacheControlMaxAge >= 0) {
|
|
162
|
+
res.setHeader('Cache-Control', `max-age=${cacheControlMaxAge}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
155
166
|
function doRedirect(res, redirectUrl) {
|
|
156
167
|
if (res) {
|
|
157
168
|
res.writeHead(301, { Location: redirectUrl });
|
|
@@ -159,6 +170,38 @@ function doRedirect(res, redirectUrl) {
|
|
|
159
170
|
} else {
|
|
160
171
|
window.location.href = redirectUrl;
|
|
161
172
|
}
|
|
173
|
+
|
|
174
|
+
return { redirecting: true };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
async function handleUrlError(err, args) {
|
|
178
|
+
const { asPath, res, handle404Error, blazeApp, errorCheckCode } = args;
|
|
179
|
+
if (!err.graphQLErrors || !err.graphQLErrors.length) {
|
|
180
|
+
return handleError(err, res, handle404Error, blazeApp);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!errorCheckCode) {
|
|
184
|
+
const result = await doUrlCheck({
|
|
185
|
+
...args,
|
|
186
|
+
url: ERROR_URLS.custom404,
|
|
187
|
+
errorCheckCode: NOT_FOUND_STATUS_CODE
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
if (handle404Error) {
|
|
191
|
+
const parentUrl = checkParent(asPath);
|
|
192
|
+
if (parentUrl) {
|
|
193
|
+
return doRedirect(res, parentUrl);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const parentPATH = checkParent(asPath);
|
|
200
|
+
if (handle404Error && parentPATH) {
|
|
201
|
+
return doRedirect(res, parentPATH);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return handleError(err, res, handle404Error, blazeApp);
|
|
162
205
|
}
|
|
163
206
|
|
|
164
207
|
export default checkUrl;
|
package/src/helpers/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import renderAppleTags from './render-apple-tags';
|
|
|
9
9
|
import getPageData from './get-page-data';
|
|
10
10
|
import getErrorMessage from './get-error-message';
|
|
11
11
|
import getRootSelectorClasses from './get-root-selector-classes';
|
|
12
|
+
import getFromLocal from './get-from-local';
|
|
12
13
|
|
|
13
14
|
export {
|
|
14
15
|
buildAdminHref,
|
|
@@ -16,6 +17,7 @@ export {
|
|
|
16
17
|
checkParent,
|
|
17
18
|
checkUrl,
|
|
18
19
|
getEntitysActions,
|
|
20
|
+
getFromLocal,
|
|
19
21
|
getSearchFilter,
|
|
20
22
|
getPageData,
|
|
21
23
|
getErrorMessage,
|
|
@@ -1,23 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
import { BLAZE_DEBUG, BLAZE_PB_EDITOR_MODE } from '../constants';
|
|
2
|
+
import getFromLocal from './get-from-local';
|
|
2
3
|
|
|
3
4
|
const setBlazeDebug = setIsDebugMode => {
|
|
4
|
-
if (
|
|
5
|
-
window.blaze = {
|
|
6
|
-
debug: () => {
|
|
7
|
-
const { localStorage } = window;
|
|
5
|
+
if (typeof window === 'undefined') return;
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
setIsDebugMode(false);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
7
|
+
const { localStorage, location } = window;
|
|
8
|
+
const params = new URLSearchParams(location.search);
|
|
14
9
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
window.blaze = window.blaze || {};
|
|
11
|
+
window.blaze.debug = () => {
|
|
12
|
+
const stored = getFromLocal(BLAZE_DEBUG);
|
|
13
|
+
if (stored) {
|
|
14
|
+
localStorage.removeItem(BLAZE_DEBUG);
|
|
15
|
+
window.localStorage.removeItem(BLAZE_PB_EDITOR_MODE);
|
|
16
|
+
setIsDebugMode(false);
|
|
17
|
+
} else {
|
|
18
|
+
localStorage.setItem(BLAZE_DEBUG, 'true');
|
|
19
|
+
setIsDebugMode(true);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (params.get(BLAZE_DEBUG) === '1') {
|
|
24
|
+
localStorage.setItem(BLAZE_DEBUG, 'true');
|
|
25
|
+
setIsDebugMode(true);
|
|
26
|
+
return;
|
|
19
27
|
}
|
|
20
|
-
|
|
28
|
+
|
|
29
|
+
const stored = JSON.parse(localStorage.getItem(BLAZE_DEBUG));
|
|
30
|
+
setIsDebugMode(!!stored);
|
|
21
31
|
};
|
|
22
32
|
|
|
23
33
|
export default setBlazeDebug;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import * as sitemap from './sitemap';
|
|
2
2
|
import * as sitemapFile from './sitemap-file';
|
|
3
3
|
import * as robots from './robots-txt';
|
|
4
|
+
import * as llms from './llms';
|
|
4
5
|
|
|
5
6
|
const { pattern: sitemapPattern, handler: sitemapHandler } = sitemap;
|
|
6
7
|
const { pattern: sitemapFilePattern, handler: sitemapFileHandler } = sitemapFile;
|
|
7
8
|
const { pattern: robotsTxtPattern, handler: robotsTxtHandler } = robots;
|
|
9
|
+
const { pattern: llmsPattern, handler: llmsTxtHandler } = llms;
|
|
8
10
|
|
|
9
11
|
const config = new Map();
|
|
10
12
|
config.set(sitemapPattern, sitemapHandler);
|
|
11
13
|
config.set(sitemapFilePattern, sitemapFileHandler);
|
|
12
14
|
config.set(robotsTxtPattern, robotsTxtHandler);
|
|
15
|
+
config.set(llmsPattern, llmsTxtHandler);
|
|
13
16
|
|
|
14
17
|
export default config;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { gql } from '@apollo/client';
|
|
2
|
-
import {
|
|
2
|
+
import { ROUTE_PATTERN_LLMS_TXT, BLAZE_STATIC_ROUTE_STORE_KEY } from '../../constants';
|
|
3
3
|
import getHandler from './generic-file-handler';
|
|
4
|
+
|
|
4
5
|
const storeKey = process.env.BLAZE_STATIC_ROUTE_STORE_KEY || BLAZE_STATIC_ROUTE_STORE_KEY;
|
|
6
|
+
|
|
5
7
|
export const fileQuery = gql`
|
|
6
8
|
query {
|
|
7
9
|
files: getFiles(
|
|
8
|
-
where: { storeKey: "${storeKey}", filename: "
|
|
10
|
+
where: { storeKey: "${storeKey}", filename: "llms.txt" }
|
|
9
11
|
limit: 1
|
|
10
12
|
sort: [{ property: "created", direction: "desc" }]
|
|
11
13
|
) {
|
|
@@ -14,6 +16,7 @@ export const fileQuery = gql`
|
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
`;
|
|
17
|
-
|
|
19
|
+
|
|
20
|
+
export const pattern = new RegExp(ROUTE_PATTERN_LLMS_TXT);
|
|
21
|
+
|
|
18
22
|
export const handler = getHandler(fileQuery);
|
|
19
|
-
//# sourceMappingURL=robots-txt.js.map
|
package/src/hoc/withBlaze.js
CHANGED
|
@@ -8,6 +8,7 @@ import dynamic from 'next/dynamic'; // Next.js dynamic
|
|
|
8
8
|
import { AppContext } from '@blaze-cms/nextjs-components';
|
|
9
9
|
import blazeConfig from '../blaze.config';
|
|
10
10
|
import { getErrorMessage } from '../helpers';
|
|
11
|
+
import HashObserver from '../components/HashObserver';
|
|
11
12
|
|
|
12
13
|
const ErrorBoundary = dynamic(() => import('@blaze-cms/core-errors-ui'));
|
|
13
14
|
|
|
@@ -143,6 +144,7 @@ function getWrappedApp(isSsr, config, blazeApp, App) {
|
|
|
143
144
|
|
|
144
145
|
return (
|
|
145
146
|
<ErrorBoundary app={this.blazeApp}>
|
|
147
|
+
<HashObserver />
|
|
146
148
|
<AppContext.Provider value={{ blazeApp: this.blazeApp }}>
|
|
147
149
|
<App {...this.props} apolloClient={this.apolloClient} blazeApp={this.blazeApp} />
|
|
148
150
|
</AppContext.Provider>
|