Browse Source

fleat:fleat answer

igb 1 month ago
parent
commit
0891d90fa8
2 changed files with 51 additions and 3 deletions
  1. 28 2
      usr/themes/beardocs/archive.php
  2. 23 1
      usr/themes/beardocs/functions.php

+ 28 - 2
usr/themes/beardocs/archive.php

@@ -88,6 +88,10 @@ function logSearch($keyword, $category_id, $dataset_id) {
 }
 
 
+
+
+
+
 // 示例调用
 $token = 'dataset-Emh5R5hCGorTuqG0dkQe7tMf';  // 传入实际的 token
 $datasets = 'c08ae7fa-c4e7-4fae-8138-2097ff19e1a6';  // 传入实际的 datasets ID
@@ -287,9 +291,18 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
             $index++;
             $content = $record['segment']['content'];
 
+
             // 提取开头的数字
             preg_match('/^\[(\d+)\]/', $content, $matches);
-            $number = $matches[1] ?? null;
+            $postId = $matches[1] ?? null;
+
+
+            $postContent=null;
+            // 从数据库获取完整内容
+
+
+            $postContent = $postId ? getPost($postId) : null;
+
 
             // 移除开头的数字部分
             $contentWithoutNumber = preg_replace('/^\[\d+\]\s*/', '', $content);
@@ -338,6 +351,19 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
                 $question = trim($contentWithoutNumber);
                 $answer = ''; // 答案部分为空
             }
+
+
+            if($postContent)
+            {
+
+                $answer=$postContent['text'];
+
+            }
+
+
+
+
+
         ?>
 
             <div class="uk-card uk-card-category uk-card-default uk-card-hover uk-card-body uk-inline uk-border-rounded uk-width-1-1">
@@ -346,7 +372,7 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
 <!--                    <span id="icon---><?php //= $index ?><!--" class="toggle-icon">▼</span>-->
 
                 </div>
-                <div id="answer-<?= $index ?>" class="answer" style="display: none;">
+                <div id="answer-<?= $index ?>" class="answer" style="display: none;white-space: pre-line;">
                     <?= $answer ?>
                 </div>
             </div>

+ 23 - 1
usr/themes/beardocs/functions.php

@@ -726,4 +726,26 @@ function themeConfig($form)
    </script>
    <?php endif; ?>
     <?php
-} ?>
+}
+
+
+
+
+function getPost($postId){
+    $db = Typecho_Db::get();
+    $post = $db->fetchRow($db->select()->from('table.contents')->where('cid = ?', $postId));
+
+    if(!$post){
+        return null;
+    }
+    else
+    {
+         return Typecho_Widget::widget('Widget_Abstract_Contents')->push($post);
+
+    }
+
+}
+
+
+
+?>