Skip to content

Commit

Permalink
fix: External svgs not rendering in top nav bar (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
526avijitgupta authored Jan 5, 2025
1 parent af70eb5 commit e1685de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
7 changes: 1 addition & 6 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,7 @@ img {
display: block;
padding: 0 6px;
}
.nav-link a svg {
height: 20px;
margin: -3px auto;
stroke-width: 2;
width: 20px;
}
.nav-link a svg,
.nav-item a svg {
height: 20px;
margin: -3px auto;
Expand Down
18 changes: 18 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ function ready() {
// Do the injection
SVGInjector(svgsToInject);

const observer = new MutationObserver(() => {
normalizeSvgPaths();
});

observer.observe(document.body, { childList: true, subtree: true });

function normalizeSvgPaths() {
document.querySelectorAll('a .svg-inject path').forEach(path => {
const bbox = path.getBBox();
const scaleX = 20 / bbox.width;
const scaleY = 20 / bbox.height;
const scale = Math.min(scaleX, scaleY);

path.setAttribute('transform', `scale(${scale}) translate(${-bbox.x}, ${-bbox.y})`);
path.setAttribute('fill', 'currentColor');
});
}

document.getElementById('hamburger-menu-toggle').addEventListener('click', () => {
const hamburgerMenu = document.getElementsByClassName('nav-hamburger-list')[0]
const hamburgerMenuToggleTarget = document.getElementById("hamburger-menu-toggle-target")
Expand Down
6 changes: 6 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ title = "Gokarna"
url = "/index.xml"
weight = 7

[[menu.main]]
identifier = "bluesky"
pre = "<img class='svg-inject' src='https://upload.wikimedia.org/wikipedia/commons/7/7a/Bluesky_Logo.svg' />"
url = "/index.xml"
weight = 8

[markup]
[markup.tableOfContents]
startLevel = 1
Expand Down

0 comments on commit e1685de

Please sign in to comment.