Skip to content

Commit

Permalink
Merge pull request #16 from newfold-labs/features/otherpages
Browse files Browse the repository at this point in the history
fix: otherpages, skip when home slug
  • Loading branch information
amartya-dev authored Feb 1, 2024
2 parents 0265f65 + 48ff2c9 commit 0760926
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ 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 ) ) {
if ( array_key_exists( 'generatedImages', $parsed_response ) ) {
$generated_images = $parsed_response['generatedImages'];
self::cache_sitegen_response( 'generatedImages', $generated_images );
}
Expand All @@ -437,30 +437,29 @@ public static function get_home_pages( $site_description, $content_style, $targe
$generated_homepages = array();
$generated_patterns = self::get_sitegen_from_cache( 'generatedPatterns' );

$categories_to_separate = array('header', 'footer');
$categories_to_separate = array( 'header', 'footer' );
// Choose random categories for the generated patterns and return
foreach ( $random_homepages as $homepage_index => $slug ) {
$generated_homepages[ $slug ] = array();
$homepage_patterns = array();
$homepage_patterns = array();
foreach ( $generated_content_structures[ $slug ] as $pattern_category ) {
if ( empty( $generated_patterns[ $pattern_category ] ) ) {
continue;
}
// Get a random pattern for the category when regenerating otherwise pick in sequence
// so that the 3 previews are as different as much as possible.
$pattern_index = ( $regenerate ) ? array_rand( $generated_patterns[ $pattern_category ] ) : $homepage_index;
$pattern_index = ( $regenerate ) ? array_rand( $generated_patterns[ $pattern_category ] ) : $homepage_index;
$random_pattern = $generated_patterns[ $pattern_category ][ $pattern_index ];

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

}
$generated_homepages[ $slug ] = $homepage_patterns;
}

$generated_homepages['generatedImages'] = $generated_images;
self::cache_sitegen_response( 'homepages', $generated_homepages );
return $generated_homepages;
Expand Down Expand Up @@ -529,7 +528,7 @@ public static function get_content_for_page(
}
}
$parsed_response = json_decode( wp_remote_retrieve_body( $response ), true );
if( ! array_key_exists( 'error', $parsed_response['content'] ) ) {
if ( ! array_key_exists( 'error', $parsed_response['content'] ) ) {
$parsed_response['content'] = implode( '', $parsed_response['content'] );
}
return $parsed_response['content'];
Expand Down Expand Up @@ -572,6 +571,10 @@ public static function get_pages(
$page = $site_menu_options['slug'];
$keywords = $site_menu_options['keywords'];

if ( strcmp( $site_menu_options['slug'], 'home' ) === 0 ) {
continue;
}

$response = self::get_content_for_page(
$site_description,
$content_style,
Expand Down

0 comments on commit 0760926

Please sign in to comment.