@blaze-cms/nextjs-tools 0.146.0-node18.0 → 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.
Files changed (187) hide show
  1. package/CHANGELOG.md +20 -5
  2. package/README.md +6 -0
  3. package/lib/application/query/index.js +68 -15
  4. package/lib/application/query/index.js.map +1 -1
  5. package/lib/blaze.config.js +16 -18
  6. package/lib/blaze.config.js.map +1 -1
  7. package/lib/components/DebugSidebar/DebugSidebar.js +115 -0
  8. package/lib/components/DebugSidebar/DebugSidebar.js.map +1 -0
  9. package/lib/components/DebugSidebar/DebugSidebarRender.js +65 -0
  10. package/lib/components/DebugSidebar/DebugSidebarRender.js.map +1 -0
  11. package/lib/components/DebugSidebar/index.js +3 -73
  12. package/lib/components/DebugSidebar/index.js.map +1 -1
  13. package/lib/components/HashObserver.js +14 -0
  14. package/lib/components/HashObserver.js.map +1 -0
  15. package/lib/components/index.js +9 -3
  16. package/lib/components/index.js.map +1 -1
  17. package/lib/constants.js +68 -61
  18. package/lib/constants.js.map +1 -1
  19. package/lib/containers/ContentContainer.js +65 -74
  20. package/lib/containers/ContentContainer.js.map +1 -1
  21. package/lib/containers/index.js +2 -3
  22. package/lib/containers/index.js.map +1 -1
  23. package/lib/helpers/build-admin-href.js +8 -11
  24. package/lib/helpers/build-admin-href.js.map +1 -1
  25. package/lib/helpers/check-for-gtm.js +10 -17
  26. package/lib/helpers/check-for-gtm.js.map +1 -1
  27. package/lib/helpers/check-parent.js +3 -5
  28. package/lib/helpers/check-parent.js.map +1 -1
  29. package/lib/helpers/check-preview-url.js +3 -6
  30. package/lib/helpers/check-preview-url.js.map +1 -1
  31. package/lib/helpers/check-url.js +197 -217
  32. package/lib/helpers/check-url.js.map +1 -1
  33. package/lib/helpers/get-entitys-actions.js +11 -11
  34. package/lib/helpers/get-entitys-actions.js.map +1 -1
  35. package/lib/helpers/get-error-message.js +4 -6
  36. package/lib/helpers/get-error-message.js.map +1 -1
  37. package/lib/helpers/get-from-local.js +17 -0
  38. package/lib/helpers/get-from-local.js.map +1 -0
  39. package/lib/helpers/get-page-data.js +34 -59
  40. package/lib/helpers/get-page-data.js.map +1 -1
  41. package/lib/helpers/get-root-selector-classes.js +8 -18
  42. package/lib/helpers/get-root-selector-classes.js.map +1 -1
  43. package/lib/helpers/get-search-filter.js +8 -12
  44. package/lib/helpers/get-search-filter.js.map +1 -1
  45. package/lib/helpers/handle-static-routes.js +5 -35
  46. package/lib/helpers/handle-static-routes.js.map +1 -1
  47. package/lib/helpers/index.js +29 -23
  48. package/lib/helpers/index.js.map +1 -1
  49. package/lib/helpers/render-apple-tags.js +11 -17
  50. package/lib/helpers/render-apple-tags.js.map +1 -1
  51. package/lib/helpers/set-blaze-debug.js +30 -21
  52. package/lib/helpers/set-blaze-debug.js.map +1 -1
  53. package/lib/helpers/static-route-handlers/generic-file-handler.js +35 -66
  54. package/lib/helpers/static-route-handlers/generic-file-handler.js.map +1 -1
  55. package/lib/helpers/static-route-handlers/index.js +22 -20
  56. package/lib/helpers/static-route-handlers/index.js.map +1 -1
  57. package/lib/helpers/static-route-handlers/llms.js +26 -0
  58. package/lib/helpers/static-route-handlers/llms.js.map +1 -0
  59. package/lib/helpers/static-route-handlers/robots-txt.js +15 -10
  60. package/lib/helpers/static-route-handlers/robots-txt.js.map +1 -1
  61. package/lib/helpers/static-route-handlers/sitemap-file.js +17 -13
  62. package/lib/helpers/static-route-handlers/sitemap-file.js.map +1 -1
  63. package/lib/helpers/static-route-handlers/sitemap.js +14 -9
  64. package/lib/helpers/static-route-handlers/sitemap.js.map +1 -1
  65. package/lib/hoc/withBlaze.js +117 -209
  66. package/lib/hoc/withBlaze.js.map +1 -1
  67. package/lib/hooks/use-get-page.js +14 -15
  68. package/lib/hooks/use-get-page.js.map +1 -1
  69. package/lib/hooks/use-hash-observer.js +101 -0
  70. package/lib/hooks/use-hash-observer.js.map +1 -0
  71. package/lib/index.js +10 -19
  72. package/lib/index.js.map +1 -1
  73. package/lib/pages/Resolver.js +43 -70
  74. package/lib/pages/Resolver.js.map +1 -1
  75. package/lib/pages/document/DocumentBody.js +6 -8
  76. package/lib/pages/document/DocumentBody.js.map +1 -1
  77. package/lib/pages/document/_document.js +21 -23
  78. package/lib/pages/document/_document.js.map +1 -1
  79. package/lib/server/index.js +13 -35
  80. package/lib/server/index.js.map +1 -1
  81. package/package.json +24 -26
  82. package/src/application/query/index.js +5 -0
  83. package/src/blaze.config.js +5 -1
  84. package/src/components/DebugSidebar/DebugSidebar.js +110 -0
  85. package/src/components/DebugSidebar/DebugSidebarRender.js +64 -0
  86. package/src/components/DebugSidebar/index.js +2 -61
  87. package/src/components/HashObserver.js +8 -0
  88. package/src/components/index.js +2 -1
  89. package/src/constants.js +12 -1
  90. package/src/containers/ContentContainer.js +16 -1
  91. package/src/helpers/check-url.js +76 -33
  92. package/src/helpers/get-from-local.js +12 -0
  93. package/src/helpers/index.js +2 -0
  94. package/src/helpers/set-blaze-debug.js +25 -15
  95. package/src/helpers/static-route-handlers/index.js +3 -0
  96. package/{lib-es/helpers/static-route-handlers/robots-txt.js → src/helpers/static-route-handlers/llms.js} +7 -4
  97. package/src/hoc/withBlaze.js +2 -0
  98. package/src/hooks/use-hash-observer.js +116 -0
  99. package/src/index.js +0 -1
  100. package/src/pages/Resolver.js +7 -4
  101. package/src/pages/document/_document.js +11 -5
  102. package/tests/unit/src/__snapshots__/constants.test.js.snap +6 -0
  103. package/tests/unit/src/application/query/__snapshots__/index.test.js.snap +98 -2
  104. package/tests/unit/src/components/DebugSidebar/DebugSidebar.test.js +14 -5
  105. package/tests/unit/src/components/DebugSidebar/__snapshots__/DebugSidebar.test.js.snap +23 -0
  106. package/tests/unit/src/containers/ContentContainer.test.js +2 -0
  107. package/tests/unit/src/containers/__snapshots__/ContentContainer.test.js.snap +7 -2
  108. package/tests/unit/src/helpers/check-url.test.js +55 -12
  109. package/tests/unit/src/helpers/static-route-handlers/__snapshots__/index.test.js.snap +1 -0
  110. package/tests/unit/src/helpers/static-route-handlers/__snapshots__/llms.test.js.snap +158 -0
  111. package/tests/unit/src/helpers/static-route-handlers/llms.test.js +4 -0
  112. package/tests/unit/src/hooks/use-hash-observer.test.js +260 -0
  113. package/tests/unit/src/pages/Resolver.test.js +5 -1
  114. package/tests/unit/src/pages/__snapshots__/Resolver.test.js.snap +5 -1
  115. package/build/next.base.config.js +0 -185
  116. package/lib/server/routes.js +0 -37
  117. package/lib/server/routes.js.map +0 -1
  118. package/lib-es/application/query/index.js +0 -66
  119. package/lib-es/application/query/index.js.map +0 -1
  120. package/lib-es/blaze.config.js +0 -24
  121. package/lib-es/blaze.config.js.map +0 -1
  122. package/lib-es/components/DebugSidebar/index.js +0 -55
  123. package/lib-es/components/DebugSidebar/index.js.map +0 -1
  124. package/lib-es/components/index.js +0 -3
  125. package/lib-es/components/index.js.map +0 -1
  126. package/lib-es/constants.js +0 -92
  127. package/lib-es/constants.js.map +0 -1
  128. package/lib-es/containers/ContentContainer.js +0 -81
  129. package/lib-es/containers/ContentContainer.js.map +0 -1
  130. package/lib-es/containers/index.js +0 -3
  131. package/lib-es/containers/index.js.map +0 -1
  132. package/lib-es/helpers/build-admin-href.js +0 -11
  133. package/lib-es/helpers/build-admin-href.js.map +0 -1
  134. package/lib-es/helpers/check-for-gtm.js +0 -11
  135. package/lib-es/helpers/check-for-gtm.js.map +0 -1
  136. package/lib-es/helpers/check-parent.js +0 -8
  137. package/lib-es/helpers/check-parent.js.map +0 -1
  138. package/lib-es/helpers/check-preview-url.js +0 -9
  139. package/lib-es/helpers/check-preview-url.js.map +0 -1
  140. package/lib-es/helpers/check-url.js +0 -190
  141. package/lib-es/helpers/check-url.js.map +0 -1
  142. package/lib-es/helpers/get-entitys-actions.js +0 -16
  143. package/lib-es/helpers/get-entitys-actions.js.map +0 -1
  144. package/lib-es/helpers/get-error-message.js +0 -13
  145. package/lib-es/helpers/get-error-message.js.map +0 -1
  146. package/lib-es/helpers/get-page-data.js +0 -39
  147. package/lib-es/helpers/get-page-data.js.map +0 -1
  148. package/lib-es/helpers/get-root-selector-classes.js +0 -14
  149. package/lib-es/helpers/get-root-selector-classes.js.map +0 -1
  150. package/lib-es/helpers/get-search-filter.js +0 -14
  151. package/lib-es/helpers/get-search-filter.js.map +0 -1
  152. package/lib-es/helpers/handle-static-routes.js +0 -12
  153. package/lib-es/helpers/handle-static-routes.js.map +0 -1
  154. package/lib-es/helpers/index.js +0 -13
  155. package/lib-es/helpers/index.js.map +0 -1
  156. package/lib-es/helpers/render-apple-tags.js +0 -13
  157. package/lib-es/helpers/render-apple-tags.js.map +0 -1
  158. package/lib-es/helpers/set-blaze-debug.js +0 -22
  159. package/lib-es/helpers/set-blaze-debug.js.map +0 -1
  160. package/lib-es/helpers/static-route-handlers/generic-file-handler.js +0 -43
  161. package/lib-es/helpers/static-route-handlers/generic-file-handler.js.map +0 -1
  162. package/lib-es/helpers/static-route-handlers/index.js +0 -21
  163. package/lib-es/helpers/static-route-handlers/index.js.map +0 -1
  164. package/lib-es/helpers/static-route-handlers/robots-txt.js.map +0 -1
  165. package/lib-es/helpers/static-route-handlers/sitemap-file.js +0 -27
  166. package/lib-es/helpers/static-route-handlers/sitemap-file.js.map +0 -1
  167. package/lib-es/helpers/static-route-handlers/sitemap.js +0 -19
  168. package/lib-es/helpers/static-route-handlers/sitemap.js.map +0 -1
  169. package/lib-es/hoc/withBlaze.js +0 -152
  170. package/lib-es/hoc/withBlaze.js.map +0 -1
  171. package/lib-es/hooks/use-get-page.js +0 -19
  172. package/lib-es/hooks/use-get-page.js.map +0 -1
  173. package/lib-es/index.js +0 -9
  174. package/lib-es/index.js.map +0 -1
  175. package/lib-es/pages/Resolver.js +0 -88
  176. package/lib-es/pages/Resolver.js.map +0 -1
  177. package/lib-es/pages/document/DocumentBody.js +0 -11
  178. package/lib-es/pages/document/DocumentBody.js.map +0 -1
  179. package/lib-es/pages/document/_document.js +0 -18
  180. package/lib-es/pages/document/_document.js.map +0 -1
  181. package/lib-es/server/index.js +0 -16
  182. package/lib-es/server/index.js.map +0 -1
  183. package/lib-es/server/routes.js +0 -36
  184. package/lib-es/server/routes.js.map +0 -1
  185. package/src/server/routes.js +0 -42
  186. package/tests/unit/src/server/__snapshots__/routes.test.js.snap +0 -31
  187. 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 React, { useState, useEffect } from 'react';
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
- const DebugSidebar = ({ itemEntity, itemId, debugMode }) => {
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;
@@ -0,0 +1,8 @@
1
+ import useHashObserver from '../hooks/use-hash-observer';
2
+
3
+ function HashObserver() {
4
+ useHashObserver();
5
+ return null;
6
+ }
7
+
8
+ export default HashObserver;
@@ -1,3 +1,4 @@
1
1
  import DebugSidebar from './DebugSidebar';
2
+ import HashObserver from './HashObserver';
2
3
 
3
- export { DebugSidebar };
4
+ export { DebugSidebar, HashObserver };
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>
@@ -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 ({ asPath, url, apolloClient, res, handle404Error, blazeApp }) => {
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
- data: {
98
- checkUrl: { itemId, itemEntity, urlTo, pageData = {} }
99
- }
100
- } = await apolloClient.query({
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
- if (urlTo && urlTo !== url) {
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
- doRedirect(res, redirectUrl);
119
- return { redirecting: true };
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
- const parentPATH = checkParent(url);
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;
@@ -0,0 +1,12 @@
1
+ const getFromLocal = key => {
2
+ if (typeof window === 'undefined') return null;
3
+
4
+ try {
5
+ const value = localStorage.getItem(key);
6
+ return value ? JSON.parse(value) : null;
7
+ } catch (error) {
8
+ return null;
9
+ }
10
+ };
11
+
12
+ export default getFromLocal;
@@ -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
- const BLAZE_DEBUG = 'blaze_debug';
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 (!window.blaze) {
5
- window.blaze = {
6
- debug: () => {
7
- const { localStorage } = window;
5
+ if (typeof window === 'undefined') return;
8
6
 
9
- if (JSON.parse(localStorage.getItem(BLAZE_DEBUG))) {
10
- localStorage.removeItem(BLAZE_DEBUG);
11
- setIsDebugMode(false);
12
- return;
13
- }
7
+ const { localStorage, location } = window;
8
+ const params = new URLSearchParams(location.search);
14
9
 
15
- localStorage.setItem(BLAZE_DEBUG, true);
16
- setIsDebugMode(true);
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
- setIsDebugMode(JSON.parse(localStorage.getItem(BLAZE_DEBUG)));
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 { ROUTE_PATTERN_ROBOTS_TXT, BLAZE_STATIC_ROUTE_STORE_KEY } from '../../constants';
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: "robots.txt" }
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
- export const pattern = new RegExp(ROUTE_PATTERN_ROBOTS_TXT);
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
@@ -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>