blurpritn adn site builde cleanup
This commit is contained in:
@@ -37,7 +37,7 @@ def publish_content_to_wordpress(self, content_id: int, site_integration_id: int
|
||||
start_time = time.time()
|
||||
|
||||
try:
|
||||
from igny8_core.business.content.models import Content, ContentTaxonomyMap
|
||||
from igny8_core.business.content.models import Content
|
||||
from igny8_core.business.integration.models import SiteIntegration, SyncEvent
|
||||
from igny8_core.modules.writer.models import Images
|
||||
from django.utils.html import strip_tags
|
||||
@@ -100,47 +100,75 @@ def publish_content_to_wordpress(self, content_id: int, site_integration_id: int
|
||||
else:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No content_html found - excerpt will be empty")
|
||||
|
||||
# STEP 4: Get taxonomy terms (categories)
|
||||
publish_logger.info(f"{log_prefix} STEP 4: Loading taxonomy mappings for categories...")
|
||||
taxonomy_maps = ContentTaxonomyMap.objects.filter(content=content).select_related('taxonomy')
|
||||
publish_logger.info(f" {log_prefix} Found {taxonomy_maps.count()} taxonomy mappings")
|
||||
# STEP 4: Get taxonomy terms (categories and tags)
|
||||
publish_logger.info(f"{log_prefix} STEP 4: Loading taxonomy terms from Content.taxonomy_terms...")
|
||||
|
||||
categories = []
|
||||
for mapping in taxonomy_maps:
|
||||
if mapping.taxonomy:
|
||||
categories.append(mapping.taxonomy.name)
|
||||
publish_logger.info(f" {log_prefix} 📁 Category: '{mapping.taxonomy.name}'")
|
||||
# Get categories from ContentTaxonomy many-to-many relationship
|
||||
# This is the CORRECT way - matching ContentSerializer.get_categories()
|
||||
categories = [
|
||||
term.name
|
||||
for term in content.taxonomy_terms.filter(taxonomy_type='category')
|
||||
]
|
||||
|
||||
publish_logger.info(f" {log_prefix} Found {len(categories)} categories from taxonomy_terms")
|
||||
for cat in categories:
|
||||
publish_logger.info(f" {log_prefix} 📁 Category: '{cat}'")
|
||||
|
||||
# FALLBACK: If no categories from taxonomy_terms, use Cluster as category (matches UI display)
|
||||
if not categories and content.cluster:
|
||||
categories.append(content.cluster.name)
|
||||
publish_logger.info(f" {log_prefix} 📁 Category (fallback from cluster): '{content.cluster.name}'")
|
||||
|
||||
if not categories:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No categories found for content")
|
||||
else:
|
||||
publish_logger.info(f" {log_prefix} ✅ TOTAL categories: {len(categories)}")
|
||||
|
||||
# STEP 5: Get keywords as tags
|
||||
publish_logger.info(f"{log_prefix} STEP 5: Extracting keywords as tags...")
|
||||
tags = []
|
||||
# STEP 5: Get tags from taxonomy_terms AND keywords
|
||||
publish_logger.info(f"{log_prefix} STEP 5: Loading tags from taxonomy_terms and keywords...")
|
||||
|
||||
# First, get tags from ContentTaxonomy many-to-many relationship
|
||||
# This matches ContentSerializer.get_tags()
|
||||
tags = [
|
||||
term.name
|
||||
for term in content.taxonomy_terms.filter(taxonomy_type='tag')
|
||||
]
|
||||
|
||||
publish_logger.info(f" {log_prefix} Found {len(tags)} tags from taxonomy_terms")
|
||||
for tag in tags:
|
||||
publish_logger.info(f" {log_prefix} 🏷️ Tag: '{tag}'")
|
||||
|
||||
# Add primary keyword as tag (if not already in tags)
|
||||
if content.primary_keyword:
|
||||
tags.append(content.primary_keyword)
|
||||
publish_logger.info(f" {log_prefix} 🏷️ Primary keyword: '{content.primary_keyword}'")
|
||||
if content.primary_keyword not in tags:
|
||||
tags.append(content.primary_keyword)
|
||||
publish_logger.info(f" {log_prefix} 🏷️ Primary keyword: '{content.primary_keyword}'")
|
||||
else:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No primary keyword found")
|
||||
|
||||
# Add secondary keywords as tags (if not already in tags)
|
||||
if content.secondary_keywords:
|
||||
if isinstance(content.secondary_keywords, list):
|
||||
tags.extend(content.secondary_keywords)
|
||||
for keyword in content.secondary_keywords:
|
||||
if keyword not in tags:
|
||||
tags.append(keyword)
|
||||
publish_logger.info(f" {log_prefix} 🏷️ Secondary keywords (list): {content.secondary_keywords}")
|
||||
elif isinstance(content.secondary_keywords, str):
|
||||
try:
|
||||
keywords = json.loads(content.secondary_keywords)
|
||||
if isinstance(keywords, list):
|
||||
tags.extend(keywords)
|
||||
for keyword in keywords:
|
||||
if keyword not in tags:
|
||||
tags.append(keyword)
|
||||
publish_logger.info(f" {log_prefix} 🏷️ Secondary keywords (JSON): {keywords}")
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ Failed to parse secondary_keywords as JSON: {content.secondary_keywords}")
|
||||
else:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No secondary keywords found")
|
||||
|
||||
publish_logger.info(f" {log_prefix} ✅ TOTAL tags: {len(tags)}")
|
||||
|
||||
|
||||
if not tags:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No tags found for content")
|
||||
else:
|
||||
@@ -154,17 +182,30 @@ def publish_content_to_wordpress(self, content_id: int, site_integration_id: int
|
||||
featured_image_url = None
|
||||
gallery_images = []
|
||||
|
||||
def convert_image_path_to_url(image_path):
|
||||
"""Convert local image path to public URL"""
|
||||
if not image_path:
|
||||
return None
|
||||
# Convert: /data/app/igny8/frontend/public/images/... -> https://app.igny8.com/images/...
|
||||
if '/frontend/public/' in image_path:
|
||||
relative_path = image_path.split('/frontend/public/')[-1]
|
||||
return f"https://app.igny8.com/{relative_path}"
|
||||
return image_path
|
||||
|
||||
for image in images:
|
||||
if image.image_type == 'featured' and image.image_url:
|
||||
featured_image_url = image.image_url
|
||||
publish_logger.info(f" {log_prefix} 🖼️ Featured image: {image.image_url[:80]}...")
|
||||
elif image.image_type == 'in_article' and image.image_url:
|
||||
# Use image_path (local file) and convert to public URL
|
||||
image_url = convert_image_path_to_url(image.image_path) if hasattr(image, 'image_path') and image.image_path else None
|
||||
|
||||
if image.image_type == 'featured' and image_url:
|
||||
featured_image_url = image_url
|
||||
publish_logger.info(f" {log_prefix} 🖼️ Featured image: {image_url[:80]}...")
|
||||
elif image.image_type == 'in_article' and image_url:
|
||||
gallery_images.append({
|
||||
'url': image.image_url,
|
||||
'alt': image.alt_text or '',
|
||||
'caption': image.caption or ''
|
||||
'url': image_url,
|
||||
'alt': getattr(image, 'alt', '') or '',
|
||||
'caption': getattr(image, 'caption', '') or ''
|
||||
})
|
||||
publish_logger.info(f" {log_prefix} 🖼️ Gallery image {len(gallery_images)}: {image.image_url[:60]}...")
|
||||
publish_logger.info(f" {log_prefix} 🖼️ Gallery image {len(gallery_images)}: {image_url[:60]}...")
|
||||
|
||||
if not featured_image_url:
|
||||
publish_logger.warning(f" {log_prefix} ⚠️ No featured image found")
|
||||
|
||||
Reference in New Issue
Block a user