-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponents.js
More file actions
99 lines (87 loc) · 2.76 KB
/
components.js
File metadata and controls
99 lines (87 loc) · 2.76 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
// ============================================
// Dynamic Header and Footer Components
// ============================================
/**
* Get the base path for navigation links based on current page location
*/
function getBasePath() {
const path = window.location.pathname;
if (path.includes('/projects/')) {
return '../';
}
return './';
}
/**
* Get the current page name to set active nav link
*/
function getCurrentPage() {
const path = window.location.pathname;
if (path.includes('projects-showcase.html')) {
return 'showcase';
}
if (path.includes('/projects/')) {
return 'project';
}
return 'home';
}
/**
* Render the header component
*/
function renderHeader() {
const headerElement = document.getElementById('dynamic-header');
if (!headerElement) return;
const basePath = getBasePath();
const currentPage = getCurrentPage();
const isHome = currentPage === 'home';
const logoLink = isHome ? '' : `href="${basePath}index.html"`;
const logoClass = isHome ? '' : 'logo-link';
headerElement.innerHTML = `
<div class="container">
<div class="logo">
${isHome ? '' : `<a ${logoLink} class="${logoClass}">`}
<span class="logo-bracket"><</span>
<span class="logo-text">CodeByte</span>
<span class="logo-bracket">/></span>
${isHome ? '' : '</a>'}
</div>
<nav class="nav">
<a href="${basePath}projects-showcase.html" class="nav-link ${currentPage === 'showcase' ? 'active' : ''}">My_Projects</a>
</nav>
</div>
`;
}
/**
* Render the footer component
*/
function renderFooter() {
const footerElement = document.getElementById('dynamic-footer');
if (!footerElement) return;
footerElement.innerHTML = `
<div class="container">
<p class="footer-text">
<span class="code-comment">// Comprehensive documentation and structured breakdowns of all my coding projects.</span>
</p>
<p class="footer-copyright">
© <span id="currentYear"></span> CodeByte. Developer Projects Documenting.
</p>
</div>
`;
// Set current year
const currentYearElement = document.getElementById('currentYear');
if (currentYearElement) {
currentYearElement.textContent = new Date().getFullYear();
}
}
/**
* Initialize components - call this after DOM is loaded
*/
function initComponents() {
renderHeader();
renderFooter();
}
// Auto-initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initComponents);
} else {
initComponents();
}