list.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="article" id="articleList">
  44. {{ $paginator := .Paginate .Data.Pages }}
  45. {{ range $paginator.Pages }}
  46. <div class="article-item">
  47. <a href="{{ .RelPermalink }}">
  48. <img src="{{ .Params.Image | relURL }}" alt="">
  49. </a>
  50. <div class="d-flex flex-column">
  51. <a href="{{ .RelPermalink }}">
  52. <h4>{{ .Title }}</h4>
  53. </a>
  54. <p class="mt-auto my-2 fw-bold">{{ .PublishDate.Format "2006-01-02" }}</p>
  55. <a href="{{ .RelPermalink }}" class="description">
  56. <p style="letter-spacing: 1px;">{{.Params.description }}</p>
  57. </a>
  58. <!-- <p style="color:#4D4D4D;">{{ .Summary }}</p> -->
  59. </div>
  60. </div>
  61. {{ end }}
  62. </div>
  63. <a class="nav-link article_readMore" href="/blog_main/">< 回到成家知識庫</a>
  64. </div>
  65. {{ partial "footer.html" . }}
  66. {{ partial "scripts.html" . }}
  67. <script>
  68. window.onload = function () {
  69. // 取得 apiData
  70. let contentsData = [];
  71. let category = localStorage.getItem('category');
  72. (function getContentsData() {
  73. // 線上版網址 http://192.53.174.202:9001/api/
  74. // 本地端網址 http://localhost:9001/api/
  75. fetch('http://localhost:9001/api/contents?url=/blog').then(res => res.json()).then(list => {
  76. contentsData = list;
  77. console.log('contentsData', contentsData);
  78. filterCategory();
  79. })
  80. })();
  81. let matchContent = "";
  82. // 分類篩選
  83. function filterCategory() {
  84. contentsData.map(item => {
  85. if (item.categories) {
  86. if (item.categories.includes(category)) {
  87. matchContent += `
  88. <div class="article-item">
  89. <a href="${item.url}">
  90. <img src="${item.image}" alt="">
  91. </a>
  92. <div class="d-flex flex-column">
  93. <a href="${item.url}">
  94. <h4>${item.title}</h4>
  95. </a>
  96. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  97. <a href="${item.url}" class="description">
  98. <p style="letter-spacing: 1px;">${item.description}</p>
  99. </a>
  100. </div>
  101. </div>`
  102. }
  103. }
  104. })
  105. document.getElementById("articleList").innerHTML = matchContent;
  106. }
  107. // 增加延遲(待輸入完成後再進行搜尋)
  108. function delay(fn, ms) {
  109. let timer = 0
  110. return function (...args) {
  111. clearTimeout(timer)
  112. timer = setTimeout(fn.bind(this, ...args), ms || 0)
  113. }
  114. }
  115. // 搜尋
  116. $('#blog_search').keyup(delay(function (e) {
  117. console.log('Time elapsed!', this.value);
  118. // 取得輸入框的值
  119. let inputVal = $('#blog_search').val();
  120. matchContent = "";
  121. contentsData.map(item => {
  122. // 搜尋特定分類文章
  123. // if (item.categories) {
  124. // if (item.categories.includes(category)) {
  125. // 搜尋所有分類文章
  126. if (item.title.includes(inputVal) || item.description.includes(inputVal) || item.content.includes(inputVal)) {
  127. matchContent += `
  128. <div class="article-item">
  129. <a href="${item.url}">
  130. <img src="${item.image}" alt="">
  131. </a>
  132. <div class="d-flex flex-column">
  133. <a href="${item.url}">
  134. <h4>${item.title}</h4>
  135. </a>
  136. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  137. <a href="${item.url}" class="description">
  138. <p style="letter-spacing: 1px;">${item.description}</p>
  139. </a>
  140. </div>
  141. </div>`
  142. }
  143. // }
  144. // }
  145. })
  146. document.getElementById("articleList").innerHTML = matchContent;
  147. }, 500));
  148. }
  149. </script>
  150. </body>
  151. </html>