Skip to content

Commit

Permalink
Various fixes in navbar logo (#144)
Browse files Browse the repository at this point in the history
* Moved scripts outside of logo svg's

* Fixed wrong variant of logo displaying in chromium-based browsers
  • Loading branch information
lurppa authored Apr 29, 2024
1 parent 79ff1d6 commit f19e760
Show file tree
Hide file tree
Showing 15 changed files with 1,469 additions and 141 deletions.
39 changes: 39 additions & 0 deletions assets/js/festive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Sets festive theming on logo.
* @param {String} festive
*/
const setFestive = (festive) => {
// logo.svg -> logo-${festive}.svg
// logo-dark.svg -> logo-${festive}-dark.svg
// logo-light.svg -> logo-${festive}-light.svg
for (const logo of document.querySelectorAll(".navbar-brand img")) {
for (const suffix of ["-dark.svg", "-light.svg", ".svg"]) {
if (logo.src.endsWith(suffix)) {
logo.src = `${logo.src.replace(suffix, "")}-${festive}${suffix}`;
break;
}
}
}
}


document.addEventListener("DOMContentLoaded", () => {
const date = new Date();
const month = date.getMonth() + 1; // Javascript's month starts from 0 and ends in 11
const day = date.getDate();

// Ylioppilaslakki
if (month == 4 && day > 30 - 2 * 7 || month == 5 && day == 1) {
setFestive("vappu");
}

// Pride month
else if (month == 6) {
setFestive("pride");
}

// Christmas
else if (month == 12) {
setFestive("joulu");
}
});
10 changes: 6 additions & 4 deletions assets/js/lightswitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const isThemeDark = () => {
return dm === "true";
}


/**
* @param {boolean} dark
*/
Expand All @@ -35,12 +36,13 @@ const setLogoDark = (dark) => {
const setDark = dark => {
window.localStorage.setItem("darkmode", dark);
const ds = document.querySelector("#darkstyle");
if (dark && !ds) {
darkStyleParent.appendChild(darkStyleObject.cloneNode());
if (dark) {
if (!ds) darkStyleParent.appendChild(darkStyleObject.cloneNode());
icon.className = "fas fa-2x fa-sun";
setLogoDark(true);
} else if (!dark && ds) {
ds.remove();
}
else {
if (ds) ds.remove();
icon.className = "fas fa-2x fa-moon";
setLogoDark(false);
}
Expand Down
4 changes: 2 additions & 2 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ home = ["html", "rss", "api-sponsors"]
copyright = "Copyright (c) 2024, Linkki Jyväskylä ry; all rights reserved."

logo_text = "Linkki Jyväskylä ry."
logo = "img/linkki-logo-modern.svg"
logo_small = "img/linkki-logo-modern.svg"
logo = "img/logo/linkki-navbar.svg"
logo_small = "img/logo/linkki-navbar.svg"

# Format dates with Go's time formatting
# https://pkg.go.dev/time
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f19e760

Please sign in to comment.