Browse Source

add blog search

SyuanYu 2 years ago
parent
commit
52288880e3

+ 1 - 1
content/blog/0712-1/index.md

@@ -7,7 +7,7 @@ draft: false
 type: "blog"
 url: "/blog/0712-1"
 image: "/img/title/8a66c9f81dc34b29986b89359ef8c542.webp"
-categories: ["0712-1"]
+categories: "預算準備"
 description: ""
 col1: "0712-1"
 col2: ""

+ 1 - 1
content/blog/0712/index.md

@@ -7,7 +7,7 @@ draft: false
 type: "blog"
 url: "/blog/0712"
 image: "/img/title/16cee02b48734b69ba99f6f27833fc5a.webp"
-categories: ["0712"]
+categories: "預算準備"
 description: ""
 col1: "0712"
 col2: ""

+ 22 - 0
content/blog/0714-1/index.md

@@ -0,0 +1,22 @@
+---
+meta_title: "0714-1"
+meta_description: "0714-1"
+title: "0714-1"
+date: 2022-07-14T16:31:08+08:00
+draft: false
+type: "blog"
+url: "/blog/0714-1"
+image: "/img/title/1.webp"
+categories: "預算準備"
+description: ""
+col1: "budget_preparation"
+col2: ""
+introduction: "0714-1"
+question_box_intro: "0714-1"
+---
+
+
+<div class="container-fluid blog_article p-0">
+
+0714-1
+

+ 85 - 43
layouts/blog/list.html

@@ -17,7 +17,8 @@
         style="--bs-breadcrumb-divider: url(&#34;data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8'%3E%3Cpath d='M2.5 0L1 1.5 3.5 4 1 6.5 2.5 8l4-4-4-4z' fill='currentColor'/%3E%3C/svg%3E&#34;);"
         aria-label="breadcrumb">
         <ol class="breadcrumb">
-          <li class="breadcrumb-item"><a href="#"><img src="/img/bt_footer_index@2x.png" width="30px" alt="" style="margin-bottom: 5px;"></a></li>
+          <li class="breadcrumb-item"><a href="#"><img src="/img/bt_footer_index@2x.png" width="30px" alt=""
+                style="margin-bottom: 5px;"></a></li>
           <li class="breadcrumb-item"><a href="#">成家知識專欄</a></li>
           <li class="breadcrumb-item active" aria-current="page">預售屋客變</li>
         </ol>
@@ -37,8 +38,7 @@
             <div class="bhouseweb_search_img" style="margin-right: 1vw;">
               <img src="/img/icon_search@2x.png" alt="">
             </div>
-            <input id="bhouseweb_search" class="me-md-2" type="search" placeholder="搜尋「客變」「工業風」「三代同堂」"
-              aria-label="Search">
+            <input id="blog_search" class="me-md-2" type="search" placeholder="搜尋「客變」「工業風」「三代同堂」" aria-label="Search">
           </form>
         </div>
       </div>
@@ -46,7 +46,7 @@
 
     <div style="border-top: 1px solid #969696;"></div>
 
-    <div class="article">
+    <div class="article" id="articleList">
 
       {{ $paginator := .Paginate .Data.Pages }}
       {{ range $paginator.Pages }}
@@ -65,51 +65,93 @@
           <!-- <p style="color:#4D4D4D;">{{ .Summary }}</p> -->
         </div>
       </div>
-
       {{ end }}
-      <!-- <div class="article-item">
-        <a href="">
-          <img src="/img//collection/boutique_hotel_slightly_drunk_chill_house_2.webp" alt="">
-        </a>
-        <div class="d-flex flex-column">
-          <a href="">
-            <h4>【客變】 預售屋客變懶人包:客變什麼?這樣做好不好?</h4>
-          </a>
-          <p class="mt-auto mb-0">2021-11-23</p>
-        </div>
-      </div>
-
-      <div class="article-item">
-        <a href="">
-          <img src="/img//collection/boutique_hotel_slightly_drunk_chill_house_2.webp" alt="">
-        </a>
-        <div class="d-flex flex-column">
-          <a href="">
-            <h4>【文章類別】 標題NotoJPBold22級字行距32pt置左</h4>
-          </a>
-          <p class="mt-auto mb-0">2021-11-23</p>
-        </div>
-      </div>
-
-      <div class="article-item">
-        <a href="">
-          <img src="/img//collection/boutique_hotel_slightly_drunk_chill_house_2.webp" alt="">
-        </a>
-        <div class="d-flex flex-column">
-          <a href="">
-            <h4>【文章類別】 標題NotoJPBold22級字行距
-              32pt置左</h4>
-          </a>
-          <p class="mt-auto mb-0">2021-11-23</p>
-        </div>
-      </div> -->
-
-      <a class="nav-link article_readMore" href="#">< 回到成家知識庫</a>
     </div>
