@swell/apps-sdk 1.0.126 → 1.0.127

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.js CHANGED
@@ -19561,14 +19561,36 @@ ${injects.join("\n")}<\/script>`;
19561
19561
  "layouts",
19562
19562
  name
19563
19563
  );
19564
- if (templateConfig) {
19565
- const content = await this.renderThemeTemplate(
19566
- templateConfig.file_path,
19567
- data
19568
- );
19569
- return typeof content === "string" ? content : `<!-- invalid layout: ${name}--> {{ content_for_layout }}`;
19564
+ if (!templateConfig) {
19565
+ throw new Error(`Layout template not found: ${name}`);
19570
19566
  }
19571
- throw new Error(`Layout template not found: ${name}`);
19567
+ let content = await this.renderThemeTemplate(
19568
+ templateConfig.file_path,
19569
+ data
19570
+ );
19571
+ if (typeof content !== "string") {
19572
+ return `<!-- invalid layout: ${name}--> {{ content_for_layout }}`;
19573
+ }
19574
+ if (!this.globals.request.is_editor) {
19575
+ let customCss = this.globals.settings.custom_css || "";
19576
+ if (Array.isArray(customCss)) {
19577
+ customCss = customCss.join("\n").trim();
19578
+ }
19579
+ if (customCss) {
19580
+ let pos = -1;
19581
+ let match = null;
19582
+ const regex = /<\/body\s*?>/gi;
19583
+ while ((match = regex.exec(content)) !== null) {
19584
+ pos = match.index;
19585
+ }
19586
+ if (pos !== -1) {
19587
+ content = `${content.slice(0, pos)}
19588
+ <style>${customCss}</style>
19589
+ ${content.slice(pos)}`;
19590
+ }
19591
+ }
19592
+ }
19593
+ return content;
19572
19594
  }
19573
19595
  async renderPageTemplate(name, data, altTemplateId) {
19574
19596
  let templateConfig = null;