list.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. {{ partial "headers.html" . }}
  5. </head>
  6. <body style="overflow-x: hidden;">
  7. {{ partial "nav.html" . }}
  8. <div class="container-fluid blog-categories p-0">
  9. <section class="bhouseweb_loc_banner">
  10. <img src="/img/banner/bn_blog@2x.png" class="banner-img card-img" alt="...">
  11. </section>
  12. <div class="container">
  13. <nav
  14. 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;);"
  15. aria-label="breadcrumb">
  16. <ol class="breadcrumb">
  17. <li class="breadcrumb-item"><a href="#"><img src="/img/bt_footer_index@2x.png" width="30px" alt=""
  18. style="margin-bottom: 5px;"></a></li>
  19. <li class="breadcrumb-item"><a href="#">成家知識專欄</a></li>
  20. <li class="breadcrumb-item active" aria-current="page">預售屋客變</li>
  21. </ol>
  22. </nav>
  23. <div class="d-flex flex-column align-items-start">
  24. <div class="link-list">
  25. <button><a href="">客廳</a></button>
  26. <button><a href="">主臥</a></button>
  27. <button><a href="">客房</a></button>
  28. <button><a href="">客廳</a></button>
  29. <button><a href="">主臥</a></button>
  30. <button><a href="">客房</a></button>
  31. </div>
  32. <div class="bhouseweb_loc_search_box">
  33. <form class="bhouseweb_search_form d-flex">
  34. <div class="bhouseweb_search_img" style="margin-right: 1vw;">
  35. <img src="/img/icon_search@2x.png" alt="">
  36. </div>
  37. <input id="blog_search" class="me-md-2" type="search" placeholder="搜尋「客變」「工業風」「三代同堂」" aria-label="Search">
  38. </form>
  39. </div>
  40. </div>
  41. </div>
  42. <div style="border-top: 1px solid #969696;"></div>
  43. <!-- <div class="alert d-flex align-items-center" role="alert" style="max-width: 300px;margin: auto;justify-content: center;">
  44. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" style="color: #808e4c;" viewBox="0 0 16 16" role="img" aria-label="Warning:">
  45. <path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
  46. </svg>
  47. <div>
  48. 找不到符合條件的文章
  49. </div>
  50. </div> -->
  51. <div class="article" id="articleList">
  52. {{ $paginator := .Paginate .Data.Pages }}
  53. {{ range $paginator.Pages }}
  54. <div class="article-item">
  55. <a href="{{ .RelPermalink }}">
  56. <img src="{{ .Params.Image | relURL }}" alt="">
  57. </a>
  58. <div class="d-flex flex-column">
  59. <a href="{{ .RelPermalink }}">
  60. <h4>{{ .Title }}</h4>
  61. </a>
  62. <p class="mt-auto my-2 fw-bold">{{ .PublishDate.Format "2006-01-02" }}</p>
  63. <a href="{{ .RelPermalink }}" class="description">
  64. <p style="letter-spacing: 1px;">{{.Params.description }}</p>
  65. </a>
  66. <!-- <p style="color:#4D4D4D;">{{ .Summary }}</p> -->
  67. </div>
  68. </div>
  69. {{ end }}
  70. </div>
  71. <a class="nav-link article_readMore" href="/blog_main/">< 回到成家知識庫</a>
  72. </div>
  73. {{ partial "footer.html" . }}
  74. {{ partial "scripts.html" . }}
  75. <script>
  76. window.onload = function () {
  77. document.getElementById('blog_search').value = '';
  78. // 取得 apiData
  79. let contentsData = [];
  80. let category = localStorage.getItem('category');
  81. (function getContentsData() {
  82. // 線上版網址 http://192.53.174.202:9001/api/
  83. // 本地端網址 http://localhost:9001/api/
  84. fetch('http://localhost:9001/api/contents?url=/blog').then(res => res.json()).then(list => {
  85. contentsData = list;
  86. console.log('contentsData', contentsData);
  87. if (category !== null) {
  88. filterCategory();
  89. }
  90. })
  91. })();
  92. let matchContent = "";
  93. // 分類篩選
  94. function filterCategory() {
  95. contentsData.map(item => {
  96. if (item.categories) {
  97. if (item.categories.includes(category)) {
  98. matchContent += `
  99. <div class="article-item">
  100. <a href="${item.url}">
  101. <img src="${item.image}" alt="">
  102. </a>
  103. <div class="d-flex flex-column">
  104. <a href="${item.url}">
  105. <h4>${item.title}</h4>
  106. </a>
  107. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  108. <a href="${item.url}" class="description">
  109. <p style="letter-spacing: 1px;">${item.description}</p>
  110. </a>
  111. </div>
  112. </div>`
  113. }
  114. }
  115. })
  116. document.getElementById("articleList").innerHTML = matchContent;
  117. }
  118. // 增加延遲(待輸入完成後再進行搜尋)
  119. function delay(fn, ms) {
  120. let timer = 0
  121. return function (...args) {
  122. clearTimeout(timer)
  123. timer = setTimeout(fn.bind(this, ...args), ms || 0)
  124. }
  125. }
  126. // 搜尋
  127. $('#blog_search').keyup(delay(function (e) {
  128. // 取得輸入框的值
  129. let inputVal = $('#blog_search').val();
  130. matchContent = "";
  131. let falseItem = [];
  132. contentsData.map((item, index) => {
  133. // 搜尋特定分類文章
  134. // if (item.categories) {
  135. // if (item.categories.includes(category)) {
  136. // 搜尋所有分類文章
  137. if (item.title.includes(inputVal) || item.description.includes(inputVal) || item.content.includes(inputVal)) {
  138. matchContent += `
  139. <div class="article-item">
  140. <a href="${item.url}">
  141. <img src="${item.image}" alt="">
  142. </a>
  143. <div class="d-flex flex-column">
  144. <a href="${item.url}">
  145. <h4>${item.title}</h4>
  146. </a>
  147. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  148. <a href="${item.url}" class="description">
  149. <p style="letter-spacing: 1px;">${item.description}</p>
  150. </a>
  151. </div>
  152. </div>`
  153. } else {
  154. falseItem.push(item);
  155. }
  156. if (falseItem.length === contentsData.length) {
  157. matchContent = `
  158. <div class="alert d-flex align-items-center" role="alert" style="max-width: 300px;margin: 0 auto 25px;justify-content: center;">
  159. <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-exclamation-triangle-fill flex-shrink-0 me-2" style="color: #808e4c;" viewBox="0 0 16 16" role="img" aria-label="Warning:">
  160. <path d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
  161. </svg>
  162. <div>
  163. 找不到符合條件的文章
  164. </div>
  165. </div>
  166. `;
  167. }
  168. // }
  169. // }
  170. })
  171. document.getElementById("articleList").innerHTML = matchContent;
  172. }, 500));
  173. }
  174. </script>
  175. </body>
  176. </html>