-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.html
151 lines (120 loc) · 5.79 KB
/
news.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CinemaPeedika</title>
<link rel="stylesheet" href="assets/CSS/styles.css">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/images/favicon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/assets/images/favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/assets/images/favicon/favicon-16x16.png">
<link rel="manifest" href="/assets/images/favicon/site.webmanifest">
</head>
<body >
<!-- ============= HEADER ============ -->
<header>
<div class="navbar">
<div class="logo">
<a href="index.html">
<img src="assets/images/Cinema Peedika Logo (1).png" alt="Cinema Peedika Logo">
</a>
</div>
<div class="nav-items">
<ul class="nav-links">
<li><a href="index.html">Movies</a></li>
<li><a href="news.html">News</a></li>
<li><a href="booktickets.html">Book Tickets</a></li>
<li><input class="search" type="text" placeholder="Search"></li>
<li>
<a href="signin.html"><button class="signup-button homepage-signin-btn username-show"
type="submit" id="signin-button"></button>
</a>
</li>
</ul>
</div>
</div>
</header>
<section>
<div class="news-container">
<h2>Latest News</h2>
</div>
</section>
<!-- Footer -->
<footer class="site-footer">
<div class="footer-content">
<p>© 2023 CinemaPeedika. All Rights Reserved.</p>
<div class="footer-links">
<ul>
<li><a href="#">Movies</a></li>
<li><a href="news.html">News</a></li>
<li><a href="booktickets.html">Book Tickets</a></li>
</ul>
</div>
<div class="developer-info">
<a href="https://github.com/safadtm" target="_blank">
<p>Developed by Safad TM</p>
<img src="assets/images/icons/github-mark-white.png">
</a>
</div>
</div>
</footer>
<script>
// Assuming you have retrieved the username from local storage
const storedUser = JSON.parse(localStorage.getItem('user')); // Retrieve user data from localStorage
const username = storedUser ? storedUser.username : null; // Get the username if available
console.log(username);
// Get the element with the class name 'username-show'
const usernameShow = document.querySelector('.username-show');
// Update the content of the element based on the presence of the username
if (!storedUser) {
usernameShow.textContent = `New User?`;
}
else if (username) {
usernameShow.textContent = `Welcome, ${username}!`; // Change the content to display the username
} else {
usernameShow.textContent = 'Welcome, User!'; // Set a default message for users without a username
}
// Function to fetch news data and populate HTML
function fetchAndPopulateNews() {
fetch('assets/JSON/news.json')
.then(response => response.json())
.then(newsData => {
const newsContainer = document.querySelector('.news-container');
newsData.forEach(news => {
const newsItem = document.createElement('div');
newsItem.classList.add('news-item');
const newsImg = document.createElement('img');
newsImg.src = news.imgSrc;
newsImg.alt = 'News Image';
const newsDetails = document.createElement('div');
newsDetails.classList.add('news-details');
const newsLink = document.createElement('a');
newsLink.href = `news_details.html?id=${news.id}`; // Redirects to specific news details page
const newsHeadline = document.createElement('h1');
newsHeadline.textContent = news.headline;
newsLink.appendChild(newsHeadline);
const dateInfo = document.createElement('p');
dateInfo.classList.add('date-info');
const clockIcon = document.createElement('img');
clockIcon.src = 'assets/images/icons/clock.png';
clockIcon.classList.add('clock-icon');
clockIcon.alt = 'Clock Icon';
const dateText = document.createTextNode(news.date);
dateInfo.appendChild(clockIcon);
dateInfo.appendChild(dateText);
newsDetails.appendChild(newsLink);
newsDetails.appendChild(dateInfo);
newsItem.appendChild(newsImg);
newsItem.appendChild(newsDetails);
newsContainer.appendChild(newsItem);
});
})
.catch(error => {
console.error('Error fetching news data:', error);
});
}
// Call the function to fetch and populate the news
fetchAndPopulateNews();
</script>
</body>
</html>