Browse Source

fleat:update template

igb 1 month ago
parent
commit
0b5137726b
2 changed files with 94 additions and 82 deletions
  1. 93 35
      usr/themes/beardocs/archive.php
  2. 1 47
      usr/themes/beardocs/index.php

+ 93 - 35
usr/themes/beardocs/archive.php

@@ -173,6 +173,53 @@ $thisChild["name"] ?></a></li> <?php }  ?>
 </div>
       <!-- 查看分类下的 END-->
 
+      <script>
+          function toggleAnswer(index) {
+              var answerDiv = document.getElementById('answer-' + index);
+              var icon = document.getElementById('icon-' + index);
+
+              if (answerDiv.style.display === 'none') {
+                  answerDiv.style.display = 'block';
+                  //icon.innerHTML = '▲'; // 展开时显示向上箭头
+              } else {
+                  answerDiv.style.display = 'none';
+                 // icon.innerHTML = '▼'; // 收起时显示向下箭头
+              }
+          }
+
+          // 默认展开第一个问题的答案
+          window.onload = function() {
+              toggleAnswer(1); // 默认展开第一个问题
+          };
+      </script>
+
+      <!-- 添加 CSS 样式 -->
+      <style>
+          .question {
+              cursor: pointer; /* 鼠标悬停时显示手型光标 */
+              color: #333; /* 深色字体 */
+
+              margin-bottom: 10px; /* 问题与答案之间的间距 */
+          }
+
+          /*.question:hover {*/
+          /*    text-decoration: underline; !* 鼠标悬停时添加下划线 *!*/
+          /*}*/
+
+          .toggle-icon {
+              margin-left: 10px; /* 图标与问题之间的间距 */
+
+              color: #666; /* 图标颜色 */
+          }
+
+          .answer {
+              /*font-size: 16px; !* 答案字体大小 *!*/
+              color: #555; /* 答案字体颜色 */
+              margin-top: 10px; /* 答案与问题之间的间距 */
+              padding-left: 20px; /* 答案缩进 */
+
+          }
+      </style>
     <div class="uk-margin-medium-top">
 
         <?php
@@ -220,43 +267,54 @@ if (!empty($keyword)&&(strpos($PathInfo, '/search') === 0))
             // 移除开头的数字部分
             $contentWithoutNumber = preg_replace('/^\[\d+\]\s*/', '', $content);
 
-            // 按空格分割内容(保留所有符号)
-            $parts = preg_split('/\s+/', $contentWithoutNumber);
-
-            // 截取处理
-            $truncatedContent = '';
-            $charCount = 0;
-            $maxLength = 300;
-
-            foreach ($parts as $part) {
-                $partLength = strlen($part);
-                $spaceLength = $truncatedContent ? 1 : 0; // 空格长度
-
-                if ($charCount + $partLength + $spaceLength <= $maxLength) {
-                    $truncatedContent .= ($spaceLength ? ' ' : '') . $part;
-                    $charCount += $partLength + $spaceLength;
-                } else {
-                    // 处理最后追加的省略号
-                    $available = $maxLength - $charCount;
-                    if ($available >= 3) { // 剩余空间足够加...
-                        $truncatedContent .= ' ' . substr($part, 0, $available - 3) . '...';
-                    } elseif ($available > 0) {
-                        $truncatedContent .= substr($part, 0, $available);
-                    }
-                    break;
-                }
-            }
-
-            // 处理刚好满长度的情况
-            if ($charCount >= $maxLength && !str_ends_with($truncatedContent, '...')) {
-                $truncatedContent = substr($truncatedContent, 0, $maxLength - 3) . '...';
-            }
+//            // 按空格分割内容(保留所有符号)
+//            $parts = preg_split('/\s+/', $contentWithoutNumber);
+//
+//            // 截取处理
+//            $truncatedContent = '';
+//            $charCount = 0;
+//            $maxLength = 300;
+//
+//            foreach ($parts as $part) {
+//                $partLength = strlen($part);
+//                $spaceLength = $truncatedContent ? 1 : 0; // 空格长度
+//
+//                if ($charCount + $partLength + $spaceLength <= $maxLength) {
+//                    $truncatedContent .= ($spaceLength ? ' ' : '') . $part;
+//                    $charCount += $partLength + $spaceLength;
+//                } else {
+//                    // 处理最后追加的省略号
+//                    $available = $maxLength - $charCount;
+//                    if ($available >= 3) { // 剩余空间足够加...
+//                        $truncatedContent .= ' ' . substr($part, 0, $available - 3) . '...';
+//                    } elseif ($available > 0) {
+//                        $truncatedContent .= substr($part, 0, $available);
+//                    }
+//                    break;
+//                }
+//            }
+//
+//            // 处理刚好满长度的情况
+//            if ($charCount >= $maxLength && !str_ends_with($truncatedContent, '...')) {
+//                $truncatedContent = substr($truncatedContent, 0, $maxLength - 3) . '...';
+//            }
+
+            $parts = explode('?', $contentWithoutNumber, 2); // 最多分割成两部分
+            $question = trim($parts[0]) . '?'; // 问题部分加上 ?
+            $answer = isset($parts[1]) ? trim($parts[1]) : ''; // 答案部分
         ?>
 
