@exdst-sitecore-content-sdk/create-astro 0.0.22 → 0.0.23

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.
@@ -1,5 +1,11 @@
1
1
  # This file should be copied to .env.local and modified with your environment variables to connect to your Sitecore container instance.
2
2
 
3
+ <% if (prerender === 'SSG') { -%>
4
+ # Set the PRERENDER variable to true if you want to prerender your application.
5
+ # This variable is used in astro.config.mjs to set the prerender value on routes.
6
+ PRERENDER=true
7
+ <% } -%>
8
+
3
9
  # To secure the Sitecore editor endpoint exposed by your Astro app
4
10
  # (`/api/editing/render` by default), a secret token is used. This (client-side)
5
11
  SITECORE_EDITING_SECRET=
@@ -1,5 +1,11 @@
1
1
  # This file should be copied to .env.local and modified with your environment variables to connect to your remote Sitecore instance.
2
2
 
3
+ <% if (prerender === 'SSG') { -%>
4
+ # Set the PRERENDER variable to true if you want to prerender your application.
5
+ # This variable is used in astro.config.mjs to set the prerender value on routes.
6
+ PRERENDER=true
7
+ <% } -%>
8
+
3
9
  # To secure the Sitecore editor endpoint exposed by your Astro app
4
10
  # (`/api/editing/render` by default), a secret token is used. This (client-side)
5
11
  SITECORE_EDITING_SECRET=
@@ -1,12 +1,32 @@
1
1
  import { defineConfig } from 'astro/config';
2
2
  import node from '@astrojs/node';
3
3
  import dotenvFlow from 'dotenv-flow';
4
+ import { loadEnv } from 'vite';
4
5
 
5
6
  // Load enviroment variables from .env.* files
6
7
  dotenvFlow.config();
7
8
 
8
9
  // https://astro.build/config
9
10
  export default defineConfig({
11
+ integrations: [
12
+ {
13
+ name: 'set-prerender',
14
+ hooks: {
15
+ 'astro:route:setup': ({ route }) => {
16
+ // Load environment variables from .env files
17
+ const { PRERENDER } = loadEnv(process.env.NODE_ENV, process.cwd(), '');
18
+ if (route.component.endsWith('/[...path].astro')) {
19
+ // Set the prerender value on routes
20
+ if (process.env.NODE_ENV === 'development') {
21
+ route.prerender = false;
22
+ } else {
23
+ route.prerender = PRERENDER === 'true';
24
+ }
25
+ }
26
+ },
27
+ },
28
+ },
29
+ ],
10
30
  security: {
11
31
  checkOrigin: false,
12
32
  allowedDomains: [{ hostname: '*.sitecorecloud.io' }, { hostname: '*.sitecore.cloud' }],
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@astrojs/node": "^10.0.2",
24
- "@exdst-sitecore-content-sdk/astro": "^0.0.21",
24
+ "@exdst-sitecore-content-sdk/astro": "^0.0.23",
25
25
  "@sitecore-content-sdk/analytics-core": "^2.0.1",
26
26
  "@sitecore-content-sdk/events": "^2.0.1",
27
27
  "astro": "^6.1.1",
@@ -1,7 +1,5 @@
1
1
  ---
2
2
  <% if (prerender === 'SSG') { -%>
3
- export const prerender = true;
4
-
5
3
  import type { GetStaticPaths } from "astro";
6
4
  <% } -%>
7
5
  <% if (prerender === 'SSG') { -%>
@@ -14,9 +12,7 @@ import {
14
12
  } from "@exdst-sitecore-content-sdk/astro/context";
15
13
  import {
16
14
  isDesignLibraryPreviewData,
17
- <% if (prerender === 'SSR') { -%>
18
15
  PreviewCookies
19
- <% } -%>
20
16
  } from "@exdst-sitecore-content-sdk/astro/editing";
21
17
  import { extractPath, removeLanguageFromPath } from "@exdst-sitecore-content-sdk/astro/utils";
22
18
  import client from "@/lib/sitecore-client";
@@ -38,25 +34,24 @@ path = removeLanguageFromPath(path, languages);
38
34
  const site = import.meta.env.SITE_NAME;
39
35
  path = `${SITE_PREFIX}${site}/${path}`;
40
36
  <% } -%>
41
- let page;
42
37
 
38
+ let page;
39
+ let previewData;
43
40
 
44
- <% if (prerender === 'SSR') { -%>
41
+ <% if (prerender === 'SSG') { -%>
42
+ if (!Astro.isPrerendered) {
43
+ <% } -%>
45
44
  const previewDataCookies = Astro.cookies.get(PreviewCookies.PREVIEW_DATA);
46
- const previewData = previewDataCookies ? JSON.parse(previewDataCookies.value) : "";
47
-
48
- const context = {
49
- preview: !!previewData,
50
- previewData: previewData,
51
- };
52
-
53
- <% } else if (prerender === 'SSG') { -%>
54
- const context = {
55
- preview: false,
56
- previewData: undefined
57
- };
45
+ previewData = previewDataCookies ? JSON.parse(previewDataCookies.value) : "";
46
+ <% if (prerender === 'SSG') { -%>
47
+ }
58
48
  <% } -%>
59
49
 
50
+ const context = {
51
+ preview: !!previewData,
52
+ previewData: previewData,
53
+ };
54
+
60
55
  if (context.preview && isDesignLibraryPreviewData(context.previewData)) {
61
56
  page = await client.getDesignLibraryData(context.previewData);
62
57
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exdst-sitecore-content-sdk/create-astro",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "Astro Content SDK initializer",
5
5
  "bin": "./dist/index.js",
6
6
  "scripts": {