-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (62 loc) · 2.34 KB
/
script.js
File metadata and controls
73 lines (62 loc) · 2.34 KB
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
// Interactive hover effects and simple animations
const blogPosts = document.querySelectorAll('.blog-post');
blogPosts.forEach(post => {
post.addEventListener('mouseenter', () => {
post.style.boxShadow = '0 10px 20px rgba(0,0,0,0.4)';
});
post.addEventListener('mouseleave', () => {
post.style.boxShadow = '0 4px 6px rgba(0,0,0,0.2)';
});
});
// Simple responsive menu toggle for smaller screens
const navLinks = document.querySelector('nav');
const menuToggle = document.createElement('button');
menuToggle.textContent = '☰';
menuToggle.style.display = 'none';
if (window.innerWidth <= 768) {
menuToggle.style.display = 'block';
navLinks.style.display = 'none';
menuToggle.addEventListener('click', () => {
navLinks.style.display = navLinks.style.display === 'none' ? 'block' : 'none';
});
}
// Fetch the JSON file
fetch('./data.json')
.then(response => {
if (!response.ok) {
throw new Error('Failed to fetch blog data');
}
return response.json();
})
.then(data => {
// Call the function to render blog posts
renderBlogPosts(data);
})
.catch(error => {
console.error('Error:', error);
});
// Function to render blog posts
function renderBlogPosts(posts) {
const container = document.getElementById('blog-container'); // Get the container element
// Loop through each post in the data
posts.forEach(post => {
// Create a blog post div
const blogPost = document.createElement('div');
blogPost.className = 'blog-post';
// Create and append the title as a link
const titleLink = document.createElement('a');
titleLink.href = post.filename; // Set the href to the filename
titleLink.textContent = post.title; // Set the text content to the title
titleLink.style.textDecoration = 'none'; // Optional: Add some style to remove the underline
titleLink.style.color = 'inherit'; // Optional: Make the link inherit text color
const title = document.createElement('h2');
title.appendChild(titleLink); // Append the link to the title
blogPost.appendChild(title);
// Create and append the description
const description = document.createElement('p');
description.textContent = post.description;
blogPost.appendChild(description);
// Append the blog post to the container
container.appendChild(blogPost);
});
}