|
@@ -92,18 +92,24 @@
|
|
|
// 取得 apiData
|
|
|
let contentsData = [];
|
|
|
let category = localStorage.getItem('category');
|
|
|
+ // 取得網址參數
|
|
|
+ let getUrlString = location.href;
|
|
|
+ let url = new URL(getUrlString);
|
|
|
+ let tagsVal = url.searchParams.get('tags');
|
|
|
|
|
|
- if (category !== null) {
|
|
|
+ // 麵包屑
|
|
|
+ if (tagsVal !== null) {
|
|
|
+ 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() {
|
|
|
- // 線上版網址 http://192.53.174.202:9001/api/
|
|
|
+ // 線上版網址 https://bhouse3.ptt.cx:9002/api/
|
|
|
// 本地端網址 http://localhost:9001/api/
|
|
|
- fetch('https://bhouse2.ptt.cx:9002/api/contents?url=/blog').then(res => res.json()).then(list => {
|
|
|
+ fetch('https://bhouse3.ptt.cx:9002/api/contents?url=/blog').then(res => res.json()).then(list => {
|
|
|
contentsData = list;
|
|
|
// contentsData.shift();
|
|
|
filterCategory();
|
|
@@ -117,11 +123,39 @@
|
|
|
|
|
|
// 分類篩選
|
|
|
function filterCategory() {
|
|
|
- contentsData.map(item => {
|
|
|
- if (category !== null) {
|
|
|
- if (item.categories) {
|
|
|
- if (item.categories.includes(category)) {
|
|
|
+ // 網址有參數
|
|
|
+ if (tagsVal !== null) {
|
|
|
+ contentsData.map(item => {
|
|
|
+ console.log('item', item);
|
|
|
+ console.log('item', item.blog_tag);
|
|
|
+ if (item.blog_tag) {
|
|
|
+ if (item.blog_tag.includes(tagsVal)) {
|
|
|
+ console.log('符合');
|
|
|
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 {
|
|
|
+ console.log('網址沒參數');
|
|
|
+ contentsData.map(item => {
|
|
|
+ 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="">
|
|
@@ -136,10 +170,10 @@
|
|
|
</a>
|
|
|
</div>
|
|
|
</div>`
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- } else {
|
|
|
- matchContent += `
|
|
|
+ } else {
|
|
|
+ matchContent += `
|
|
|
<div class="article-item">
|
|
|
<a href="${item.url}">
|
|
|
<img src="${item.image}" alt="">
|
|
@@ -154,8 +188,49 @@
|
|
|
</a>
|
|
|
</div>
|
|
|
</div>`
|
|
|
- }
|
|
|
- })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // contentsData.map(item => {
|
|
|
+ // 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;
|
|
|
|
|
@@ -204,7 +279,7 @@
|
|
|
falseItem.push(item);
|
|
|
}
|
|
|
|
|
|
- if (falseItem.length === contentsData.length-1) {
|
|
|
+ if (falseItem.length === contentsData.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:">
|