Skip to content

Commit

Permalink
site gen fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
amartya-dev committed Nov 16, 2023
1 parent 92b8c67 commit 6f72164
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ private static function check_capabilities() {
* @param string $identifier The identifier to be used for generating the required meta
*/
private static function validate_site_info( $site_info, $identifier ) {
if ( in_array( $identifier, self::$required_validations, true ) ) {
if ( array_key_exists( $identifier, self::$required_validations ) ) {
$validations = self::$required_validations[ $identifier ];
foreach ( $validations as $required_key ) {
if ( ! in_array( $required_key, $site_info, true ) ) {
if ( ! array_key_exists( $required_key, $site_info ) ) {
return false;
}
}
return true;
}
return true;
}

/**
Expand Down Expand Up @@ -139,8 +139,8 @@ private static function get_patterns_for_category( $category ) {
$patterns = json_decode( wp_remote_retrieve_body( $response ), true );
$processed_patterns = array();

foreach ( $patterns as $pattern ) {
array_push( $processed_patterns, array( $pattern['slug'] => $pattern ) );
foreach ( $patterns['data'] as $pattern ) {
$processed_patterns[ $pattern['slug'] ] = $pattern;
}

return $processed_patterns;
Expand Down Expand Up @@ -174,7 +174,7 @@ private static function generate_pattern_content(
$unique_categories = array();
foreach ( $content_structure as $homepage => $structure ) {
foreach ( $structure as $category ) {
if ( ! in_array( $unique_categories, $category, true ) ) {
if ( ! in_array( $category, $unique_categories, true ) ) {
array_push( $unique_categories, $category );
}
}
Expand All @@ -186,13 +186,14 @@ private static function generate_pattern_content(
foreach ( $unique_categories as $category ) {
$patterns_for_category = self::get_patterns_for_category( $category );
if ( count( $patterns_for_category ) <= 5 ) {
$random_selected_patterns = $patterns_for_category;
$random_selected_patterns = array_rand( $patterns_for_category, count( $patterns_for_category ) );
} else {
$random_selected_patterns = array_rand( $patterns_for_category, 5 );
}

array_push( $category_pattern_map, array( $category => array() ) );
foreach ( $random_selected_patterns as $pattern ) {
$category_pattern_map[ $category ] = array();
foreach ( $random_selected_patterns as $pattern_slug ) {
$pattern = $patterns_for_category[ $pattern_slug ];
// Generate content for these patterns
$response = wp_remote_post(
NFD_AI_BASE . 'generateSiteMeta',
Expand All @@ -205,7 +206,7 @@ private static function generate_pattern_content(
array(
'hiivetoken' => HiiveConnection::get_auth_token(),
'prompt' => array(
'pattern' => $pattern,
'pattern' => $pattern['content'],
'prompt' => self::get_prompt_from_info(
array(
'site_description' => $site_description,
Expand Down Expand Up @@ -310,7 +311,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache
* @param array $target_audience Generated target audience.
* @param boolean $regenerate If we need to regenerate.
*/
public static function get_home_pages( $site_description, $content_style, $target_audience, $regenerate ) {
public static function get_home_pages( $site_description, $content_style, $target_audience, $regenerate = false ) {
$generated_content_structures = self::generate_site_meta(
array( 'site_description' => $site_description ),
'contentstructure'
Expand Down

0 comments on commit 6f72164

Please sign in to comment.