Skip to content

Commit 486cfc0

Browse files
author
Smart Cloud Solutions Inc.
committed
feat(ai-kit): add document description override for KB docs and DocSearch result excerpts
1 parent 69e620e commit 486cfc0

14 files changed

Lines changed: 89 additions & 8 deletions

File tree

ai-kit-admin/dist/chunks/330.4f1e5014.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

ai-kit-admin/dist/chunks/330.828d35e6.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ai-kit-admin/dist/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('jquery', 'react', 'react-dom', 'react-jsx-runtime', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => 'e972fb7777808103e323');
1+
<?php return array('dependencies' => array('jquery', 'react', 'react-dom', 'react-jsx-runtime', 'wp-components', 'wp-data', 'wp-i18n'), 'version' => 'fb86e5d1fe3b40905744');

ai-kit-admin/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ai-kit-admin/php/kb/admin.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,10 +1138,14 @@ private function getKbPostTypeOptions(): array
11381138
private function getEffectiveSectionMetadata(object $section, ?object $override): array
11391139
{
11401140
$metadata = [];
1141+
$extra_meta = $section->extra_meta_json ? json_decode($section->extra_meta_json, true) : null;
11411142

11421143
if ($section->title) {
11431144
$metadata['title'] = $section->title;
11441145
}
1146+
if (is_array($extra_meta) && !empty($extra_meta['description']) && is_string($extra_meta['description'])) {
1147+
$metadata['description'] = $extra_meta['description'];
1148+
}
11451149
if ($section->category) {
11461150
$metadata['category'] = $section->category;
11471151
}
@@ -1264,6 +1268,9 @@ public function restGetPostKbData(\WP_REST_Request $request): \WP_REST_Response
12641268
'md' => $section->md,
12651269
'origin_hash' => $section->origin_hash,
12661270
'generated_at' => $section->generated_at,
1271+
'extra_meta' => $section->extra_meta_json
1272+
? json_decode($section->extra_meta_json, true)
1273+
: null,
12671274
'has_override' => (bool) $override,
12681275
'needs_review' => false
12691276
];
@@ -1304,6 +1311,9 @@ public function restGetPostKbData(\WP_REST_Request $request): \WP_REST_Response
13041311
return new \WP_REST_Response([
13051312
'post_id' => $post_id,
13061313
'post_title' => $post->post_title,
1314+
'post_excerpt' => has_excerpt($post_id)
1315+
? get_the_excerpt($post_id)
1316+
: wp_trim_words(wp_strip_all_tags($post->post_content), 30, '...'),
13071317
'post_type' => $post->post_type,
13081318
'post_url' => get_permalink($post_id),
13091319
'source' => $source ? [

ai-kit-admin/php/kb/parser.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ private function parseKbSectionBlock(\WP_Post $post, array $block, int $sort_ord
342342
$section_key = $attrs['sectionKey'] ?? null;
343343
$doc_key = $attrs['docKey'] ?? null;
344344
$title = $attrs['title'] ?? null;
345+
$description = $attrs['description'] ?? null;
345346
$tags = $attrs['tags'] ?? null;
346347
$category = $attrs['category'] ?? null;
347348
$subcategory = $attrs['subcategory'] ?? null;
@@ -379,6 +380,7 @@ private function parseKbSectionBlock(\WP_Post $post, array $block, int $sort_ord
379380
'source_updated_at' => $post->post_modified,
380381
'extra_meta' => [
381382
'block_type' => 'gutenberg',
383+
'description' => $description,
382384
'priority' => $priority,
383385
],
384386
];
@@ -412,6 +414,9 @@ private function parseGutenbergSimple(\WP_Post $post, array $blocks): array
412414
'md' => $markdown,
413415
'generated_at' => current_time('mysql'),
414416
'source_updated_at' => $post->post_modified,
417+
'extra_meta' => [
418+
'description' => $this->getPostDescription($post),
419+
],
415420
];
416421

417422
$section['origin_hash'] = $this->calculateOriginHash($section);
@@ -582,6 +587,7 @@ private function parseElementorWithSections(\WP_Post $post, array $elements): ar
582587
'generated_at' => current_time('mysql'),
583588
'source_updated_at' => $post->post_modified,
584589
'extra_meta' => [
590+
'description' => $this->getPostDescription($post),
585591
'source_type' => 'elementor',
586592
],
587593
];
@@ -672,6 +678,7 @@ private function parseElementorKbSection(\WP_Post $post, array $element, int $so
672678
$section_key = $settings['kb_section_key'] ?? null;
673679
$doc_key = $settings['kb_doc_key'] ?? null;
674680
$doc_title = $settings['kb_doc_title'] ?? null;
681+
$doc_description = $settings['kb_doc_description'] ?? null;
675682
$title = $settings['kb_title'] ?? null;
676683
$category = $settings['kb_category'] ?? null;
677684
$subcategory = $settings['kb_subcategory'] ?? null;
@@ -725,6 +732,7 @@ private function parseElementorKbSection(\WP_Post $post, array $element, int $so
725732
'generated_at' => current_time('mysql'),
726733
'source_updated_at' => $post->post_modified,
727734
'extra_meta' => [
735+
'description' => $doc_description,
728736
'source_type' => 'elementor',
729737
'priority' => $priority,
730738
],
@@ -844,6 +852,7 @@ private function parseElementorSimple(\WP_Post $post, array $elements): array
844852
'generated_at' => current_time('mysql'),
845853
'source_updated_at' => $post->post_modified,
846854
'extra_meta' => [
855+
'description' => $this->getPostDescription($post),
847856
'source_type' => 'elementor',
848857
],
849858
];
@@ -889,6 +898,9 @@ private function parseClassicPost(\WP_Post $post): array
889898
'md' => $markdown,
890899
'generated_at' => current_time('mysql'),
891900
'source_updated_at' => $post->post_modified,
901+
'extra_meta' => [
902+
'description' => $this->getPostDescription($post),
903+
],
892904
];
893905

894906
$section['origin_hash'] = $this->calculateOriginHash($section);
@@ -942,6 +954,20 @@ private function getPostTags(\WP_Post $post): ?array
942954
return array_map(fn($tag) => $tag->name, $tags);
943955
}
944956

957+
/**
958+
* Get the best available post description/excerpt for metadata.
959+
*/
960+
private function getPostDescription(\WP_Post $post): ?string
961+
{
962+
$description = has_excerpt($post->ID)
963+
? get_the_excerpt($post->ID)
964+
: wp_trim_words(wp_strip_all_tags($post->post_content), 30, '...');
965+
966+
$description = trim((string) $description);
967+
968+
return $description !== '' ? $description : null;
969+
}
970+
945971
/**
946972
* Generate a stable section ID from block data
947973
*/
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => '4626d5e6b69eba621932');
1+
<?php return array('dependencies' => array('react', 'react-dom', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'ce7a317b779454e7ef4a');

ai-kit-blocks/dist/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ai-kit-blocks/dist/kb-section/block.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"title": {
2525
"type": "string"
2626
},
27+
"description": {
28+
"type": "string"
29+
},
2730
"tags": {
2831
"type": "array",
2932
"default": [],

ai-kit-blocks/src/kb-section/block.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
"title": {
2525
"type": "string"
2626
},
27+
"description": {
28+
"type": "string"
29+
},
2730
"tags": {
2831
"type": "array",
2932
"default": [],

0 commit comments

Comments
 (0)