Skip to content

Commit 8793142

Browse files
committed
Update logo and site title links in header
- Logo now links to the organization root (https://beancount.github.io). - 'Beancount Documentation' title now links to the documentation root. - Implemented via a new JavaScript file (docs/javascripts/header.js). - Added script to zensical.yml extra_javascript configuration.
1 parent bc905d5 commit 8793142

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

docs/javascripts/header.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(function() {
2+
console.log("Beancount header script loaded");
3+
4+
function applyLinks() {
5+
const logoLinks = document.querySelectorAll('[data-md-component="logo"]');
6+
if (logoLinks.length === 0) return false;
7+
8+
let docRoot = '';
9+
// Find the original documentation root link.
10+
// It's usually "" (on index) or contains ".." or is "/docs/"
11+
for (let logo of logoLinks) {
12+
const href = logo.getAttribute('href');
13+
if (href !== null && href !== 'https://beancount.github.io') {
14+
docRoot = logo.href; // Get resolved absolute URL
15+
break;
16+
}
17+
}
18+
19+
// If we can't find it clearly, fallback to a sensible default.
20+
if (!docRoot) docRoot = window.location.origin + '/docs/';
21+
22+
console.log("Determined docRoot:", docRoot);
23+
24+
// Update all logo links to point to organization root.
25+
logoLinks.forEach(function(logo) {
26+
logo.href = 'https://beancount.github.io';
27+
});
28+
29+
// Update the site title in the header.
30+
const titleTopics = document.querySelectorAll('.md-header__topic');
31+
if (titleTopics.length > 0) {
32+
const titleSpan = titleTopics[0].querySelector('.md-ellipsis');
33+
if (titleSpan && !titleSpan.querySelector('a')) {
34+
const titleText = titleSpan.textContent.trim();
35+
if (titleText === 'Beancount Documentation') {
36+
titleSpan.innerHTML = `<a href="${docRoot}" style="color: inherit; text-decoration: none;">${titleText}</a>`;
37+
console.log("Updated title link to:", docRoot);
38+
}
39+
}
40+
}
41+
42+
// Also update the sidebar title if it exists.
43+
const navTitle = document.querySelector('.md-nav__title');
44+
if (navTitle) {
45+
for (let node of navTitle.childNodes) {
46+
if (node.nodeType === Node.TEXT_NODE && node.textContent.trim() === 'Beancount Documentation') {
47+
const span = document.createElement('span');
48+
span.innerHTML = `<a href="${docRoot}" style="color: inherit; text-decoration: none;">${node.textContent}</a>`;
49+
navTitle.replaceChild(span, node);
50+
console.log("Updated sidebar title link");
51+
}
52+
}
53+
}
54+
55+
return true;
56+
}
57+
58+
// Try multiple times to handle potential dynamic loading or race conditions.
59+
let attempts = 0;
60+
const interval = setInterval(function() {
61+
attempts++;
62+
const success = applyLinks();
63+
if (success || attempts > 20) {
64+
clearInterval(interval);
65+
}
66+
}, 250);
67+
68+
// Also hook into Material for MkDocs navigation if available.
69+
if (typeof location$ !== 'undefined') {
70+
location$.subscribe(function() {
71+
setTimeout(applyLinks, 100);
72+
setTimeout(applyLinks, 500);
73+
});
74+
}
75+
})();

zensical.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ extra_css:
111111
- css/custom.css
112112
extra_javascript:
113113
- javascripts/shortcuts.js
114+
- javascripts/header.js
114115

115116
extra:
116117
version:

0 commit comments

Comments
 (0)