+    <a class="nav-link article_readMore" href="/blog_main/">< 回到成家知識庫</a>
   </div>
 
   {{ partial "footer.html" . }}
   {{ partial "scripts.html" . }}
+
+  <script>
+    window.onload = function () {
+      // 取得 apiData
+      let contentsData = [];
+      let category = localStorage.getItem('category');
+
+      (function getContentsData() {
+        // 線上版網址 http://192.53.174.202:9001/api/
+        // 本地端網址 http://localhost:9001/api/
+        fetch('http://localhost:9001/api/contents?url=/blog').then(res => res.json()).then(list => {
+          contentsData = list;
+          console.log('contentsData', contentsData);
+          filterCategory();
+        })
+      })();
+
+      let matchContent = "";
+
+      // 分類篩選
+      function filterCategory() {
+        contentsData.map(item => {
+          if (item.categories) {
+            if (item.categories.includes(category)) {
+              matchContent += `
+            <div class="article-item">
+              <a href="${item.url}">
+                <img src="${item.image}" alt="">
+              </a>
+              <div class="d-flex flex-column">
+                <a href="${item.url}">
+                  <h4>${item.title}</h4>
+                </a>
+                <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
+                <a href="${item.url}" class="description">
+                  <p style="letter-spacing: 1px;">${item.description}</p>
+                </a>
+              </div>
+            </div>`
+            }
+          }
+
+        })
+        document.getElementById("articleList").innerHTML = matchContent;
+      }
+
+      // 搜尋
+      document.getElementById('blog_search').addEventListener("keyup", event => {
+        // 取得輸入框的值
+        let inputVal = $('#blog_search').val();
+        matchContent = "";
+        contentsData.map(item => {
+          // 搜尋特定分類的文章
+          if (item.categories) {
+            if (item.categories.includes(category)) {
+              if (item.title.includes(inputVal) || item.description.includes(inputVal) || item.content.includes(inputVal)) {
+                matchContent += `
+                <div class="article-item">
+                  <a href="${item.url}">
+                    <img src="${item.image}" alt="">
+                  </a>
+                  <div class="d-flex flex-column">
+                    <a href="${item.url}">
+                      <h4>${item.title}</h4>
+                    </a>
+                    <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
+                    <a href="${item.url}" class="description">
+                      <p style="letter-spacing: 1px;">${item.description}</p>
+                    </a>
+                  </div>
+                </div>`
+              }
+            }
+          }
+        })
+        document.getElementById("articleList").innerHTML = matchContent;
+      });
+    }
+  </script>
+
 </body>
 
 </html>

+ 24 - 6
layouts/blog_main/list.html

@@ -150,7 +150,7 @@
                 {{ range $index, $element := first 3 ( where $t.Pages "Params.categories" "認識裝修裝潢") }}
                 {{ if (eq $index 2) }}
                 <div class="btn_box">
-                  <a href="/blog/" class="read_more">
+                  <a href="/blog/" class="read_more" onclick="getCategories('{{ .Params.categories }}')">
                     <p>閱讀更多</p>
                     <img src="/img/blog/readmore.svg" alt="">
                   </a>
@@ -207,7 +207,7 @@
                 {{ range $index, $element := first 3 ( where $t.Pages "Params.categories" "驗收交屋") }}
                 {{ if (eq $index 2) }}
                 <div class="btn_box">
-                  <a href="/blog/" class="read_more">
+                  <a href="/blog/" class="read_more" onclick="getCategories('{{ .Params.categories }}')">
                     <p>閱讀更多</p>
                     <img src="/img/blog/readmore.svg" alt="">
                   </a>
@@ -245,17 +245,20 @@
                   <span>第 3 步:</span>預算準備
                 </h4>
                 <ul>
+                  {{ $t := $.Site.GetPage "/blog" }}
+                  {{ range $index, $element := first 3 ( where $t.Pages "Params.categories" "預算準備") }}
                   <li>
                     <div class="blog_img">
                       <img src="/img/blog/boutique_hotel_slightly_drunk_chill_house_2.webp" alt="">
-                      <img src="/img/blog/points1.png" alt="">
+                      <img src='/img/blog/points{{ add $index 1 }}.png' alt="">
                     </div>
                     <div class="blog_text">
                       <h5>
-                        <a href="">文章標題</a>
+                        <a href="">{{ .Title }}</a>
+                        <span></span>
                       </h5>
                       <p>
-                        內文內文內文內文內文內文內文內文內文內文內文內文內文內文內文內文內文內文...
+                        {{ .Params.description }}
                       </p>
                     </div>
                   </li>
@@ -264,6 +267,21 @@
                       <img src="/img/blog/line.png" alt="">
                     </span>
                   </li>
