@cmssy/astro 11.4.1 → 11.4.2

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/dist/index.cjs CHANGED
@@ -12,14 +12,19 @@ function cmssyMiddleware(config, options = {}) {
12
12
  const { pathname } = context.url;
13
13
  context.request.headers.delete(core.CMSSY_EDIT_HEADER);
14
14
  context.request.headers.delete(internal.CMSSY_LOCALE_HEADER);
15
- const locale = await internal.localeForPathname(config, pathname);
15
+ const underEditRoute = pathname === CMSSY_EDIT_PATH_PREFIX || pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`);
16
+ const locale = await internal.localeForPathname(
17
+ config,
18
+ underEditRoute ? pathname.slice(CMSSY_EDIT_PATH_PREFIX.length) || "/" : pathname
19
+ );
16
20
  context.request.headers.set(internal.CMSSY_LOCALE_HEADER, locale);
17
21
  const editRequested = context.url.searchParams.getAll(core.CMSSY_EDIT_QUERY_PARAM).includes("1");
18
- const underEditRoute = pathname === CMSSY_EDIT_PATH_PREFIX || pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`);
19
22
  if (editRequested) {
20
23
  const verified = await core.isVerifiedEditUrl(context.url, config);
21
- if (verified && !underEditRoute) {
24
+ if (verified) {
22
25
  context.request.headers.set(core.CMSSY_EDIT_HEADER, "1");
26
+ }
27
+ if (verified && !underEditRoute) {
23
28
  const target = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}${context.url.search}`;
24
29
  const response = await next(
25
30
  new Request(new URL(target, context.url), context.request)
@@ -72,9 +77,13 @@ function cmssyMiddleware(config, options = {}) {
72
77
  return next();
73
78
  };
74
79
  }
80
+ function withoutEditPrefix(pathname) {
81
+ if (pathname === CMSSY_EDIT_PATH_PREFIX) return "/";
82
+ return pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`) ? pathname.slice(CMSSY_EDIT_PATH_PREFIX.length) : pathname;
83
+ }
75
84
  async function loadCmssyPage(config, request, url, options = {}) {
76
85
  const isEdit = request.headers.get(core.CMSSY_EDIT_HEADER) === "1" || await core.isVerifiedEditUrl(url, config);
77
- const segments = url.pathname.replace(/^\/cmssy-edit/, "").split("/").filter(Boolean);
86
+ const segments = withoutEditPrefix(url.pathname).split("/").filter(Boolean);
78
87
  const positions = options.positions ?? ["header", "footer"];
79
88
  const blocks = options.blocks ?? [];
80
89
  const headerLocale = request.headers.get(internal.CMSSY_LOCALE_HEADER) ?? void 0;
package/dist/index.js CHANGED
@@ -11,14 +11,19 @@ function cmssyMiddleware(config, options = {}) {
11
11
  const { pathname } = context.url;
12
12
  context.request.headers.delete(CMSSY_EDIT_HEADER);
13
13
  context.request.headers.delete(CMSSY_LOCALE_HEADER);
14
- const locale = await localeForPathname(config, pathname);
14
+ const underEditRoute = pathname === CMSSY_EDIT_PATH_PREFIX || pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`);
15
+ const locale = await localeForPathname(
16
+ config,
17
+ underEditRoute ? pathname.slice(CMSSY_EDIT_PATH_PREFIX.length) || "/" : pathname
18
+ );
15
19
  context.request.headers.set(CMSSY_LOCALE_HEADER, locale);
16
20
  const editRequested = context.url.searchParams.getAll(CMSSY_EDIT_QUERY_PARAM).includes("1");
17
- const underEditRoute = pathname === CMSSY_EDIT_PATH_PREFIX || pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`);
18
21
  if (editRequested) {
19
22
  const verified = await isVerifiedEditUrl(context.url, config);
20
- if (verified && !underEditRoute) {
23
+ if (verified) {
21
24
  context.request.headers.set(CMSSY_EDIT_HEADER, "1");
25
+ }
26
+ if (verified && !underEditRoute) {
22
27
  const target = `${CMSSY_EDIT_PATH_PREFIX}${pathname === "/" ? "" : pathname}${context.url.search}`;
23
28
  const response = await next(
24
29
  new Request(new URL(target, context.url), context.request)
@@ -71,9 +76,13 @@ function cmssyMiddleware(config, options = {}) {
71
76
  return next();
72
77
  };
73
78
  }
79
+ function withoutEditPrefix(pathname) {
80
+ if (pathname === CMSSY_EDIT_PATH_PREFIX) return "/";
81
+ return pathname.startsWith(`${CMSSY_EDIT_PATH_PREFIX}/`) ? pathname.slice(CMSSY_EDIT_PATH_PREFIX.length) : pathname;
82
+ }
74
83
  async function loadCmssyPage(config, request, url, options = {}) {
75
84
  const isEdit = request.headers.get(CMSSY_EDIT_HEADER) === "1" || await isVerifiedEditUrl(url, config);
76
- const segments = url.pathname.replace(/^\/cmssy-edit/, "").split("/").filter(Boolean);
85
+ const segments = withoutEditPrefix(url.pathname).split("/").filter(Boolean);
77
86
  const positions = options.positions ?? ["header", "footer"];
78
87
  const blocks = options.blocks ?? [];
79
88
  const headerLocale = request.headers.get(CMSSY_LOCALE_HEADER) ?? void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmssy/astro",
3
- "version": "11.4.1",
3
+ "version": "11.4.2",
4
4
  "description": "Astro bindings for cmssy headless sites: middleware, page loader, sitemap and robots.",
5
5
  "keywords": [
6
6
  "cmssy",
@@ -47,10 +47,10 @@
47
47
  "tsup": "^8.3.0",
48
48
  "typescript": "^5.6.0",
49
49
  "vitest": "^2.1.0",
50
- "@cmssy/react": "11.4.1"
50
+ "@cmssy/react": "11.4.2"
51
51
  },
52
52
  "dependencies": {
53
- "@cmssy/core": "11.4.1"
53
+ "@cmssy/core": "11.4.2"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "tsup",