123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- {{ partial "headers.html" . }}
- </head>
- <body style="overflow-x: hidden;">
- {{ partial "nav.html" . }}
- <div class="container-fluid blog-categories p-0">
- <section class="bhouseweb_loc_banner">
- <img src="/img/banner/bn_blog@2x.webp" class="banner-img card-img" alt="...">
- </section>
- <div class="container">
- <nav
- style="--bs-breadcrumb-divider: url("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");"
- 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="/blog_main/">成家知識專欄</a></li>
- <li class="breadcrumb-item active" aria-current="page" id="category_name">預售屋客變</li>
- </ol>
- </nav>
- <div class="d-flex flex-column align-items-start">
- <!-- 暫時隱藏標籤 -->
- <!-- <div class="link-list">
- <button><a href="">客廳</a></button>
- <button><a href="">主臥</a></button>
- <button><a href="">客房</a></button>
- <button><a href="">客廳</a></button>
- <button><a href="">主臥</a></button>
- <button><a href="">客房</a></button>
- </div> -->
- <div class="bhouseweb_loc_search_box">
- <form class="bhouseweb_search_form d-flex">
- <div class="bhouseweb_search_img" style="margin-right: 1vw;">
- <img src="/img/icon_search@2x.png" alt="">
- </div>
- <input id="blog_search" class="me-md-2" type="search" placeholder="搜尋「預算」「電視牆設計」「天花板」「電器櫃」「沙發」"
- aria-label="Search">
- </form>
- </div>
- </div>
- </div>
- <div style="border-top: 1px solid #969696;"></div>
- <div class="article" id="articleList">
- <div id="blog-loading" class="d-flex justify-content-center mb-5">
- <div class="spinner-border text-success" role="status" style="color: rgba(128, 143, 76, 1) !important;">
- <span class="visually-hidden">Loading...</span>
- </div>
- </div>
- {{ $paginator := .Paginate .Data.Pages }}
- {{ range $paginator.Pages }}
- <!-- <div class="article-item" id="defaultArticle">
- <a href="{{ .RelPermalink }}">
- <img src="{{ .Params.Image | relURL }}" alt="">
- </a>
- <div class="d-flex flex-column">
- <a href="{{ .RelPermalink }}">
- <h4>{{ .Title }}</h4>
- </a>
- <p class="mt-auto my-2 fw-bold">{{ .PublishDate.Format "2006-01-02" }}</p>
- <a href="{{ .RelPermalink }}" class="description">
- <p style="letter-spacing: 1px;">{{.Params.description }}</p>
- </a>
- </div>
- </div> -->
- {{ end }}
- </div>
- <a class="nav-link article_readMore" href="/blog_main/">< 回到成家知識庫</a>
- <div class="reserve d-flex flex-column">
- <a href="https://maac.io/1Pife" target="_blank">
- <img src="/img/bhousev2_img/LINE-CONTACT.png" alt="">
- </a>
- <!-- <a href="/store/">
- <img src="/img/home/store-reserve.png" alt="">
- </a> -->
- </div>
- </div>
- {{ partial "footer.html" . }}
- {{ partial "scripts.html" . }}
- <script>
- window.onload = function () {
- document.getElementById('blog_search').value = '';
- // 取得 apiData
- let contentsData = [];
- // let category = localStorage.getItem('category');
- // console.log('分類名稱', category);
- // 取得網址參數
- let getUrlString = location.href;
- let url = new URL(getUrlString);
- let tagsVal = url.searchParams.get('tags');
- let category = "";
- if (url.pathname === '/blog/') {
- document.getElementById('category_name').style.display = 'none';
- } else {
- category = url.pathname.slice(6, -1);
- }
- // 麵包屑
- if (tagsVal !== null) {
- document.getElementById('category_name').style.display = 'block';
- document.getElementById('category_name').textContent = tagsVal;
- } else if (category !== null) {
- document.getElementById('category_name').textContent = category;
- } else {
- document.getElementById('category_name').style.display = 'none';
- }
- (function getContentsData() {
- // 線上版網址 https://bhouse3.ptt.cx:9002/api/
- // 本地端網址 http://localhost:9001/api/
- fetch('https://bhouse3.ptt.cx:9002/api/contents?url=/blog').then(res => res.json()).then(list => {
- contentsData = list;
- // contentsData.shift();
- filterCategory();
- // if (category !== null) {
- // filterCategory();
- // }
- })
- })();
- let matchContent = "";
- // 分類篩選
- function filterCategory() {
- // 網址有參數
- if (tagsVal !== null) {
- contentsData.map(item => {
- if (item.draft !== "true") {
- if (item.blog_tag) {
- if (item.blog_tag.includes(tagsVal)) {
- matchContent += `
- <div class="article-item">
- <a href="${item.url}?tags=${tagsVal}">
- <img src="${item.image}" alt="">
- </a>
- <div class="d-flex flex-column">
- <a href="${item.url}?tags=${tagsVal}">
- <h4>${item.title}</h4>
- </a>
- <p class="mt-auto my-2 fw-bold">${item.date.substr(0, 10)}</p>
- <a href="${item.url}?tags=${tagsVal}" class="description">
- <p style="letter-spacing: 1px;">${item.description}</p>
- </a>
- </div>
- </div>`
- }
- }
- }
- })
- } else if (url.pathname === '/blog/') {
- contentsData.map(item => {
- if (item.draft !== "true") {
- // 排除根目錄
- if (item.url !== "/blog") {
- 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>`
- }
- }
- }
- )
- } else {
- // 網址沒有參數
- contentsData.map(item => {
- if (item.draft !== "true") {
- if (category !== null) {
- 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>`
- }
- }
- } else {
- 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>`
- }
- }
- })
- }
- $('#blog-loading').addClass("blog_loading");
- document.getElementById("articleList").innerHTML = matchContent;
- }
- // 增加延遲(待輸入完成後再進行搜尋)
- function delay(fn, ms) {
- let timer = 0
- return function (...args) {
- clearTimeout(timer)
- timer = setTimeout(fn.bind(this, ...args), ms || 0)
- }
- }
- // 搜尋
- $('#blog_search').keyup(delay(function (e) {
- // 搜尋全部文章需移除分類麵包屑
- document.getElementById('category_name').style.display = 'none';
- // 取得輸入框的值
- let inputVal = $('#blog_search').val();
- matchContent = "";
- let draftItem = []; // 草稿 (draft: true)
- let falseItem = []; // 不符合搜尋條件文章
- contentsData.map((item, index) => {
- // 搜尋特定分類文章
- // if (item.categories) {
- // if (item.categories.includes(category)) {
- // 搜尋所有分類文章
- if (item.draft !== "true") {
- if (item.url !== '/blog') {
- 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>`
- } else {
- falseItem.push(item);
- }
- }
- } else {
- draftItem.push(item); // 草稿
- }
- if (falseItem.length === (contentsData.length - draftItem.length) - 1) {
- matchContent = `
- <div class="alert d-flex align-items-center" role="alert" style="max-width: 300px;margin: 0 auto 25px;justify-content: center;">
- <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:">
- <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"/>
- </svg>
- <div>
- 找不到符合條件的文章
- </div>
- </div>
- `;
- }
- // }
- // }
- })
- document.getElementById("articleList").innerHTML = matchContent;
- }, 500));
- }
- </script>
- </body>
- </html>
|