-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
188 lines (168 loc) · 6.88 KB
/
main.js
File metadata and controls
188 lines (168 loc) · 6.88 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Navigation Menu Toggle
document.addEventListener('DOMContentLoaded', () => {
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
menuToggle?.addEventListener('click', () => {
navLinks.classList.toggle('active');
// Animate hamburger menu
const spans = menuToggle.querySelectorAll('span');
spans.forEach(span => span.classList.toggle('active'));
});
// Sample blog posts data with full content
const blogPosts = [
{
id: 1,
title: 'Getting Started with Linux',
excerpt: 'A beginner\'s guide to installing and using Linux...',
content: `
<p>Linux is a powerful and versatile operating system that offers users complete control over their computing environment. This guide will walk you through the basics of getting started with Linux.</p>
<h2>Choosing a Distribution</h2>
<p>For beginners, we recommend starting with Ubuntu or Linux Mint. These distributions offer:</p>
<ul>
<li>User-friendly interfaces</li>
<li>Large community support</li>
<li>Extensive documentation</li>
<li>Regular updates</li>
</ul>
<h2>Installation Process</h2>
<p>The installation process is straightforward:</p>
<ol>
<li>Download the ISO file</li>
<li>Create a bootable USB drive</li>
<li>Boot from the USB drive</li>
<li>Follow the installation wizard</li>
</ol>
`,
date: '2024-02-20',
category: 'Tutorials',
author: 'John Doe',
image: 'https://via.placeholder.com/800x400'
},
{
id: 2,
title: 'Why Open Source Matters',
excerpt: 'Exploring the importance of open source software...',
content: `
<p>Open source software has revolutionized the technology industry and continues to shape our digital future.</p>
<h2>The Power of Collaboration</h2>
<p>Open source enables developers worldwide to collaborate, innovate, and build better software together.</p>
`,
date: '2024-02-18',
category: 'Opinion',
author: 'Jane Smith',
image: 'https://via.placeholder.com/800x400'
},
// Add more blog posts...
];
// Populate blog grid
const blogGrid = document.getElementById('blog-grid');
if (blogGrid) {
blogPosts.forEach(post => {
const postElement = createBlogPostCard(post);
blogGrid.appendChild(postElement);
});
}
// Handle blog post page
const postContent = document.getElementById('post-content');
if (postContent) {
const urlParams = new URLSearchParams(window.location.search);
const postId = parseInt(urlParams.get('id'));
const post = blogPosts.find(p => p.id === postId);
if (post) {
document.title = `${post.title} - GLUG`;
document.getElementById('post-category').textContent = post.category;
document.getElementById('post-title').textContent = post.title;
document.getElementById('post-date').textContent = formatDate(post.date);
document.getElementById('post-author').textContent = `By ${post.author}`;
postContent.innerHTML = post.content;
}
}
// Blog filters
const filterButtons = document.querySelectorAll('.filter-button');
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
const category = button.textContent;
if (blogGrid) {
blogGrid.innerHTML = '';
const filteredPosts = category === 'All'
? blogPosts
: blogPosts.filter(post => post.category === category);
filteredPosts.forEach(post => {
const postElement = createBlogPostCard(post);
blogGrid.appendChild(postElement);
});
}
});
});
// FAQ Accordion
const faqItems = document.querySelectorAll('.faq-item');
faqItems.forEach(item => {
const question = item.querySelector('.faq-question');
question?.addEventListener('click', () => {
const isActive = item.classList.contains('active');
// Close all FAQ items
faqItems.forEach(faqItem => {
faqItem.classList.remove('active');
});
// Open clicked item if it wasn't active
if (!isActive) {
item.classList.add('active');
}
});
});
});
// Create blog post card
function createBlogPostCard(post) {
const article = document.createElement('article');
article.className = 'blog-post';
article.innerHTML = `
<img src="${post.image}" alt="${post.title}" class="blog-post-image">
<div class="blog-post-content">
<div class="blog-post-category">${post.category}</div>
<h3 class="blog-post-title">${post.title}</h3>
<p class="blog-post-excerpt">${post.excerpt}</p>
<div class="blog-post-meta">
<time datetime="${post.date}">${formatDate(post.date)}</time>
<a href="blog-post.html?id=${post.id}" class="read-more">Read More →</a>
</div>
</div>
`;
return article;
}
// Format date
function formatDate(dateString) {
const options = { year: 'numeric', month: 'long', day: 'numeric' };
return new Date(dateString).toLocaleDateString('en-US', options);
}
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add scroll-based animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, observerOptions);
document.querySelectorAll('.feature-card, .post-card, .feature-item, .blog-post').forEach(element => {
observer.observe(element);
});