+                  {{ end }}
+                </ul>
+
+                {{ $t := $.Site.GetPage "/blog" }}
+                {{ range $index, $element := first 3 ( where $t.Pages "Params.categories" "預算準備") }}
+                {{ if (eq $index 2) }}
+                <div class="btn_box">
+                  <a href="/blog/" class="read_more" onclick="getCategories('{{ .Params.categories }}')">
+                    <p>閱讀更多</p>
+                    <img src="/img/blog/readmore.svg" alt="">
+                  </a>
+                  <span></span>
+                </div>
+                {{ end }}
+                {{ end }}
               </section>
             </div>
           </div>
@@ -836,7 +854,7 @@
               {{ range $index, $element := first 3 ( where $t.Pages "Params.categories" "認識裝修裝潢") }}
               {{ if (eq $index 2) }}
               <div class="btn_box">
-                <a href="/blog/" class="read_more">
+                <a href="/blog/" class="read_more" onclick="getCategories('{{ .Params.categories }}')">
                   <p>閱讀更多</p>
                   <img src="/img/blog/readmore.svg" alt="">
                 </a>

+ 5 - 3
themes/hugo-universal-theme-master/static/css/style.bhouse.css

@@ -988,7 +988,8 @@ img {
   padding: 0.35rem 0.35rem;
 }
 
-.bhouseweb_loc_search_box #bhouseweb_search {
+.bhouseweb_loc_search_box #bhouseweb_search,
+.bhouseweb_loc_search_box #blog_search {
   width: 70%;
   background: #565656 !important;
   border: none;
@@ -1000,7 +1001,8 @@ img {
 }
 
 @media screen and (max-width: 767px) {
-  .bhouseweb_loc_search_box #bhouseweb_search {
+  .bhouseweb_loc_search_box #bhouseweb_search,
+.bhouseweb_loc_search_box #blog_search {
     width: 86%;
     font-size: 14.4px;
   }
@@ -3148,7 +3150,7 @@ img {
 .blog-main .article_list .article_item .text_box h4 {
   color: #649e2e;
   font-size: 35px;
-  font-family: NSJP-700;
+  font-family: NSJP-700, -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen, Ubuntu, Cantarell, ‘Open Sans’, ‘Helvetica Neue’, sans-serif;
 }
 @media (max-width: 767px) {
   .blog-main .article_list .article_item .text_box h4 {

File diff suppressed because it is too large
+ 0 - 0
themes/hugo-universal-theme-master/static/css/style.bhouse.css.map


+ 6 - 5
themes/hugo-universal-theme-master/static/css/style.bhouse.scss

@@ -1064,7 +1064,8 @@ img {
   padding: 0.35rem 0.35rem;
 }
 
-.bhouseweb_loc_search_box #bhouseweb_search {
+.bhouseweb_loc_search_box #bhouseweb_search,
+.bhouseweb_loc_search_box #blog_search {
   width: 70%;
   background: #565656 !important;
   border: none;
@@ -1076,7 +1077,8 @@ img {
 }
 
 @media screen and (max-width: 767px) {
-  .bhouseweb_loc_search_box #bhouseweb_search {
+  .bhouseweb_loc_search_box #bhouseweb_search,
+  .bhouseweb_loc_search_box #blog_search {
     width: 86%;
     font-size: 14.4px;
   }
@@ -2751,10 +2753,9 @@ img {
 // }
 
 .blog-categories .article .article-item:last-child {
- border: none;
+  border: none;
 }
 
-
 .blog-categories .article .article-item img {
   width: 240px;
   height: auto;
@@ -3118,7 +3119,7 @@ img {
         h4 {
           color: #649e2e;
           font-size: 35px;
-          font-family: NSJP-700;
+          font-family: NSJP-700, -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen, Ubuntu, Cantarell, ‘Open Sans’, ‘Helvetica Neue’, sans-serif;
           @media (max-width: 767px) {
             font-size: 26px;
           }

+ 7 - 1
themes/hugo-universal-theme-master/static/js/bhouse.js

@@ -230,4 +230,10 @@ $("#collection_icon_fb").attr("href",fb_link);
 let line_link = `http://line.naver.jp/R/msg/text/?${location.href}`;
 let collection_icon_line = document.getElementById('collection_icon_line');
 
-$("#collection_icon_line").attr("href",line_link);
+$("#collection_icon_line").attr("href",line_link);
+
+// blog 分類篩選
+function getCategories(item) {
+  // 將分類名稱儲存至 localStorage
+  localStorage.setItem('category',item);
+}

+ 2 - 0
themes/hugo-universal-theme-master/static/js/cz_filter.js

@@ -38,6 +38,8 @@ function update_info(type, ping, budget, room) {
   var items = []; // 作品集資料清單
 
   // 讀取作品集資料(json)
+  // 線上版網址 http://192.53.174.202:9001/api/
+  // 本地端網址 http://localhost:9001/api/
   fetch('http://192.53.174.202:9001/api/contents?url=/collection')
     .then(response => response.json())
     .then(items => {

Some files were not shown because too many files changed in this diff