mirror of
https://github.com/jlengrand/ghost-mcp.git
synced 2026-03-10 08:21:19 +00:00
🚸 Make post status draft by default
This commit is contained in:
@@ -803,17 +803,20 @@ async def create_post(post_data: dict, ctx: Context = None) -> str:
|
|||||||
"""Create a new blog post.
|
"""Create a new blog post.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
post_data: Dictionary containing post data with at least one of these required fields:
|
post_data: Dictionary containing post data with required fields:
|
||||||
- title: The title of the post
|
- title: The title of the post
|
||||||
- lexical: The lexical content as a JSON string
|
- lexical: The lexical content as a JSON string
|
||||||
- status: Post status ('draft' or 'published', default: 'draft')
|
Additional optional fields:
|
||||||
Additional fields like tags, authors, etc. can also be included.
|
- status: Post status ('draft' or 'published', defaults to 'draft')
|
||||||
|
- tags: List of tags
|
||||||
|
- authors: List of authors
|
||||||
|
- feature_image: URL of featured image
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
{
|
{
|
||||||
"title": "My test post",
|
"title": "My test post",
|
||||||
"lexical": "{\"root\":{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"Hello World\",\"type\":\"text\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}",
|
"lexical": "{\"root\":{\"children\":[{\"children\":[{\"detail\":0,\"format\":0,\"mode\":\"normal\",\"style\":\"\",\"text\":\"Hello World\",\"type\":\"text\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":\"ltr\",\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}"
|
||||||
"status": "published"
|
"status": "draft",
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx: Optional context for logging
|
ctx: Optional context for logging
|
||||||
@@ -840,18 +843,29 @@ async def create_post(post_data: dict, ctx: Context = None) -> str:
|
|||||||
return error_msg
|
return error_msg
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Create a copy of post_data to avoid modifying the original
|
||||||
|
post_payload = post_data.copy()
|
||||||
|
|
||||||
|
# Ensure status is 'draft' by default
|
||||||
|
if 'status' not in post_payload:
|
||||||
|
post_payload['status'] = 'draft'
|
||||||
|
if ctx:
|
||||||
|
ctx.debug("Setting default status to 'draft'")
|
||||||
|
|
||||||
if ctx:
|
if ctx:
|
||||||
|
ctx.debug(f"Post status: {post_payload['status']}")
|
||||||
ctx.debug("Getting auth headers")
|
ctx.debug("Getting auth headers")
|
||||||
|
|
||||||
headers = await get_auth_headers(STAFF_API_KEY)
|
headers = await get_auth_headers(STAFF_API_KEY)
|
||||||
|
|
||||||
# Ensure lexical is a valid JSON string if present
|
# Ensure lexical is a valid JSON string if present
|
||||||
if 'lexical' in post_data:
|
if 'lexical' in post_payload:
|
||||||
try:
|
try:
|
||||||
if isinstance(post_data['lexical'], dict):
|
if isinstance(post_payload['lexical'], dict):
|
||||||
post_data['lexical'] = json.dumps(post_data['lexical'])
|
post_payload['lexical'] = json.dumps(post_payload['lexical'])
|
||||||
else:
|
else:
|
||||||
# Validate the JSON string
|
# Validate the JSON string
|
||||||
json.loads(post_data['lexical'])
|
json.loads(post_payload['lexical'])
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
error_msg = f"Invalid JSON in lexical content: {str(e)}"
|
error_msg = f"Invalid JSON in lexical content: {str(e)}"
|
||||||
if ctx:
|
if ctx:
|
||||||
@@ -860,7 +874,7 @@ async def create_post(post_data: dict, ctx: Context = None) -> str:
|
|||||||
|
|
||||||
# Prepare post creation payload
|
# Prepare post creation payload
|
||||||
request_data = {
|
request_data = {
|
||||||
"posts": [post_data]
|
"posts": [post_payload]
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx:
|
if ctx:
|
||||||
|
|||||||
Reference in New Issue
Block a user