Add generate_page_content functionality for structured page content generation
- Introduced a new AI function `generate_page_content` to create structured content for website pages using JSON blocks. - Updated `AIEngine` to handle the new function and return appropriate messages for content generation. - Enhanced `PageGenerationService` to utilize the new AI function for generating page content based on blueprints. - Modified `prompts.py` to include detailed content generation requirements for the new function. - Updated site rendering logic to accommodate structured content blocks in various layouts.
This commit is contained in:
@@ -105,6 +105,7 @@ class SitesRendererAdapter(BaseAdapter):
|
||||
def _build_site_definition(self, site_blueprint: SiteBlueprint) -> Dict[str, Any]:
|
||||
"""
|
||||
Build site definition JSON from blueprint.
|
||||
Merges actual Content from Writer into PageBlueprint blocks.
|
||||
|
||||
Args:
|
||||
site_blueprint: SiteBlueprint instance
|
||||
@@ -112,15 +113,55 @@ class SitesRendererAdapter(BaseAdapter):
|
||||
Returns:
|
||||
dict: Site definition structure
|
||||
"""
|
||||
from igny8_core.business.content.models import Tasks, Content
|
||||
|
||||
# Get all pages
|
||||
pages = []
|
||||
for page in site_blueprint.pages.all().order_by('order'):
|
||||
# Get blocks from blueprint (placeholders)
|
||||
blocks = page.blocks_json or []
|
||||
|
||||
# Try to find actual Content from Writer
|
||||
# PageBlueprint -> Task (by title pattern) -> Content
|
||||
task_title = f"[Site Builder] {page.title or page.slug.replace('-', ' ').title()}"
|
||||
task = Tasks.objects.filter(
|
||||
account=page.account,
|
||||
site=page.site,
|
||||
sector=page.sector,
|
||||
title=task_title
|
||||
).first()
|
||||
|
||||
# If task exists, get its Content
|
||||
if task and hasattr(task, 'content_record'):
|
||||
content = task.content_record
|
||||
# If content is published, merge its blocks
|
||||
if content and content.status == 'publish' and content.json_blocks:
|
||||
# Merge Content.json_blocks into PageBlueprint.blocks_json
|
||||
# Content blocks take precedence over blueprint placeholders
|
||||
blocks = content.json_blocks
|
||||
logger.info(
|
||||
f"[SitesRendererAdapter] Using published Content blocks for page {page.slug} "
|
||||
f"(Content ID: {content.id})"
|
||||
)
|
||||
elif content and content.status == 'publish' and content.html_content:
|
||||
# If no json_blocks but has html_content, convert to text block
|
||||
blocks = [{
|
||||
'type': 'text',
|
||||
'data': {
|
||||
'content': content.html_content,
|
||||
'title': content.title or page.title
|
||||
}
|
||||
}]
|
||||
logger.info(
|
||||
f"[SitesRendererAdapter] Converted HTML content to text block for page {page.slug}"
|
||||
)
|
||||
|
||||
pages.append({
|
||||
'id': page.id,
|
||||
'slug': page.slug,
|
||||
'title': page.title,
|
||||
'type': page.type,
|
||||
'blocks': page.blocks_json,
|
||||
'blocks': blocks,
|
||||
'status': page.status,
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user