" line (mirrors AILM_LlmsTxt_Generator::generate()). $description = self::site_description( $settings ); if ( '' !== $description ) { $parts[] = '> ' . $description; $parts[] = ''; } $total = 0; foreach ( $post_types as $post_type ) { if ( $total >= $max_posts ) { break; } $posts = self::query_posts( $post_type, $exclude, $max_posts - $total ); if ( empty( $posts ) ) { continue; } foreach ( $posts as $post ) { $parts[] = self::render_post( $post, $settings ); $parts[] = ''; $total++; } } $content = implode( "\n", $parts ) . "\n" . AILM_LlmsTxt_Generator::FOOTER . "\n"; // Always keep a DB copy: when the site root is not writable, the // Server's template_redirect fallback still serves llms-full.txt. AILM_LlmsTxt_Server::store_db_copy( AILM_LlmsTxt_File_Writer::FILENAME_LLMS_FULL, $content ); if ( ! $write_live ) { return true; } return AILM_LlmsTxt_File_Writer::write( AILM_LlmsTxt_File_Writer::FILENAME_LLMS_FULL, $content ); } /** * Render one post as a Markdown section (with per-post cache). * * @param WP_Post $post Post. * @param array $settings Module settings. * @return string */ private static function render_post( $post, array $settings ) { $url = get_permalink( $post->ID ); // Shared title helper (entity decoding + single-line flattening), // same as the main llms.txt generator — keeps the two files consistent. $title = AILM_LlmsTxt_Generator::post_title( $post ); $head = '## ' . $title . "\n\n"; $head .= '- URL: ' . $url . "\n"; // AI summary as the intro (if fresh), else excerpt. plain_line() // decodes HTML entities so "&" / "–" do not leak into // llms-full.txt (same fix as the main generator's tagline line). $summary = ''; if ( ! empty( $settings['use_summaries'] ) ) { $summary = AILM_LlmsTxt_Data::get_summary( $post->ID, $post->post_content ); } if ( '' === $summary ) { $summary = wp_strip_all_tags( get_the_excerpt( $post ) ); } $summary = AILM_LlmsTxt_Generator::plain_line( $summary ); if ( '' !== $summary ) { $head .= '- Summary: ' . $summary . "\n"; } $body = self::get_markdown_body( $post ); return $head . "\n" . $body; } /** * Get the Markdown body for a post, using the postmeta cache when the * content hash is unchanged. * * @param WP_Post $post Post. * @return string */ private static function get_markdown_body( $post ) { $content_hash = md5( $post->post_content ); $cached_hash = get_post_meta( $post->ID, self::META_MD_HASH, true ); $cached_body = get_post_meta( $post->ID, self::META_MD_BODY, true ); if ( $cached_hash === $content_hash && is_string( $cached_body ) && '' !== $cached_body ) { return $cached_body; } $markdown = AILM_LlmsTxt_Markdown::convert( $post->post_content ); // Guard against postmeta size limits: only cache bodies < 256KB. if ( strlen( $markdown ) < 256 * 1024 ) { update_post_meta( $post->ID, self::META_MD_HASH, $content_hash ); update_post_meta( $post->ID, self::META_MD_BODY, $markdown ); } return $markdown; } /** * Query published posts (same filtering as the main generator). * * @param string $post_type Post type slug. * @param array $exclude Excluded post IDs. * @param int $limit Max posts. * @return WP_Post[] */ private static function query_posts( $post_type, array $exclude, $limit ) { $args = array( 'post_type' => $post_type, 'post_status' => 'publish', 'posts_per_page' => $limit, 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => false, ); if ( ! empty( $exclude ) ) { $args['post__not_in'] = $exclude; } $query = new WP_Query( $args ); $posts = $query->posts; wp_reset_postdata(); return $posts ? $posts : array(); } /** * Site name (same logic as the main generator). * * @return string */ private static function site_name() { // Entity-decoded via the shared helper so "&" in the site title // does not leak into the "# … — Full Content" heading. return AILM_LlmsTxt_Generator::plain_line( get_bloginfo( 'name' ) ); } /** * Site description (same logic as the main generator). * * @param array $settings Module settings. * @return string */ private static function site_description( array $settings ) { $custom = isset( $settings['site_description'] ) ? trim( (string) $settings['site_description'] ) : ''; if ( '' !== $custom ) { return AILM_LlmsTxt_Generator::plain_line( $custom ); } return AILM_LlmsTxt_Generator::plain_line( get_bloginfo( 'description' ) ); } }