-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtech-trend-board.html
More file actions
519 lines (464 loc) · 16.1 KB
/
tech-trend-board.html
File metadata and controls
519 lines (464 loc) · 16.1 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="이호기의 기술 트렌드/뉴스 게시판 - 자동차 산업의 최신 동향과 기술 트렌드를 주간별로 정리하여 제공"
/>
<meta name="author" content="Hoki Lee" />
<title>기술 트렌드/뉴스 게시판 - 이호기</title>
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="board-styles.css" />
<style>
/* 현재 페이지 정보 스타일 */
.page-info {
text-align: center;
margin: 20px 0 10px 0;
font-size: 14px;
color: #666;
}
.page-info strong {
color: #dc3545;
font-weight: 600;
}
</style>
<!-- 외부 데이터 파일 -->
<script src="tech-trend/tech-trend-data.js"></script>
<script src="scripts.js" defer></script>
</head>
<body>
<!-- 히어로 배너 섹션 -->
<section class="hero-banner tech-hero">
<div class="hero-image">
<img src="web-image/technology-news-image.jpg" alt="기술 트렌드/뉴스" />
</div>
<div class="hero-content">
<h1>기술 트렌드/뉴스</h1>
<p>
자동차 산업의 최신 동향과 기술 트렌드를 주간별로 정리하여 제공합니다
</p>
</div>
</section>
<!-- 네비게이션 바 -->
<nav class="main-navigation">
<div class="nav-container">
<div class="nav-item">
<a href="about-me-board.html">
<img
src="web-image/about-me-icon.png"
alt="About Me"
class="nav-icon"
/>
<span>About Me</span>
</a>
</div>
<div class="nav-item">
<a href="career-board.html">
<img
src="web-image/career-icon.png"
alt="경력 이야기"
class="nav-icon"
/>
<span>경력 이야기</span>
</a>
</div>
<div class="nav-item">
<a href="today-content-board.html">
<img
src="web-image/information-icon.png"
alt="오늘의 콘텐츠"
class="nav-icon"
/>
<span>오늘의 콘텐츠</span>
</a>
</div>
<div class="nav-item">
<a href="latest-content-board.html">
<img
src="web-image/books-icon.png"
alt="기술자료"
class="nav-icon"
/>
<span>기술자료</span>
</a>
</div>
<div class="nav-item active">
<img
src="web-image/news_icon.png"
alt="기술 트렌드/뉴스"
class="nav-icon"
/>
<span>기술 트렌드/뉴스</span>
</div>
<div class="nav-item">
<a href="daily-thoughts-collection-board.html">
<img
src="web-image/think-something.png"
alt="이전 자료"
class="nav-icon"
/>
<span>이전 자료</span>
</a>
</div>
<div class="nav-item">
<a href="contact-board.html">
<img
src="web-image/contect-icon.png"
alt="연락처"
class="nav-icon"
/>
<span>연락처</span>
</a>
</div>
<div class="nav-item">
<a href="index.html">
<img
src="web-image/return-icon.png"
alt="초기화면"
class="nav-icon"
/>
<span>초기화면</span>
</a>
</div>
</div>
</nav>
<!-- 메인 콘텐츠 섹션 -->
<main class="main-content latest-content-board">
<div class="board-container">
<!-- 메인 콘텐츠 -->
<div class="board-main">
<div class="board-header">
<h1>기술 트렌드/뉴스 게시판</h1>
<p>
자동차 산업의 최신 동향과 기술 트렌드를 주간별로 정리하여
제공합니다
</p>
</div>
<!-- 검색 및 필터 바 -->
<div class="search-filter-bar">
<div class="search-group">
<input
type="text"
id="searchInput"
placeholder="뉴스 제목으로 검색..."
class="search-input"
/>
<button id="searchBtn" class="search-btn">🔍</button>
</div>
</div>
<div class="result-info">
<span id="result-count">총 0건</span>
</div>
<!-- 게시판 테이블 -->
<div class="board-table">
<table>
<thead>
<tr>
<th class="col-number">번호</th>
<th class="col-title">제목</th>
<th class="col-category">카테고리</th>
<th class="col-author">작성자</th>
<th class="col-date">등록일</th>
</tr>
</thead>
<tbody id="boardTableBody">
<!-- 동적으로 생성되는 게시글 목록 -->
</tbody>
</table>
</div>
<!-- 현재 페이지 정보 -->
<div class="page-info">
<span id="current-page-info"
>현재 페이지: <strong>1</strong> / 1 페이지</span
>
</div>
<!-- 페이지네이션 -->
<div class="pagination" id="pagination">
<!-- 동적으로 생성되는 페이지네이션 -->
</div>
</div>
</div>
</main>
<script>
// 전역 변수
let currentPage = 1;
let itemsPerPage = 10;
let filteredData = [];
let currentFilter = '';
// 게시판 데이터
let boardData = [];
let totalPages = 0;
// 데이터 로드 함수
function loadBoardData() {
try {
console.log('loadBoardData 실행 중...');
console.log('techTrendData:', typeof techTrendData);
// 외부 데이터가 로드되었는지 확인
if (
typeof techTrendData !== 'undefined' &&
techTrendData.length > 0
) {
boardData = techTrendData.map((item) => ({
id: item.id,
title: item.title,
link: item.link,
category: item.category,
author: item.author,
date: item.date,
}));
totalPages = Math.ceil(boardData.length / itemsPerPage);
console.log('데이터 로드 완료:', boardData.length);
console.log('boardData 샘플:', boardData.slice(0, 3));
// 초기화 실행
initializeBoard();
} else {
console.log('외부 데이터가 아직 로드되지 않음. 재시도...');
setTimeout(loadBoardData, 100);
}
} catch (error) {
console.error('데이터 로드 중 오류:', error);
setTimeout(loadBoardData, 100);
}
}
// 게시판 테이블 렌더링
function renderBoardTable(page) {
const startIndex = (page - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const pageData = boardData.slice(startIndex, endIndex);
const tbody = document.getElementById('boardTableBody');
tbody.innerHTML = '';
if (pageData.length === 0) {
tbody.innerHTML = `
<tr>
<td colspan="5" style="text-align: center; padding: 40px; color: #666;">
아직 등록된 뉴스가 없습니다.<br>
매주 월요일에 최신 기술 트렌드와 뉴스를 업데이트합니다.
</td>
</tr>
`;
return;
}
pageData.forEach((item) => {
const row = document.createElement('tr');
row.className = 'board-row';
// NEW 배지 표시 (7일 이내)
const isNew = isWithinDays(item.date, 7);
const newBadge = isNew ? '<span class="new-badge">NEW</span>' : '';
row.innerHTML = `
<td class="col-number">${item.id}</td>
<td class="col-title">
<a href="javascript:void(0)" onclick="handleLinkClick('${item.link}')">${item.title}</a>
${newBadge}
</td>
<td class="col-category">${item.category}</td>
<td class="col-author">${item.author}</td>
<td class="col-date">${item.date}</td>
`;
tbody.appendChild(row);
});
}
// 필터링된 게시판 테이블 렌더링
function renderFilteredBoardTable(page) {
const startIndex = (page - 1) * itemsPerPage;
const endIndex = startIndex + itemsPerPage;
const pageData = filteredData.slice(startIndex, endIndex);
const tbody = document.getElementById('boardTableBody');
tbody.innerHTML = '';
pageData.forEach((item) => {
const row = document.createElement('tr');
row.className = 'board-row';
// NEW 배지 표시 (7일 이내)
const isNew = isWithinDays(item.date, 7);
const newBadge = isNew ? '<span class="new-badge">NEW</span>' : '';
row.innerHTML = `
<td class="col-number">${item.id}</td>
<td class="col-title">
<a href="javascript:void(0)" onclick="handleLinkClick('${item.link}')">${item.title}</a>
${newBadge}
</td>
<td class="col-category">${item.category}</td>
<td class="col-author">${item.author}</td>
<td class="col-date">${item.date}</td>
`;
tbody.appendChild(row);
});
}
// 페이지네이션 렌더링
function renderPagination() {
const pagination = document.getElementById('pagination');
const dataLength = currentFilter
? filteredData.length
: boardData.length;
const totalPages = Math.ceil(dataLength / itemsPerPage);
pagination.innerHTML = '';
if (totalPages <= 1) return;
// 이전 페이지 버튼
if (currentPage > 1) {
const prevBtn = document.createElement('button');
prevBtn.textContent = '◀';
prevBtn.onclick = () => changePage(currentPage - 1);
pagination.appendChild(prevBtn);
}
// 페이지 번호 버튼들 - 5개 페이지를 기본으로 표시
let startPage, endPage;
if (totalPages <= 5) {
startPage = 1;
endPage = totalPages;
} else {
if (currentPage <= 3) {
startPage = 1;
endPage = 5;
} else if (currentPage >= totalPages - 2) {
startPage = totalPages - 4;
endPage = totalPages;
} else {
startPage = currentPage - 2;
endPage = currentPage + 2;
}
}
for (let i = startPage; i <= endPage; i++) {
const pageBtn = document.createElement('button');
pageBtn.textContent = i;
pageBtn.className = i === currentPage ? 'active' : '';
pageBtn.onclick = () => changePage(i);
pagination.appendChild(pageBtn);
}
// 다음 페이지 버튼
if (currentPage < totalPages) {
const nextBtn = document.createElement('button');
nextBtn.textContent = '▶';
nextBtn.onclick = () => changePage(currentPage + 1);
pagination.appendChild(nextBtn);
}
}
// 페이지 변경
function changePage(page) {
currentPage = page;
if (currentFilter) {
renderFilteredBoardTable(page);
} else {
renderBoardTable(page);
}
renderPagination();
updateResultCount();
updateCurrentPageInfo();
}
// 검색 및 필터링 설정
function setupSearchAndFilter() {
const searchInput = document.getElementById('searchInput');
const searchBtn = document.getElementById('searchBtn');
// 검색 버튼 클릭 이벤트
if (searchBtn) {
searchBtn.addEventListener('click', function () {
performSearch();
});
}
// 엔터 키 이벤트
if (searchInput) {
searchInput.addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
performSearch();
}
});
}
}
// 검색 실행
function performSearch() {
const searchTerm = document
.getElementById('searchInput')
.value.toLowerCase();
if (!boardData || boardData.length === 0) {
console.error('boardData가 로드되지 않았습니다.');
return;
}
if (searchTerm === '') {
// 검색어가 비어있으면 전체 데이터 표시
currentFilter = '';
currentPage = 1;
renderBoardTable(currentPage);
renderPagination();
updateResultCount();
updateCurrentPageInfo();
return;
}
filteredData = boardData.filter((item) => {
return item.title.toLowerCase().includes(searchTerm);
});
currentFilter = 'search';
currentPage = 1;
renderFilteredBoardTable(currentPage);
renderPagination();
updateResultCount();
updateCurrentPageInfo();
}
// 결과 개수 업데이트
function updateResultCount() {
const resultCount = document.getElementById('result-count');
const dataLength = currentFilter
? filteredData.length
: boardData.length;
if (resultCount) {
resultCount.textContent = `총 ${dataLength}건`;
}
}
// 현재 페이지 정보 업데이트
function updateCurrentPageInfo() {
const currentPageInfo = document.getElementById('current-page-info');
const dataLength = currentFilter
? filteredData.length
: boardData.length;
const totalPages = Math.ceil(dataLength / itemsPerPage);
if (currentPageInfo) {
currentPageInfo.innerHTML = `현재 페이지: <strong>${currentPage}</strong> / ${totalPages} 페이지`;
}
}
// 날짜가 지정된 일수 이내인지 확인
function isWithinDays(dateStr, days) {
const today = new Date();
const itemDate = parseDate(dateStr);
const diffTime = Math.abs(today - itemDate);
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
return diffDays <= days;
}
// 날짜 문자열을 Date 객체로 변환
function parseDate(dateStr) {
const [month, day] = dateStr.split('-').map(Number);
const currentYear = new Date().getFullYear();
return new Date(currentYear, month - 1, day);
}
// 링크 클릭 처리
function handleLinkClick(link) {
if (link && link !== '#') {
// HTML 파일인 경우 새 탭에서 열기
window.open(link, '_blank');
}
}
// 초기화 및 이벤트 리스너 설정
function initializeBoard() {
console.log('게시판 초기화 시작');
console.log('boardData 확인:', boardData.length);
// 초기 렌더링
renderBoardTable(1);
renderPagination();
updateResultCount();
updateCurrentPageInfo();
setupSearchAndFilter();
}
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', function () {
console.log('DOM이 로드되었습니다. 데이터 로드를 시작합니다.');
loadBoardData();
});
// 연도 표시
const yearElement = document.getElementById('year');
if (yearElement) {
yearElement.textContent = new Date().getFullYear();
}
</script>
<footer class="footer">
<p>Copyright ⓒ <span id="year"></span> Hoki Lee.</p>
</footer>
</body>
</html>