瀏覽代碼

update blog

SyuanYu 2 年之前
父節點
當前提交
e63077038d
共有 1 個文件被更改,包括 53 次插入35 次删除
  1. 53 35
      layouts/blog/single.html

+ 53 - 35
layouts/blog/single.html

@@ -71,52 +71,75 @@
     history.back();
   }
 
+  // 延伸閱讀清單
   (function getContentsData() {
     // 線上版網址 https://bhouse3.ptt.cx:9002/api/
     // 本地端網址 http://localhost:9001/api/
     fetch('http://localhost:9001/api/contents?url=/blog').then(res => res.json()).then(list => {
       let title = document.querySelector('h1').innerHTML;
-      let arr = [];
+      let lnkList = [];
 
       list.map(e => {
         // 找出符合標題的文章
-        if (e.meta_title.includes(title)) {
-          let ttlList = JSON.parse(e.readmore_ttl.replace("\/", ""));
-          let lnkList = JSON.parse(e.readmore_lnk.replace("\/", ""));
-          let content = [
-            '<li>你可能會喜歡的,延伸閱讀點擊標題,看更多設計專欄!</li>',
-          ];
-
-          for (let i = 0; i < ttlList.length; i++) {
-            let obj =
-            {
-              ttl: ttlList[i],
-              lnk: lnkList[i]
-            };
-            arr.push(obj);
-          }
+        if (`${e.url}\/` === window.location.pathname) {
+          lnkList = JSON.parse(e.readmore_lnk);
+          // let ttlList = JSON.parse(e.readmore_ttl.replace("\/", ""));
+        }
+      });
 
-          for (let i = 0; i < arr.length; i++) {
-            const item = arr[i];
+      let content = [
+        '<li>你可能會喜歡的,延伸閱讀點擊標題,看更多設計專欄!</li>',
+      ];
+
+      list.map(item => {
+        for (let i = 0; i < lnkList.length; i++) {
+          const link = lnkList[i];
+          if (link == `${item.url}\/`) {
+          /* 分類英文名稱 :
+             預售屋客變 pre-sale-house-design-change
+             驗收交屋 house-acceptance-check
+             預算準備 budget-planning
+             認識裝修裝潢 about-interior-decoration
+             空間計畫 floor-planning
+             居家風格 decoration-style
+             家具家電 furnitures-appliances
+             驗收入住 design-acceptanc-and-move-in */
+
+            let categorieZh = "";
+
+            if (item.categories.includes("pre-sale-house-design-change")) {
+              categorieZh = "預售屋客變";
+            } else if (item.categories.includes("house-acceptance-check")) {
+              categorieZh = "驗收交屋";
+            }else if (item.categories.includes("budget-planning")) {
+              categorieZh = "預算準備";
+            }else if (item.categories.includes("about-interior-decoration")) {
+              categorieZh = "認識裝修裝潢";
+            }else if (item.categories.includes("floor-planning")) {
+              categorieZh = "空間計畫";
+            }else if (item.categories.includes("decoration-style")) {
+              categorieZh = "居家風格";
+            }else if (item.categories.includes("furnitures-appliances")) {
+              categorieZh = "家具家電";
+            }else if (item.categories.includes("design-acceptanc-and-move-in")) {
+              categorieZh = "驗收入住";
+            }
 
-            if (item.ttl !== "") {
-              let dom = `
+            let dom = `
             <li>
-              <a href="${item.lnk}">${item.ttl}</a>
+              <a href="https://bhouse.com.tw/${item.url}">【${categorieZh}】 ${item.title}</a>
             </li>`;
 
-              content.push(dom);
-            }
-          }
-          document.querySelector('.read-more-list').innerHTML = content.join(" ");
-
-          let moreList = document.querySelector('.read-more-list');
-          if (moreList.children.length === 1) {
-            moreList.style.display = 'none';
+            content.push(dom);
           }
         }
-      });
+        document.querySelector('.read-more-list').innerHTML = content.join(" ");
+      })
 
+      let moreList = document.querySelector('.read-more-list');
+      if (moreList.children.length === 1) {
+        moreList.style.display = 'none';
+      }
     })
   })();
 
@@ -127,10 +150,5 @@
       element.style.display = 'none';
     }
   }
-
-  // let moreList = document.querySelector('.read-more-list');
-  // if (moreList.children.length === 1) {
-  //   moreList.style.display = 'none';
-  // }
 </script>
 {{ end }}