feat(Ghost Node): Add support for lexical format (#7488)

This commit is contained in:
MC Naveen 2023-10-23 14:30:38 +05:30 committed by GitHub
parent 450e0cc66a
commit 7b1973c058
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 0 deletions

View file

@ -195,6 +195,14 @@ export class Ghost implements INodeType {
if (contentFormat === 'html') { if (contentFormat === 'html') {
post.html = content; post.html = content;
qs.source = 'html'; qs.source = 'html';
} else if (contentFormat === 'lexical') {
const lexical = validateJSON(content);
if (lexical === undefined) {
throw new NodeOperationError(this.getNode(), 'Content must be a valid JSON', {
itemIndex: i,
});
}
post.lexical = content;
} else { } else {
const mobileDoc = validateJSON(content); const mobileDoc = validateJSON(content);
if (mobileDoc === undefined) { if (mobileDoc === undefined) {
@ -293,6 +301,15 @@ export class Ghost implements INodeType {
post.html = updateFields.content || ''; post.html = updateFields.content || '';
qs.source = 'html'; qs.source = 'html';
delete updateFields.content; delete updateFields.content;
} else if (contentFormat === 'lexical') {
const lexical = validateJSON((updateFields.contentJson as string) || undefined);
if (lexical === undefined) {
throw new NodeOperationError(this.getNode(), 'Content must be a valid JSON', {
itemIndex: i,
});
}
post.lexical = updateFields.contentJson;
delete updateFields.contentJson;
} else { } else {
const mobileDoc = validateJSON((updateFields.contentJson as string) || undefined); const mobileDoc = validateJSON((updateFields.contentJson as string) || undefined);
if (mobileDoc === undefined) { if (mobileDoc === undefined) {

View file

@ -114,6 +114,10 @@ export const postFields: INodeProperties[] = [
name: 'Mobile Doc', name: 'Mobile Doc',
value: 'mobileDoc', value: 'mobileDoc',
}, },
{
name: 'Lexical',
value: 'lexical',
},
], ],
default: 'html', default: 'html',
description: 'The format of the post', description: 'The format of the post',
@ -150,6 +154,22 @@ export const postFields: INodeProperties[] = [
description: description:
'Mobiledoc is the raw JSON format that Ghost uses to store post contents. <a href="https://ghost.org/docs/concepts/posts/#document-storage">Info</a>.', 'Mobiledoc is the raw JSON format that Ghost uses to store post contents. <a href="https://ghost.org/docs/concepts/posts/#document-storage">Info</a>.',
}, },
{
displayName: 'Content (JSON)',
name: 'content',
type: 'json',
displayOptions: {
show: {
source: ['adminApi'],
resource: ['post'],
operation: ['create'],
contentFormat: ['lexical'],
},
},
default: '',
description: 'Lexical is the JSON format returned by the Ghost Default editor',
},
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -395,6 +415,10 @@ export const postFields: INodeProperties[] = [
name: 'Mobile Doc', name: 'Mobile Doc',
value: 'mobiledoc', value: 'mobiledoc',
}, },
{
name: 'Lexical',
value: 'lexical',
},
], ],
default: ['mobiledoc'], default: ['mobiledoc'],
}, },
@ -532,6 +556,10 @@ export const postFields: INodeProperties[] = [
name: 'Plaintext', name: 'Plaintext',
value: 'plaintext', value: 'plaintext',
}, },
{
name: 'Lexical',
value: 'lexical',
},
], ],
default: ['html'], default: ['html'],
description: description:
@ -593,6 +621,10 @@ export const postFields: INodeProperties[] = [
name: 'Mobile Doc', name: 'Mobile Doc',
value: 'mobiledoc', value: 'mobiledoc',
}, },
{
name: 'Lexical',
value: 'lexical',
},
], ],
default: ['mobiledoc'], default: ['mobiledoc'],
}, },
@ -636,6 +668,10 @@ export const postFields: INodeProperties[] = [
name: 'Mobile Doc', name: 'Mobile Doc',
value: 'mobileDoc', value: 'mobileDoc',
}, },
{
name: 'Lexical',
value: 'lexical',
},
], ],
default: 'html', default: 'html',
description: 'The format of the post', description: 'The format of the post',
@ -707,6 +743,18 @@ export const postFields: INodeProperties[] = [
description: description:
'Mobiledoc is the raw JSON format that Ghost uses to store post contents. <a href="https://ghost.org/docs/concepts/posts/#document-storage">Info.</a>.', 'Mobiledoc is the raw JSON format that Ghost uses to store post contents. <a href="https://ghost.org/docs/concepts/posts/#document-storage">Info.</a>.',
}, },
{
displayName: 'Content (JSON)',
name: 'contentJson',
type: 'json',
displayOptions: {
show: {
'/contentFormat': ['lexical'],
},
},
default: '',
description: 'Lexical is the JSON format returned by the Ghost Default editor',
},
{ {
displayName: 'Featured', displayName: 'Featured',
name: 'featured', name: 'featured',