@exdst-sitecore-content-sdk/create-astro 0.0.7 → 0.0.22
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/README.md +3 -0
- package/dist/bin.js +119 -0
- package/dist/common/base/Initializer.js +2 -0
- package/dist/common/base/args.js +2 -0
- package/dist/common/base/prompts.js +7 -0
- package/dist/common/index.js +18 -0
- package/dist/common/processes/install.js +55 -0
- package/dist/common/processes/next.js +112 -0
- package/dist/common/processes/transform.js +116 -0
- package/dist/common/utils/cmd.js +53 -0
- package/dist/common/utils/helpers.js +80 -0
- package/dist/index.js +6 -0
- package/dist/initialize.js +71 -0
- package/dist/initializers/astro/args.js +2 -0
- package/dist/initializers/astro/index.js +30 -0
- package/dist/initializers/astro/prompts.js +26 -0
- package/dist/templates/astro/.env.container.example +27 -0
- package/dist/templates/astro/.env.remote.example +39 -0
- package/dist/templates/astro/.prettierignore +2 -0
- package/dist/templates/astro/.prettierrc +17 -0
- package/dist/templates/astro/LICENSE.txt +202 -0
- package/dist/templates/astro/README.MD +1 -0
- package/dist/templates/astro/astro.config.mjs +46 -0
- package/dist/templates/astro/eslint.config.mjs +21 -0
- package/dist/templates/astro/package.json +45 -0
- package/dist/templates/astro/public/favicon.ico +0 -0
- package/dist/templates/astro/public/favicon.svg +9 -0
- package/dist/templates/astro/sitecore.cli.config.ts +15 -0
- package/dist/templates/astro/sitecore.config.ts +6 -0
- package/dist/templates/astro/sitecore.config.ts.example +31 -0
- package/dist/templates/astro/src/Bootstrap.astro +77 -0
- package/dist/templates/astro/src/Layout.astro +57 -0
- package/dist/templates/astro/src/NotFound.astro +21 -0
- package/dist/templates/astro/src/Scripts.astro +9 -0
- package/dist/templates/astro/src/components/content-sdk/CdpPageView.astro +73 -0
- package/dist/templates/astro/src/components/content-sdk/SitecoreStyles.astro +20 -0
- package/dist/templates/astro/src/env.d.ts +10 -0
- package/dist/templates/astro/src/lib/component-props/index.ts +23 -0
- package/dist/templates/astro/src/lib/languages.ts +3 -0
- package/dist/templates/astro/src/lib/sitecore-client.ts +8 -0
- package/dist/templates/astro/src/middleware/index.ts +50 -0
- package/dist/templates/astro/src/pages/-/[...media].ts +20 -0
- package/dist/templates/astro/src/pages/404.astro +5 -0
- package/dist/templates/astro/src/pages/[...path].astro +118 -0
- package/dist/templates/astro/src/pages/api/editing/config.ts +17 -0
- package/dist/templates/astro/src/pages/api/editing/render.ts +19 -0
- package/dist/templates/astro/src/pages/robots.txt.ts +18 -0
- package/dist/templates/astro/src/pages/sitemap-[id].xml.ts +17 -0
- package/dist/templates/astro/src/pages/sitemap.xml.ts +17 -0
- package/dist/templates/astro/tsconfig.json +14 -0
- package/package.json +58 -9
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { type Field, type Page } from '@exdst-sitecore-content-sdk/astro';
|
|
3
|
+
import Placeholder from '@exdst-sitecore-content-sdk/astro/components/Placeholder/Placeholder.astro';
|
|
4
|
+
import Bootstrap from '@/Bootstrap.astro';
|
|
5
|
+
import Scripts from '@/Scripts.astro';
|
|
6
|
+
import SitecoreStyles from '@/components/content-sdk/SitecoreStyles.astro';
|
|
7
|
+
|
|
8
|
+
interface LayoutProps {
|
|
9
|
+
page: Page;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface RouteFields {
|
|
13
|
+
[key: string]: unknown;
|
|
14
|
+
Title?: Field;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const { page } = Astro.props as LayoutProps;
|
|
18
|
+
const { layout, mode } = page;
|
|
19
|
+
const { route, context } = layout.sitecore;
|
|
20
|
+
const fields = route?.fields as RouteFields;
|
|
21
|
+
const mainClassPageEditing = mode.isEditing ? 'editing-mode' : 'prod-mode';
|
|
22
|
+
|
|
23
|
+
const theme = context.theme as string;
|
|
24
|
+
const language = context.language || 'en';
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
<!doctype html>
|
|
28
|
+
<html lang=`${language}`>
|
|
29
|
+
<head>
|
|
30
|
+
<meta charset="utf-8" />
|
|
31
|
+
<meta name="viewport" content="width=device-width" />
|
|
32
|
+
<title>{fields?.Title?.value?.toString() || 'Page'}</title>
|
|
33
|
+
<link rel="icon" href={`${Astro.url.origin}/favicon.ico`} />
|
|
34
|
+
<SitecoreStyles slot="head" layoutData={layout} />
|
|
35
|
+
</head>
|
|
36
|
+
<body>
|
|
37
|
+
<Bootstrap page={page} />
|
|
38
|
+
<Scripts />
|
|
39
|
+
<div class={`${mainClassPageEditing} site-${theme?.toLowerCase()} body`}>
|
|
40
|
+
<header>
|
|
41
|
+
<div id="header">
|
|
42
|
+
{route && <Placeholder name="headless-header" rendering={route} />}
|
|
43
|
+
</div>
|
|
44
|
+
</header>
|
|
45
|
+
<main>
|
|
46
|
+
<div id="content">
|
|
47
|
+
{route && <Placeholder name="headless-main" rendering={route} />}
|
|
48
|
+
</div>
|
|
49
|
+
</main>
|
|
50
|
+
<footer>
|
|
51
|
+
<div id="footer">
|
|
52
|
+
{route && <Placeholder name="headless-footer" rendering={route} />}
|
|
53
|
+
</div>
|
|
54
|
+
</footer>
|
|
55
|
+
</div>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
<!doctype html>
|
|
6
|
+
<html lang="en">
|
|
7
|
+
<head>
|
|
8
|
+
<meta charset="UTF-8" />
|
|
9
|
+
<meta name="viewport" content="width=device-width" />
|
|
10
|
+
<meta name="generator" content={Astro.generator} />
|
|
11
|
+
<title>404: NotFound</title>
|
|
12
|
+
<link rel="icon" href="/favicon.ico" />
|
|
13
|
+
</head>
|
|
14
|
+
<body>
|
|
15
|
+
<div style="padding:10px">
|
|
16
|
+
<h1>Page not found</h1>
|
|
17
|
+
<p>This page does not exist.</p>
|
|
18
|
+
<a href="/">Go to the Home page</a>
|
|
19
|
+
</div>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* This is the CDP page view component.
|
|
4
|
+
* See Sitecore Content SDK documentation for details.
|
|
5
|
+
* https://www.npmjs.com/package/@sitecore-content-sdk/events
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { CdpHelper } from '@exdst-sitecore-content-sdk/astro';
|
|
9
|
+
import { useSitecore } from '@exdst-sitecore-content-sdk/astro/context';
|
|
10
|
+
import config from 'sitecore.config';
|
|
11
|
+
|
|
12
|
+
const {
|
|
13
|
+
page: { layout, mode },
|
|
14
|
+
} = useSitecore();
|
|
15
|
+
const { route, context } = layout.sitecore;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Determines if the page view events should be turned off.
|
|
19
|
+
* IMPORTANT: You should implement based on your cookie consent management solution of choice.
|
|
20
|
+
* By default it is disabled in development mode
|
|
21
|
+
*/
|
|
22
|
+
const disabled = () => {
|
|
23
|
+
return process.env.NODE_ENV === 'development';
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// Do not create events in editing or preview mode or if missing route data
|
|
27
|
+
if (!mode.isNormal || !route?.itemId) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Do not create events if disabled (e.g. we don't have consent)
|
|
32
|
+
if (disabled()) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const language = route.itemLanguage || config.defaultLanguage;
|
|
37
|
+
const scope = config.personalize?.scope;
|
|
38
|
+
|
|
39
|
+
const pageVariantId = CdpHelper.getPageVariantId(
|
|
40
|
+
route.itemId,
|
|
41
|
+
language,
|
|
42
|
+
context.variantId as string,
|
|
43
|
+
scope
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const pageViewData = JSON.stringify({
|
|
47
|
+
channel: 'WEB',
|
|
48
|
+
currency: 'USD',
|
|
49
|
+
page: route.name,
|
|
50
|
+
pageVariantId,
|
|
51
|
+
language,
|
|
52
|
+
});
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
<>
|
|
56
|
+
<astro-cdp-page-view data-page-view-data={pageViewData}></astro-cdp-page-view>
|
|
57
|
+
|
|
58
|
+
<script>
|
|
59
|
+
import { pageView } from '@sitecore-content-sdk/events';
|
|
60
|
+
|
|
61
|
+
class CdpPageView extends HTMLElement {
|
|
62
|
+
async connectedCallback() {
|
|
63
|
+
const pageViewData = this.dataset.pageViewData;
|
|
64
|
+
|
|
65
|
+
if (pageViewData !== undefined) {
|
|
66
|
+
// there can be cases where Events are not initialized which are expected to reject
|
|
67
|
+
pageView(JSON.parse(pageViewData)).catch((e) => console.debug(e));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
customElements.define('astro-cdp-page-view', CdpPageView);
|
|
72
|
+
</script>
|
|
73
|
+
</>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
import client from '@/lib/sitecore-client';
|
|
3
|
+
import type { LayoutServiceData, HTMLLink } from '@exdst-sitecore-content-sdk/astro';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component to render `<link>` elements for Sitecore styles
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const layoutData = Astro.props.layoutData as LayoutServiceData;
|
|
10
|
+
const { enableStyles, enableThemes } = Astro.props;
|
|
11
|
+
|
|
12
|
+
const headLinks = client.getHeadLinks(layoutData, {
|
|
13
|
+
enableStyles,
|
|
14
|
+
enableThemes,
|
|
15
|
+
});
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<>
|
|
19
|
+
{headLinks.map(({ rel, href }: HTMLLink) => <link rel={rel} href={href} />)}
|
|
20
|
+
</>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ComponentParams, type ComponentRendering } from '@exdst-sitecore-content-sdk/astro';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared component props
|
|
5
|
+
*/
|
|
6
|
+
export type ComponentProps = {
|
|
7
|
+
rendering: ComponentRendering;
|
|
8
|
+
params: ComponentParams & {
|
|
9
|
+
/**
|
|
10
|
+
* The identifier for the rendering
|
|
11
|
+
*/
|
|
12
|
+
RenderingIdentifier?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The styles for the rendering
|
|
15
|
+
* This value is calculated by the Placeholder component
|
|
16
|
+
*/
|
|
17
|
+
styles?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The enabled placeholders for the rendering
|
|
20
|
+
*/
|
|
21
|
+
EnabledPlaceholders?: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineMiddleware, sequence } from 'astro/middleware';
|
|
2
|
+
import { MultisiteMiddleware } from '@exdst-sitecore-content-sdk/astro/middleware';
|
|
3
|
+
import sites from '.sitecore/sites.json';
|
|
4
|
+
import scConfig from 'sitecore.config';
|
|
5
|
+
|
|
6
|
+
const requestFilterMiddleware = defineMiddleware(async (context, next) => {
|
|
7
|
+
<% if (prerender === 'SSG') { -%>
|
|
8
|
+
// Skip the multisite middleware for SSG
|
|
9
|
+
if (context.isPrerendered) {
|
|
10
|
+
context.locals.skipMiddleware = true;
|
|
11
|
+
return next();
|
|
12
|
+
}
|
|
13
|
+
<% } -%>
|
|
14
|
+
/*
|
|
15
|
+
* Match all paths except for:
|
|
16
|
+
* 1. /api routes
|
|
17
|
+
* 2. /sitecore/api (Sitecore API routes)
|
|
18
|
+
* 3. /- (Sitecore media)
|
|
19
|
+
* 4. /healthz (Health check)
|
|
20
|
+
* 5. all root files inside /public
|
|
21
|
+
* 6. Astro files
|
|
22
|
+
*/
|
|
23
|
+
const matcher = new RegExp(
|
|
24
|
+
'(api/|healthz|sitecore/api/|-/|_astro|_image|favicon.ico|sc_logo.svg|_site_)'
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const requestUrl = new URL(context.request.url.toLowerCase());
|
|
28
|
+
if (matcher.test(requestUrl.pathname)) {
|
|
29
|
+
context.locals.skipMiddleware = true;
|
|
30
|
+
return next();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return next();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Instantiate middlewares - they will use Edge config if available, otherwise fall back to local config
|
|
37
|
+
const multisite = new MultisiteMiddleware({
|
|
38
|
+
/**
|
|
39
|
+
* List of sites for site resolver to work with
|
|
40
|
+
*/
|
|
41
|
+
sites,
|
|
42
|
+
...scConfig.api.edge,
|
|
43
|
+
...scConfig.multisite,
|
|
44
|
+
// This function determines if the middleware should be turned off on per-request basis.
|
|
45
|
+
// Certain paths are ignored by default (e.g. files and Next.js API routes), but you may wish to disable more.
|
|
46
|
+
// This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
47
|
+
skip: () => false,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const onRequest = sequence(requestFilterMiddleware, multisite.handle);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { APIRoute } from 'astro';
|
|
2
|
+
import config from 'sitecore.config';
|
|
3
|
+
|
|
4
|
+
// Proxy media requests to the Sitecore host without a client-side redirect.
|
|
5
|
+
// When IncludeServerURLinMediaURLs is disabled, Sitecore returns relative media URLs
|
|
6
|
+
// (for example `/-/media/...`). We forward those requests to the Sitecore host so media still loads correctly.
|
|
7
|
+
// Astro does not provide a rewrite rules config, so we handle this with a route-level proxy.
|
|
8
|
+
export const GET: APIRoute = async ({ url }) => {
|
|
9
|
+
const target = new URL(
|
|
10
|
+
`${config.api.local.apiHost || process.env.PUBLIC_SITECORE_API_HOST || ''}${url.pathname}${url.search}`
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const upstream = await fetch(new Request(target.toString()));
|
|
14
|
+
|
|
15
|
+
return new Response(upstream.body, {
|
|
16
|
+
status: upstream.status,
|
|
17
|
+
statusText: upstream.statusText,
|
|
18
|
+
headers: upstream.headers,
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
<% if (prerender === 'SSG') { -%>
|
|
3
|
+
export const prerender = true;
|
|
4
|
+
|
|
5
|
+
import type { GetStaticPaths } from "astro";
|
|
6
|
+
<% } -%>
|
|
7
|
+
<% if (prerender === 'SSG') { -%>
|
|
8
|
+
import { type StaticPath } from "@exdst-sitecore-content-sdk/astro";
|
|
9
|
+
import { SITE_PREFIX } from "@exdst-sitecore-content-sdk/astro/site";
|
|
10
|
+
<% } -%>
|
|
11
|
+
import {
|
|
12
|
+
updateSitecoreContext,
|
|
13
|
+
updateSitecoreDictionary,
|
|
14
|
+
} from "@exdst-sitecore-content-sdk/astro/context";
|
|
15
|
+
import {
|
|
16
|
+
isDesignLibraryPreviewData,
|
|
17
|
+
<% if (prerender === 'SSR') { -%>
|
|
18
|
+
PreviewCookies
|
|
19
|
+
<% } -%>
|
|
20
|
+
} from "@exdst-sitecore-content-sdk/astro/editing";
|
|
21
|
+
import { extractPath, removeLanguageFromPath } from "@exdst-sitecore-content-sdk/astro/utils";
|
|
22
|
+
import client from "@/lib/sitecore-client";
|
|
23
|
+
import Layout from "@/Layout.astro";
|
|
24
|
+
import components from ".sitecore/component-map";
|
|
25
|
+
import config from "sitecore.config";
|
|
26
|
+
<% if (prerender === 'SSG') { -%>
|
|
27
|
+
import sites from ".sitecore/sites.json";
|
|
28
|
+
<% } -%>
|
|
29
|
+
import languages from "lib/languages";
|
|
30
|
+
import NotFound from "@/NotFound.astro";
|
|
31
|
+
|
|
32
|
+
let path = extractPath(Astro.params);
|
|
33
|
+
|
|
34
|
+
// Remove language segment from path
|
|
35
|
+
path = removeLanguageFromPath(path, languages);
|
|
36
|
+
|
|
37
|
+
<% if (prerender === 'SSG') { -%>
|
|
38
|
+
const site = import.meta.env.SITE_NAME;
|
|
39
|
+
path = `${SITE_PREFIX}${site}/${path}`;
|
|
40
|
+
<% } -%>
|
|
41
|
+
let page;
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
<% if (prerender === 'SSR') { -%>
|
|
45
|
+
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
|
+
};
|
|
58
|
+
<% } -%>
|
|
59
|
+
|
|
60
|
+
if (context.preview && isDesignLibraryPreviewData(context.previewData)) {
|
|
61
|
+
page = await client.getDesignLibraryData(context.previewData);
|
|
62
|
+
} else {
|
|
63
|
+
page = context.preview
|
|
64
|
+
? await client.getPreview(context.previewData)
|
|
65
|
+
: await client.getPage(path, {
|
|
66
|
+
locale: Astro.props.locale || Astro.currentLocale,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (page) {
|
|
71
|
+
const dictionary = await client.getDictionary({
|
|
72
|
+
site: page.siteName,
|
|
73
|
+
locale: page.locale,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
updateSitecoreContext({
|
|
77
|
+
page,
|
|
78
|
+
api: config.api,
|
|
79
|
+
componentMap: components,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
updateSitecoreDictionary({
|
|
83
|
+
dictionary,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
<% if (prerender === 'SSG') { -%>
|
|
88
|
+
// This function gets called at build and export time to determine
|
|
89
|
+
// pages for SSG ("paths", as tokenized array).
|
|
90
|
+
export const getStaticPaths = (async () => {
|
|
91
|
+
let paths: StaticPath[] = [];
|
|
92
|
+
|
|
93
|
+
if (process.env.NODE_ENV !== "development" && config.generateStaticPaths) {
|
|
94
|
+
try {
|
|
95
|
+
const siteName = import.meta.env.SITE_NAME;
|
|
96
|
+
const site = sites.find((s) => s.name === siteName) || sites[0];
|
|
97
|
+
paths = await client.getPagePaths([site.name], languages);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.log("Error occurred while fetching static paths");
|
|
100
|
+
console.log(error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return paths.map((p) => {
|
|
105
|
+
const path = p.params.path.join("/");
|
|
106
|
+
return {
|
|
107
|
+
params: { path: `${p.locale}/${path}` },
|
|
108
|
+
props: { locale: p.locale },
|
|
109
|
+
};
|
|
110
|
+
});
|
|
111
|
+
}) satisfies GetStaticPaths;
|
|
112
|
+
<% } -%>
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
<>
|
|
116
|
+
{page && <Layout page={page} />}
|
|
117
|
+
{!page && <NotFound />}
|
|
118
|
+
</>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { APIRoute, APIContext } from 'astro';
|
|
2
|
+
import { EditingConfigMiddleware } from '@exdst-sitecore-content-sdk/astro/editing';
|
|
3
|
+
import components from '.sitecore/component-map';
|
|
4
|
+
import metadata from '.sitecore/metadata.json';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This API route is used by Sitecore Editor in XM Cloud
|
|
8
|
+
* to determine feature compatibility and configuration.
|
|
9
|
+
*/
|
|
10
|
+
export const ALL: APIRoute = async ({ request }: APIContext) => {
|
|
11
|
+
const handler = new EditingConfigMiddleware({
|
|
12
|
+
components,
|
|
13
|
+
metadata,
|
|
14
|
+
}).getHandler();
|
|
15
|
+
|
|
16
|
+
return await handler(request);
|
|
17
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { APIRoute, APIContext } from 'astro';
|
|
2
|
+
import { EditingRenderMiddleware } from '@exdst-sitecore-content-sdk/astro/editing';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This API route is used to handle GET requests from Sitecore Editor.
|
|
6
|
+
* This route should match the `serverSideRenderingEngineEndpointUrl` in your Sitecore configuration,
|
|
7
|
+
* which is set to "http://<rendering_host>/api/editing/render" by default (see the settings item under /sitecore/content/<your/site/path>/Settings/Site Grouping).
|
|
8
|
+
*
|
|
9
|
+
* The `EditingRenderMiddleware` will
|
|
10
|
+
* 1. Extract data about the route we need to render from the Sitecore Editor GET request
|
|
11
|
+
* 2. Enable Preview Mode, passing the route data as preview data
|
|
12
|
+
* 3. Redirect the request to the route, passing along the Preview Mode cookies.
|
|
13
|
+
* This allows retrieval of the editing data in preview context (via an `EditingDataService`) - see `SitecorePagePropsFactory`
|
|
14
|
+
* 4. The redirected request will render the page with editing markup in place
|
|
15
|
+
*/
|
|
16
|
+
export const ALL: APIRoute = async ({ request }: APIContext) => {
|
|
17
|
+
const handler = new EditingRenderMiddleware().getHandler();
|
|
18
|
+
return await handler(request);
|
|
19
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { APIContext, APIRoute } from 'astro';
|
|
2
|
+
import { RobotsMiddleware } from '@exdst-sitecore-content-sdk/astro/middleware';
|
|
3
|
+
import scClient from 'lib/sitecore-client';
|
|
4
|
+
import sites from '.sitecore/sites.json';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* API route for serving robots.txt
|
|
8
|
+
*
|
|
9
|
+
* This API route generates and returns the robots.txt content dynamically
|
|
10
|
+
* based on the resolved site name. It is commonly
|
|
11
|
+
* used by search engine crawlers to determine crawl and indexing rules.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const GET: APIRoute = async ({ request }: APIContext) => {
|
|
15
|
+
// Wire up the RobotsMiddleware handler
|
|
16
|
+
const handler = new RobotsMiddleware(scClient, sites).getHandler();
|
|
17
|
+
return await handler(request);
|
|
18
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { APIContext, APIRoute } from 'astro';
|
|
2
|
+
import { SitemapMiddleware } from '@exdst-sitecore-content-sdk/astro/middleware';
|
|
3
|
+
import scClient from 'lib/sitecore-client';
|
|
4
|
+
import sites from '.sitecore/sites.json';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* API route for generating sitemap-{id}.xml
|
|
8
|
+
*
|
|
9
|
+
* This API route dynamically generates and serves the sitemap XML for your site.
|
|
10
|
+
* The sitemap configuration can be managed within XM Cloud.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const GET: APIRoute = async ({ request }: APIContext) => {
|
|
14
|
+
// Wire up the SitemapMiddleware handler
|
|
15
|
+
const handler = new SitemapMiddleware(scClient, sites).getHandler();
|
|
16
|
+
return await handler(request);
|
|
17
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { APIContext, APIRoute } from 'astro';
|
|
2
|
+
import { SitemapMiddleware } from '@exdst-sitecore-content-sdk/astro/middleware';
|
|
3
|
+
import scClient from 'lib/sitecore-client';
|
|
4
|
+
import sites from '.sitecore/sites.json';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* API route for generating sitemap.xml
|
|
8
|
+
*
|
|
9
|
+
* This API route dynamically generates and serves the sitemap XML for your site.
|
|
10
|
+
* The sitemap configuration can be managed within XM Cloud.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const GET: APIRoute = async ({ request }: APIContext) => {
|
|
14
|
+
// Wire up the SitemapMiddleware handler
|
|
15
|
+
const handler = new SitemapMiddleware(scClient, sites).getHandler();
|
|
16
|
+
return await handler(request);
|
|
17
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "astro/tsconfigs/strict",
|
|
3
|
+
"include": [".astro/types.d.ts", "**/*"],
|
|
4
|
+
"exclude": ["dist"],
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@/*": ["src/*"],
|
|
9
|
+
"components/*": ["src/components/*"],
|
|
10
|
+
"lib/*": ["src/lib/*"]
|
|
11
|
+
},
|
|
12
|
+
"strictFunctionTypes": false
|
|
13
|
+
}
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exdst-sitecore-content-sdk/create-astro",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.22",
|
|
4
|
+
"description": "Astro Content SDK initializer",
|
|
5
|
+
"bin": "./dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "npm run clean && tsc && ts-node ./scripts/build-templates.ts",
|
|
8
|
+
"clean": "del-cli dist types",
|
|
9
|
+
"lint": "eslint \"./src/**/*.ts\"",
|
|
10
|
+
"watch": "ts-node ./scripts/watch-templates.ts",
|
|
11
|
+
"test": "mocha --require ts-node/register \"./src/**/*.test.ts\"",
|
|
12
|
+
"coverage": "nyc npm test"
|
|
13
|
+
},
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=24"
|
|
16
|
+
},
|
|
6
17
|
"author": {
|
|
7
18
|
"name": "EXDST",
|
|
8
19
|
"url": "https://exdst.com"
|
|
@@ -11,15 +22,53 @@
|
|
|
11
22
|
"type": "git",
|
|
12
23
|
"url": "https://github.com/exdst/jss-astro-public"
|
|
13
24
|
},
|
|
25
|
+
"license": "Apache-2.0",
|
|
14
26
|
"bugs": {
|
|
15
27
|
"url": "https://github.com/exdst/jss-astro-public/issues"
|
|
16
28
|
},
|
|
17
|
-
"
|
|
18
|
-
"
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"chalk": "^4.1.2",
|
|
34
|
+
"cross-spawn": "^7.0.6",
|
|
35
|
+
"ejs": "^3.1.10",
|
|
36
|
+
"fs-extra": "^11.3.0",
|
|
37
|
+
"glob": "^11.0.2",
|
|
38
|
+
"inquirer": "^8.2.4",
|
|
39
|
+
"minimist": "^1.2.8"
|
|
19
40
|
},
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@stylistic/eslint-plugin": "^5.2.2",
|
|
43
|
+
"@types/chai": "^5.2.2",
|
|
44
|
+
"@types/cross-spawn": "^6.0.6",
|
|
45
|
+
"@types/ejs": "^3.1.5",
|
|
46
|
+
"@types/fs-extra": "^11.0.4",
|
|
47
|
+
"@types/glob": "^8.1.0",
|
|
48
|
+
"@types/inquirer": "^9.0.8",
|
|
49
|
+
"@types/minimist": "^1.2.5",
|
|
50
|
+
"@types/mocha": "^10.0.10",
|
|
51
|
+
"@types/node": "^24.10.4",
|
|
52
|
+
"@types/proxyquire": "^1.3.31",
|
|
53
|
+
"@types/sinon": "17.0.4",
|
|
54
|
+
"@types/sinon-chai": "^4.0.0",
|
|
55
|
+
"@typescript-eslint/eslint-plugin": "8.39.0",
|
|
56
|
+
"@typescript-eslint/parser": "8.39.0",
|
|
57
|
+
"chai": "^4.4.1",
|
|
58
|
+
"chokidar": "^4.0.3",
|
|
59
|
+
"del-cli": "^6.0.0",
|
|
60
|
+
"eslint": "^9.32.0",
|
|
61
|
+
"eslint-config-prettier": "^10.1.8",
|
|
62
|
+
"eslint-plugin-import": "2.32.0",
|
|
63
|
+
"eslint-plugin-jsdoc": "52.0.3",
|
|
64
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
65
|
+
"mocha": "^11.2.2",
|
|
66
|
+
"nyc": "^17.1.0",
|
|
67
|
+
"prettier": "^2.8.0",
|
|
68
|
+
"proxyquire": "^2.1.3",
|
|
69
|
+
"sinon": "^20.0.0",
|
|
70
|
+
"sinon-chai": "^3.7.0",
|
|
71
|
+
"ts-node": "^10.9.2",
|
|
72
|
+
"typescript": "~5.8.3"
|
|
24
73
|
}
|
|
25
74
|
}
|