-        <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">
-            <a class="uk-position-cover" target="_blank" href="https://support.hydrogelmachine.com/archives/<?= $number ?>.html"></a>
-            <p class="uk-margin-small-top"><?= "$index. $truncatedContent" ?></p>
-        </div>
+            <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">
+                <div class="question" onclick="toggleAnswer(<?= $index ?>)">
+                    <h4><?= "$index. $question" ?> </h4>
+<!--                    <span id="icon---><?php //= $index ?><!--" class="toggle-icon">▼</span>-->
+
+                </div>
+                <div id="answer-<?= $index ?>" class="answer" style="display: none;">
+                    <?= $answer ?>
+                </div>
+            </div>
+
 
         <?php
         }

+ 1 - 47
usr/themes/beardocs/index.php

@@ -53,54 +53,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
     </div>
 
 
-<?php if (General::Options('commonProblem_module') == true): ?>
-<div class="uk-section uk-section-muted">
-	<div class="uk-container uk-container-small">
-		<h2 class="uk-text-center">常见问题解答</h2>
-		<ul class="uk-margin-medium-top" data-uk-accordion="multiple: true">
-		    <?php foreach(General::Options('commonProblem') as $commonProblem):?>
-			<li>
-				<a class="uk-accordion-title uk-box-shadow-hover-small"><?php echo $commonProblem['commonProblem_title']; ?></a>
-				<div class="uk-article-content uk-accordion-content link-secondary">
-					<p><?php echo $commonProblem['commonProblem_answer']; ?></p>
-				</div>
-			</li>
-	<?php endforeach;?>
-		</ul>
-	</div>
-</div>
 
-<?php endif; ?>
 
-<?php if (General::Options('friendLinks_module') == true): ?>
-<div class="uk-section uk-section-muted">
-	<div class="uk-container uk-container-large">
-		<h2 class="uk-text-center">友情链接</h2>
-<div class="uk-grid-small uk-animation-fade uk-flex-middle uk-child-width-1-9 uk-child-width-1-2@m uk-child-width-1-3@l uk-grid-match uk-padding-small" uk-grid >
-    <?php foreach(General::Options('friendLinks') as $friendLinks):?>
-  <a href="<?php echo $friendLinks['friendLink_url']; ?>" target="_blank">
-      
-    <div class="uk-card uk-card-default uk-card-hover">
-      <div class="uk-card-header">
-        <div class="uk-grid-small uk-flex-middle" uk-grid>
-          <div class="uk-width-auto">
-            <img width="60" height="60" src="<?php echo $friendLinks['friendLink_logo']; ?>" loading="lazy">
-          </div>
-          <div class="uk-width-expand">
-            <h3 class="uk-card-title uk-margin-remove-bottom"><?php echo $friendLinks['friendLink_title']; ?></h3>
-            <p class="uk-text uk-margin-remove"><?php echo $friendLinks['friendLink_desc']; ?></p>
-          </div>
-        </div>
-        
-      </div>
-    </div>
-    
-  </a>
-  <?php endforeach; ?>
-  </div>
-    
-   </div></div> 
-      
 
-<?php endif; ?>
+
 <?php $this->need('footer.php'); ?>