Skip to content

Commit

Permalink
Merge pull request #18 from newfold-labs/features/otherpages
Browse files Browse the repository at this point in the history
response change to include generated images per page
  • Loading branch information
amartya-dev authored Feb 9, 2024
2 parents a2cea71 + 855d985 commit c60abd4
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ public static function get_home_pages( $site_description, $content_style, $targe
$generated_content_structures = self::get_sitegen_from_cache(
'contentStructures'
);
$generated_images = self::get_sitegen_from_cache(
'generatedImages'
);
$keywords = self::generate_site_meta(
array(
'site_description' => $site_description,
Expand Down Expand Up @@ -424,10 +421,6 @@ public static function get_home_pages( $site_description, $content_style, $targe
$generated_content_structures = $parsed_response['contentStructures'];
$generated_patterns = $parsed_response['generatedPatterns'];
$generated_homepages = $parsed_response['pages'];
if ( array_key_exists( 'generatedImages', $parsed_response ) ) {
$generated_images = $parsed_response['generatedImages'];
self::cache_sitegen_response( 'generatedImages', $generated_images );
}
self::cache_sitegen_response( 'contentStructures', $generated_content_structures );
self::cache_sitegen_response( 'generatedPatterns', $generated_patterns );
self::cache_sitegen_response( 'homepages', $generated_homepages );
Expand All @@ -452,15 +445,20 @@ public static function get_home_pages( $site_description, $content_style, $targe
$random_pattern = $generated_patterns[ $pattern_category ][ $pattern_index ];

if ( in_array( $pattern_category, $categories_to_separate, true ) ) {
$homepage_patterns[ $pattern_category ] = $random_pattern;
$homepage_patterns[ $pattern_category ] = $random_pattern['replacedPattern'];
} else {
$homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern;
$homepage_patterns['content'] = $homepage_patterns['content'] . $random_pattern['replacedPattern'];
}

$homepage_patterns['generatedImages'] = array();

if ( ! empty( $random_pattern['dalleImages'] ) ) {
$homepage_patterns['generatedImages'] = $random_pattern['dalleImages'];
}
}
$generated_homepages[ $slug ] = $homepage_patterns;
}

$generated_homepages['generatedImages'] = $generated_images;
self::cache_sitegen_response( 'homepages', $generated_homepages );
return $generated_homepages;
}
Expand Down Expand Up @@ -528,10 +526,13 @@ public static function get_content_for_page(
}
}
$parsed_response = json_decode( wp_remote_retrieve_body( $response ), true );
$generated_page = '';
if ( ! array_key_exists( 'error', $parsed_response['content'] ) ) {
$parsed_response['content'] = implode( '', $parsed_response['content'] );
foreach ( $parsed_response['content'] as $pattern_content ) {
$generated_page .= $pattern_content['replacedPattern'];
}
}
return $parsed_response['content'];
return $generated_page;
}

/**
Expand Down

0 comments on commit c60abd4

Please sign in to comment.