Add dynamic support for avatar.png or logo.png in header
This commit is contained in:
parent
ac0249ceb9
commit
979e655d4d
3 changed files with 36 additions and 0 deletions
23
script.js
23
script.js
|
|
@ -33,6 +33,7 @@ async function fetchConfig() {
|
|||
config = await res.json();
|
||||
populateUI();
|
||||
setupEventListeners();
|
||||
loadLogo();
|
||||
} catch (error) {
|
||||
console.error("Failed to load config.json", error);
|
||||
document.getElementById('site-title').innerText = "Error loading config";
|
||||
|
|
@ -40,6 +41,28 @@ async function fetchConfig() {
|
|||
}
|
||||
}
|
||||
|
||||
// Check for avatar.png or logo.png to display in header
|
||||
function loadLogo() {
|
||||
const logoEl = document.getElementById('site-logo');
|
||||
const imagesToTry = ['avatar.png', 'logo.png'];
|
||||
|
||||
function tryNextImage(index) {
|
||||
if (index >= imagesToTry.length) return; // None found
|
||||
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
logoEl.src = imagesToTry[index];
|
||||
logoEl.classList.remove('hidden');
|
||||
};
|
||||
img.onerror = () => {
|
||||
tryNextImage(index + 1);
|
||||
};
|
||||
img.src = imagesToTry[index];
|
||||
}
|
||||
|
||||
tryNextImage(0);
|
||||
}
|
||||
|
||||
// Render dynamic elements based on config
|
||||
function populateUI() {
|
||||
// Populate Text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue