taxonomy.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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.webp" 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="/blog_main/">成家知識專欄</a></li>
  20. <li class="breadcrumb-item active" aria-current="page" id="category_name">預售屋客變</li>
  21. </ol>
  22. </nav>
  23. <div class="d-flex flex-column align-items-start">
  24. <!-- 暫時隱藏標籤 -->
  25. <!-- <div class="link-list">
  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. <button><a href="">客房</a></button>
  32. </div> -->
  33. <div class="bhouseweb_loc_search_box">
  34. <form class="bhouseweb_search_form d-flex">
  35. <div class="bhouseweb_search_img" style="margin-right: 1vw;">
  36. <img src="/img/icon_search@2x.png" alt="">
  37. </div>
  38. <input id="blog_search" class="me-md-2" type="search" placeholder="搜尋「預算」「電視牆設計」「天花板」「電器櫃」「沙發」"
  39. aria-label="Search">
  40. </form>
  41. </div>
  42. </div>
  43. </div>
  44. <div style="border-top: 1px solid #969696;"></div>
  45. <div class="article" id="articleList">
  46. <div id="blog-loading" class="d-flex justify-content-center mb-5">
  47. <div class="spinner-border text-success" role="status" style="color: rgba(128, 143, 76, 1) !important;">
  48. <span class="visually-hidden">Loading...</span>
  49. </div>
  50. </div>
  51. {{ $paginator := .Paginate .Data.Pages }}
  52. {{ range $paginator.Pages }}
  53. <!-- <div class="article-item" id="defaultArticle">
  54. <a href="{{ .RelPermalink }}">
  55. <img src="{{ .Params.Image | relURL }}" alt="">
  56. </a>
  57. <div class="d-flex flex-column">
  58. <a href="{{ .RelPermalink }}">
  59. <h4>{{ .Title }}</h4>
  60. </a>
  61. <p class="mt-auto my-2 fw-bold">{{ .PublishDate.Format "2006-01-02" }}</p>
  62. <a href="{{ .RelPermalink }}" class="description">
  63. <p style="letter-spacing: 1px;">{{.Params.description }}</p>
  64. </a>
  65. </div>
  66. </div> -->
  67. {{ end }}
  68. </div>
  69. <a class="nav-link article_readMore" href="/blog_main/">< 回到成家知識庫</a>
  70. <div class="reserve d-flex flex-column">
  71. <a href="https://maac.io/1Pife" target="_blank">
  72. <img src="/img/home/reserve.png" alt="">
  73. </a>
  74. <a href="/store/">
  75. <img src="/img/home/store-reserve.png" alt="">
  76. </a>
  77. </div>
  78. </div>
  79. {{ partial "footer.html" . }}
  80. {{ partial "scripts.html" . }}
  81. <script>
  82. window.onload = function () {
  83. document.getElementById('blog_search').value = '';
  84. // 取得 apiData
  85. let contentsData = [];
  86. // 取得網址參數
  87. let getUrlString = location.href;
  88. let url = new URL(getUrlString);
  89. let tagsVal = url.searchParams.get('tags');
  90. let category = url.pathname.slice(6, -1);
  91. // let category = localStorage.getItem('category');
  92. console.log('網址參數', tagsVal);
  93. console.log('分類名稱', category);
  94. // 麵包屑
  95. if (tagsVal !== null) {
  96. document.getElementById('category_name').textContent = tagsVal;
  97. } else if (category !== null) {
  98. let categoryName = "";
  99. switch (category) {
  100. case 'pre-sale-house-design-change':
  101. categoryName = "預售屋客變";
  102. break;
  103. case 'house-acceptance-check':
  104. categoryName = "驗收交屋";
  105. break;
  106. case 'budget-planning':
  107. categoryName = "預算準備";
  108. break;
  109. case 'about-interior-decoration':
  110. categoryName = "認識裝修裝潢";
  111. break;
  112. case 'floor-planning':
  113. categoryName = "空間計畫";
  114. break;
  115. case 'decoration-style':
  116. categoryName = "居家風格";
  117. break;
  118. case 'furnitures-appliances':
  119. categoryName = "家具家電";
  120. break;
  121. case 'design-acceptanc-and-move-in':
  122. categoryName = "驗收入住";
  123. break;
  124. default:
  125. console.log(`找不到 "${category}" 這個分類`);
  126. document.getElementById('category_name').style.display = 'none';
  127. }
  128. document.getElementById('category_name').textContent = categoryName;
  129. } else {
  130. document.getElementById('category_name').style.display = 'none';
  131. }
  132. (function getContentsData() {
  133. // 線上版網址 https://bhouse3.ptt.cx:9002/api/
  134. // 本地端網址 http://localhost:9001/api/
  135. fetch('http://localhost:9001/api/contents?url=/blog').then(res => res.json()).then(list => {
  136. contentsData = list;
  137. console.log('list',list);
  138. // contentsData.shift();
  139. filterCategory();
  140. // if (category !== null) {
  141. // filterCategory();
  142. // }
  143. })
  144. })();
  145. let matchContent = "";
  146. // 分類篩選
  147. function filterCategory() {
  148. // 網址有參數
  149. console.log('filterCategory');
  150. if (tagsVal !== null) {
  151. contentsData.map(item => {
  152. if (item.draft !== "true") {
  153. if (item.blog_tag) {
  154. if (item.blog_tag.includes(tagsVal)) {
  155. matchContent += `
  156. <div class="article-item">
  157. <a href="${item.url}?tags=${tagsVal}">
  158. <img src="${item.image}" alt="">
  159. </a>
  160. <div class="d-flex flex-column">
  161. <a href="${item.url}?tags=${tagsVal}">
  162. <h4>${item.title}</h4>
  163. </a>
  164. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  165. <a href="${item.url}?tags=${tagsVal}" class="description">
  166. <p style="letter-spacing: 1px;">${item.description}</p>
  167. </a>
  168. </div>
  169. </div>`
  170. }
  171. }
  172. }
  173. })
  174. } else {
  175. contentsData.map(item => {
  176. if (item.draft !== "true") {
  177. if (category !== null) {
  178. if (item.categories) {
  179. if (item.categories.includes(category)) {
  180. matchContent += `
  181. <div class="article-item">
  182. <a href="${item.url}">
  183. <img src="${item.image}" alt="">
  184. </a>
  185. <div class="d-flex flex-column">
  186. <a href="${item.url}">
  187. <h4>${item.title}</h4>
  188. </a>
  189. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  190. <a href="${item.url}" class="description">
  191. <p style="letter-spacing: 1px;">${item.description}</p>
  192. </a>
  193. </div>
  194. </div>`
  195. }
  196. }
  197. } else {
  198. matchContent += `
  199. <div class="article-item">
  200. <a href="${item.url}">
  201. <img src="${item.image}" alt="">
  202. </a>
  203. <div class="d-flex flex-column">
  204. <a href="${item.url}">
  205. <h4>${item.title}</h4>
  206. </a>
  207. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  208. <a href="${item.url}" class="description">
  209. <p style="letter-spacing: 1px;">${item.description}</p>
  210. </a>
  211. </div>
  212. </div>`
  213. }
  214. }
  215. })
  216. }
  217. // contentsData.map(item => {
  218. // if (category !== null) {
  219. // if (item.categories) {
  220. // if (item.categories.includes(category)) {
  221. // matchContent += `
  222. // <div class="article-item">
  223. // <a href="${item.url}">
  224. // <img src="${item.image}" alt="">
  225. // </a>
  226. // <div class="d-flex flex-column">
  227. // <a href="${item.url}">
  228. // <h4>${item.title}</h4>
  229. // </a>
  230. // <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  231. // <a href="${item.url}" class="description">
  232. // <p style="letter-spacing: 1px;">${item.description}</p>
  233. // </a>
  234. // </div>
  235. // </div>`
  236. // }
  237. // }
  238. // } else {
  239. // matchContent += `
  240. // <div class="article-item">
  241. // <a href="${item.url}">
  242. // <img src="${item.image}" alt="">
  243. // </a>
  244. // <div class="d-flex flex-column">
  245. // <a href="${item.url}">
  246. // <h4>${item.title}</h4>
  247. // </a>
  248. // <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  249. // <a href="${item.url}" class="description">
  250. // <p style="letter-spacing: 1px;">${item.description}</p>
  251. // </a>
  252. // </div>
  253. // </div>`
  254. // }
  255. // })
  256. $('#blog-loading').addClass("blog_loading");
  257. document.getElementById("articleList").innerHTML = matchContent;
  258. }
  259. // 增加延遲(待輸入完成後再進行搜尋)
  260. function delay(fn, ms) {
  261. let timer = 0
  262. return function (...args) {
  263. clearTimeout(timer)
  264. timer = setTimeout(fn.bind(this, ...args), ms || 0)
  265. }
  266. }
  267. // 搜尋
  268. $('#blog_search').keyup(delay(function (e) {
  269. console.log('blog_search');
  270. // 搜尋全部文章需移除分類麵包屑
  271. document.getElementById('category_name').style.display = 'none';
  272. // 取得輸入框的值
  273. let inputVal = $('#blog_search').val();
  274. matchContent = "";
  275. let draftItem = []; // 草稿 (draft: true)
  276. let falseItem = []; // 不符合搜尋條件文章
  277. contentsData.map((item, index) => {
  278. // 搜尋特定分類文章
  279. // if (item.categories) {
  280. // if (item.categories.includes(category)) {
  281. // 搜尋所有分類文章
  282. if (item.draft !== "true") {
  283. if (item.url !== '/blog') {
  284. if (item.title.includes(inputVal) || item.description.includes(inputVal) || item.content.includes(inputVal)) {
  285. matchContent += `
  286. <div class="article-item">
  287. <a href="${item.url}">
  288. <img src="${item.image}" alt="">
  289. </a>
  290. <div class="d-flex flex-column">
  291. <a href="${item.url}">
  292. <h4>${item.title}</h4>
  293. </a>
  294. <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
  295. <a href="${item.url}" class="description">
  296. <p style="letter-spacing: 1px;">${item.description}</p>
  297. </a>
  298. </div>
  299. </div>`
  300. } else {
  301. falseItem.push(item);
  302. }
  303. }
  304. } else {
  305. draftItem.push(item); // 草稿
  306. }
  307. if (falseItem.length === (contentsData.length - draftItem.length) - 1) {
  308. matchContent = `
  309. <div class="alert d-flex align-items-center" role="alert" style="max-width: 300px;margin: 0 auto 25px;justify-content: center;">
  310. <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:">
  311. <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"/>
  312. </svg>
  313. <div>
  314. 找不到符合條件的文章
  315. </div>
  316. </div>
  317. `;
  318. }
  319. // }
  320. // }
  321. })
  322. document.getElementById("articleList").innerHTML = matchContent;
  323. }, 500));
  324. }
  325. </script>
  326. </body>
  327. </html>