Skip to content

Commit 1fdff7e

Browse files
authored
Try to prevent undefined placeholders during template selection (#437)
1 parent 04cb394 commit 1fdff7e

File tree

1 file changed

+9
-3
lines changed
  • services/backend-api/client/src/features/templates/constants

1 file changed

+9
-3
lines changed

services/backend-api/client/src/features/templates/constants/templates.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ export const DEFAULT_TEMPLATE: Template = {
3636
}
3737

3838
if (!content) {
39-
content = `{{${titleField}}}`;
39+
const descriptionField = fields?.description[0]?.field;
40+
const fallbackField = titleField ?? descriptionField ?? "title||New untitled article";
41+
42+
content = `{{${fallbackField}}}`;
4043
}
4144

4245
return {
@@ -45,6 +48,7 @@ export const DEFAULT_TEMPLATE: Template = {
4548
name: "Simple Text Template",
4649
stripImages: true,
4750
ignoreNewLines: true,
51+
enablePlaceholderFallback: true,
4852
children: [
4953
{
5054
type: ComponentType.LegacyText,
@@ -72,14 +76,15 @@ export const RICH_EMBED_TEMPLATE: Template = {
7276

7377
const hasImage = !!imageField;
7478
const hasTitle = !!titleField;
79+
const safeTitleField = titleField ?? "title||New untitled article";
7580

7681
const titleComponent = {
7782
type: ComponentType.V2TextDisplay as const,
7883
id: "rich-embed-title",
7984
name: "Title",
8085
content: linkField
81-
? `### [{{${titleField}}}]({{${linkField}}})${authorField ? "\n**{{author}}**" : ""}`
82-
: `### {{${titleField}}}${authorField ? "\n**{{author}}**" : ""}`,
86+
? `### [{{${safeTitleField}}}]({{${linkField}}})${authorField ? "\n**{{author}}**" : ""}`
87+
: `### {{${safeTitleField}}}${authorField ? "\n**{{author}}**" : ""}`,
8388
};
8489

8590
const headerComponent = hasImage
@@ -109,6 +114,7 @@ export const RICH_EMBED_TEMPLATE: Template = {
109114
],
110115
stripImages: true,
111116
ignoreNewLines: true,
117+
enablePlaceholderFallback: true,
112118
children: [
113119
{
114120
type: ComponentType.V2Container,

0 commit comments

Comments
 (0)