-
Notifications
You must be signed in to change notification settings - Fork 1
/
blog.html
85 lines (66 loc) · 2.7 KB
/
blog.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Blog Index</title>
<link rel="stylesheet" href="css/blog.css">
<link rel="stylesheet" href="css/style.default.css">
</head>
<body>
<div class="container">
<h1>Blog Index</h1>
<div class="tab" onclick="filterCategory('all')">All</div>
<div class="tab" onclick="filterCategory('OTEL')">OTEL</div>
<div class="tab" onclick="filterCategory('CICD')">CICD</div>
<div class="blog-box">
<ul class="blog-list" id="blogList">
<!-- Blog items will be dynamically added here -->
</ul>
</div>
</div>
<script>
function filterCategory(category) {
var blogItems = document.querySelectorAll('.blog-item');
blogItems.forEach(function (item) {
var itemCategory = item.getAttribute('data-category');
if (category === 'all' || category === itemCategory) {
item.style.display = 'block';
} else {
item.style.display = 'none';
}
});
}
// Fetch blog list from the JSON API
fetch('blog-list.json')
.then(response => response.json())
.then(data => {
// Sort the data by date in descending order
data.sort((a, b) => new Date(b.date) - new Date(a.date));
var blogList = document.getElementById('blogList');
data.forEach(blog => {
var listItem = document.createElement('li');
listItem.classList.add('blog-item');
listItem.setAttribute('data-category', blog.category);
var title = document.createElement('div');
title.classList.add('blog-title');
// Create a hyperlink
var link = document.createElement('a');
link.href = blog.href;
link.textContent = blog.title;
title.appendChild(link);
var date = document.createElement('div');
date.classList.add('blog-date');
date.textContent = 'Published on ' + blog.date;
listItem.appendChild(title);
listItem.appendChild(date);
blogList.appendChild(listItem);
});
})
.catch(error => console.error('Error fetching blog list:', error));
</script>
</body>
<footer align="center">
<p><a href="/" style="color: black;">Home</a></p>
</footer>
</html>