-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
94 lines (81 loc) · 2.76 KB
/
config.js
File metadata and controls
94 lines (81 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
// Configuration loader
function loadConfig() {
return fetch('/config.json')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load configuration');
}
return response.json();
})
.catch(error => {
console.error('Error loading configuration:', error);
return null;
});
}
// Apply social media links
function applySocialLinks(config) {
if (!config || !config.social) return;
// Find all social links by their data attributes
document.querySelectorAll('[data-social]').forEach(link => {
const socialType = link.getAttribute('data-social');
if (config.social[socialType]) {
link.href = config.social[socialType];
}
});
}
// Apply project links
function applyProjectLinks(config) {
if (!config || !config.projects) return;
// Find all project links by their data attributes
document.querySelectorAll('[data-project]').forEach(link => {
const projectName = link.getAttribute('data-project');
const linkType = link.getAttribute('data-link-type'); // github or live
if (config.projects[projectName] && config.projects[projectName][linkType]) {
link.href = config.projects[projectName][linkType];
}
});
}
// Apply tool links
function applyToolLinks(config) {
if (!config || !config.tools) return;
// Find all tool links by their data attributes
document.querySelectorAll('[data-tool]').forEach(link => {
const toolName = link.getAttribute('data-tool');
if (config.tools[toolName]) {
link.href = config.tools[toolName];
}
});
}
// Apply Notion notes links
function applyNotionLinks(config) {
if (!config || !config.notionNotes) return;
// Find all notion note links by their data attributes
document.querySelectorAll('[data-notion-note]').forEach(link => {
const noteType = link.getAttribute('data-notion-note');
if (config.notionNotes[noteType]) {
link.href = config.notionNotes[noteType];
}
});
}
// Apply GitHub stats configuration
function applyGitHubStats(config) {
if (!config || !config.githubStats) return;
// Set the GitHub username in the script.js file
window.githubUsername = config.githubStats.username;
window.defaultStars = config.githubStats.defaultStars;
window.defaultContributions = config.githubStats.defaultContributions;
}
// Initialize configuration when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
loadConfig().then(config => {
if (config) {
applySocialLinks(config);
applyProjectLinks(config);
applyToolLinks(config);
applyNotionLinks(config);
applyGitHubStats(config);
// Dispatch an event to notify that config is loaded
document.dispatchEvent(new CustomEvent('configLoaded', { detail: config }));
}
});
});