@exdst-sitecore-content-sdk/astro 0.0.1
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/LICENSE.txt +202 -0
- package/README.md +3 -0
- package/package.json +101 -0
- package/src/client/index.ts +12 -0
- package/src/client/sitecore-astro-client.test.ts +271 -0
- package/src/client/sitecore-astro-client.ts +137 -0
- package/src/components/AstroImage.astro +114 -0
- package/src/components/Date.astro +76 -0
- package/src/components/DefaultEmptyFieldEditingComponentImage.astro +24 -0
- package/src/components/DefaultEmptyFieldEditingComponentText.astro +12 -0
- package/src/components/EditingScripts.astro +49 -0
- package/src/components/EmptyRendering.astro +3 -0
- package/src/components/ErrorBoundary.astro +77 -0
- package/src/components/FieldMetadata.astro +30 -0
- package/src/components/File.astro +46 -0
- package/src/components/HiddenRendering.astro +22 -0
- package/src/components/Image.astro +155 -0
- package/src/components/Link.astro +105 -0
- package/src/components/MissingComponent.astro +39 -0
- package/src/components/Placeholder/EmptyPlaceholder.astro +9 -0
- package/src/components/Placeholder/Placeholder.astro +100 -0
- package/src/components/Placeholder/PlaceholderMetadata.astro +102 -0
- package/src/components/Placeholder/PlaceholderUtils.astro +153 -0
- package/src/components/Placeholder/index.ts +5 -0
- package/src/components/Placeholder/models.ts +82 -0
- package/src/components/Placeholder/placeholder-utils.test.ts +162 -0
- package/src/components/Placeholder/placeholder-utils.ts +80 -0
- package/src/components/RenderWrapper.astro +31 -0
- package/src/components/RichText.astro +59 -0
- package/src/components/Text.astro +97 -0
- package/src/components/sharedTypes/index.ts +1 -0
- package/src/components/sharedTypes/props.ts +17 -0
- package/src/config/define-config.test.ts +526 -0
- package/src/config/define-config.ts +99 -0
- package/src/config/index.ts +1 -0
- package/src/config-cli/define-cli-config.test.ts +95 -0
- package/src/config-cli/define-cli-config.ts +50 -0
- package/src/config-cli/index.ts +1 -0
- package/src/context.ts +68 -0
- package/src/editing/constants.ts +8 -0
- package/src/editing/editing-config-middleware.test.ts +166 -0
- package/src/editing/editing-config-middleware.ts +111 -0
- package/src/editing/editing-render-middleware.test.ts +801 -0
- package/src/editing/editing-render-middleware.ts +288 -0
- package/src/editing/index.ts +16 -0
- package/src/editing/render-middleware.test.ts +57 -0
- package/src/editing/render-middleware.ts +51 -0
- package/src/editing/utils.test.ts +852 -0
- package/src/editing/utils.ts +308 -0
- package/src/enhancers/WithEmptyFieldEditingComponent.astro +56 -0
- package/src/enhancers/WithFieldMetadata.astro +31 -0
- package/src/env.d.ts +12 -0
- package/src/index.ts +16 -0
- package/src/middleware/index.ts +24 -0
- package/src/middleware/middleware.test.ts +507 -0
- package/src/middleware/middleware.ts +167 -0
- package/src/middleware/multisite-middleware.test.ts +672 -0
- package/src/middleware/multisite-middleware.ts +147 -0
- package/src/middleware/robots-middleware.test.ts +113 -0
- package/src/middleware/robots-middleware.ts +47 -0
- package/src/middleware/sitemap-middleware.test.ts +152 -0
- package/src/middleware/sitemap-middleware.ts +65 -0
- package/src/services/component-props-service.ts +182 -0
- package/src/sharedTypes/component-props.ts +17 -0
- package/src/site/index.ts +1 -0
- package/src/test-data/components/Bar.astro +0 -0
- package/src/test-data/components/Baz.astro +0 -0
- package/src/test-data/components/Foo.astro +0 -0
- package/src/test-data/components/Hero.variant.astro +0 -0
- package/src/test-data/components/NotComponent.bsx +0 -0
- package/src/test-data/components/Qux.astro +0 -0
- package/src/test-data/components/folded/Folded.astro +0 -0
- package/src/test-data/components/folded/random-file-2.docx +0 -0
- package/src/test-data/components/random-file.txt +0 -0
- package/src/test-data/helpers.ts +46 -0
- package/src/test-data/personalizeData.ts +63 -0
- package/src/tools/generate-map.ts +83 -0
- package/src/tools/index.ts +8 -0
- package/src/tools/templating/components.test.ts +305 -0
- package/src/tools/templating/components.ts +49 -0
- package/src/tools/templating/constants.ts +4 -0
- package/src/tools/templating/default-component.test.ts +31 -0
- package/src/tools/templating/default-component.ts +63 -0
- package/src/tools/templating/index.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/utils.test.ts +48 -0
- package/src/utils/utils.ts +52 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import {
|
|
3
|
+
ScaffoldTemplate,
|
|
4
|
+
ComponentTemplateType,
|
|
5
|
+
} from '@sitecore-content-sdk/core/config';
|
|
6
|
+
import { COMPONENT_FILE_EXTENSION } from './constants';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Astro component boilerplate
|
|
10
|
+
* @param {string} componentName - the component name
|
|
11
|
+
* @returns component generated template
|
|
12
|
+
*/
|
|
13
|
+
const generateTemplate = (componentName: string): string => {
|
|
14
|
+
return `
|
|
15
|
+
---
|
|
16
|
+
import { Field } from "@astro-sitecore-jss/astro-content-sdk";
|
|
17
|
+
|
|
18
|
+
interface Fields {
|
|
19
|
+
Title: Field<string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type ${componentName}Props = {
|
|
23
|
+
params: { [key: string]: string };
|
|
24
|
+
fields: Fields;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const props: ${componentName}Props = Astro.props.route;
|
|
28
|
+
|
|
29
|
+
const id = props.params.RenderingIdentifier;
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
<div class={\`component \${props.params.styles}\`} id={id ? id : undefined}>
|
|
33
|
+
<div class="component-content">
|
|
34
|
+
<p>${componentName} Component</p>
|
|
35
|
+
<Text field={props.fields.Title} />
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
`;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Generates a list of next steps when scaffolding a component.
|
|
43
|
+
* @param {string} componentOutputPath - The file path where the component file is generated.
|
|
44
|
+
* @returns {string[]} An array of strings, each representing a next step.
|
|
45
|
+
*/
|
|
46
|
+
const getNextSteps = (componentOutputPath: string): string[] => {
|
|
47
|
+
const nextSteps = [];
|
|
48
|
+
|
|
49
|
+
if (componentOutputPath) {
|
|
50
|
+
nextSteps.push(
|
|
51
|
+
`* Implement the Astro component in ${chalk.green(componentOutputPath)}`
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return nextSteps;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const defaultTemplate: ScaffoldTemplate = {
|
|
59
|
+
name: ComponentTemplateType.DEFAULT,
|
|
60
|
+
fileExtension: COMPONENT_FILE_EXTENSION,
|
|
61
|
+
generateTemplate,
|
|
62
|
+
getNextSteps,
|
|
63
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getEditingSecret, extractPath, removeLanguageFromPath, addClassName } from './utils';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-unused-expressions */
|
|
2
|
+
import { expect, use } from 'chai';
|
|
3
|
+
import spies from 'chai-spies';
|
|
4
|
+
import { addClassName, getEditingSecret } from './utils';
|
|
5
|
+
|
|
6
|
+
use(spies);
|
|
7
|
+
|
|
8
|
+
describe('utils', () => {
|
|
9
|
+
describe('getEditingSecret', () => {
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
delete process.env.SITECORE_EDITING_SECRET;
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should throw if env variable missing', () => {
|
|
15
|
+
expect(() => getEditingSecret()).to.throw();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should return env variable', () => {
|
|
19
|
+
const secret = '1234abcd';
|
|
20
|
+
process.env.SITECORE_EDITING_SECRET = secret;
|
|
21
|
+
const result = getEditingSecret();
|
|
22
|
+
expect(result).to.equal(secret);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('addClassName', () => {
|
|
28
|
+
it('should add class attribute value to className', () => {
|
|
29
|
+
const modifiableAttrs = {
|
|
30
|
+
className: 'first-class',
|
|
31
|
+
class: 'second-class',
|
|
32
|
+
};
|
|
33
|
+
addClassName(modifiableAttrs);
|
|
34
|
+
expect(modifiableAttrs).to.deep.equal({
|
|
35
|
+
className: 'first-class second-class',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should convert class attribute value to className when className is absent', () => {
|
|
39
|
+
const modifiableAttrs = {
|
|
40
|
+
class: 'second-class',
|
|
41
|
+
};
|
|
42
|
+
addClassName(modifiableAttrs);
|
|
43
|
+
expect(modifiableAttrs).to.deep.equal({
|
|
44
|
+
className: 'second-class',
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const getEditingSecret = (): string => {
|
|
2
|
+
const secret = process.env.SITECORE_EDITING_SECRET;
|
|
3
|
+
|
|
4
|
+
if (!secret || secret.length === 0) {
|
|
5
|
+
throw new Error('The SITECORE_EDITING_SECRET environment variable is missing or invalid.');
|
|
6
|
+
}
|
|
7
|
+
return secret.toLowerCase();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const extractPath = (params: Record<string, string | undefined>) => {
|
|
11
|
+
return params === undefined
|
|
12
|
+
? '/'
|
|
13
|
+
: Array.isArray(params.path)
|
|
14
|
+
? params.path.join('/')
|
|
15
|
+
: params.path ?? '/';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const removeLanguageFromPath = (path: string, languages: string[]): string => {
|
|
19
|
+
const segments = path.split('/');
|
|
20
|
+
|
|
21
|
+
const langs = languages.map((lang) => lang.toLowerCase());
|
|
22
|
+
|
|
23
|
+
if (segments.length > 0 && langs.includes(segments[0].toLowerCase())) {
|
|
24
|
+
// E.g. /en/About
|
|
25
|
+
segments.splice(0, 1);
|
|
26
|
+
} else if (segments.length > 1 && langs.includes(segments[1].toLowerCase())) {
|
|
27
|
+
// if path contains _site_ segment before language
|
|
28
|
+
// E.g. /_site_Basic/en/About
|
|
29
|
+
segments.splice(1, 1);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return segments.join('/') || '/';
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* "class" property will be transformed into or appended to "className" instead.
|
|
37
|
+
* @param {string} otherAttrs all other props included on the image component
|
|
38
|
+
* @returns {void}
|
|
39
|
+
*/
|
|
40
|
+
export const addClassName = (otherAttrs: { [key: string]: unknown }): void => {
|
|
41
|
+
if (otherAttrs.class) {
|
|
42
|
+
// if any classes are defined properly already
|
|
43
|
+
if (otherAttrs.className) {
|
|
44
|
+
let className: string = otherAttrs.className as string;
|
|
45
|
+
className += ` ${otherAttrs.class}`;
|
|
46
|
+
otherAttrs.className = className;
|
|
47
|
+
} else {
|
|
48
|
+
otherAttrs.className = otherAttrs.class;
|
|
49
|
+
}
|
|
50
|
+
delete otherAttrs.class;
|
|
51
|
+
}
|
|
52
|
+
};
|