Skip to content

Commit f0ba61a

Browse files
authored
feat(docs): add favicons and other improvements (#1393)
add favicon, cleanup template, use requestAnimationFrame for better scrolling performance
1 parent 578729e commit f0ba61a

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

docs/assets/apple-touch-icon.png

22.7 KB
Loading

docs/assets/astronvim.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/assets/favicon.ico

15 KB
Binary file not shown.

docs/assets/template.html5

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
name="viewport"
1515
content="width=device-width, initial-scale=1.0, user-scalable=yes"
1616
/>
17+
<link rel="icon" type="image/svg+xml" href="./assets/astronvim.svg" />
18+
<link rel="shortcut icon" href="./assets/favicon.ico" />
19+
<link rel="apple-touch-icon" href="./assets/apple-touch-icon.png" />
1720
$for(author-meta)$
1821
<meta name="author" content="$author-meta$" />
1922
$endfor$ $if(date-meta)$
@@ -104,40 +107,50 @@
104107
});
105108
});
106109
})();
107-
document.addEventListener('DOMContentLoaded', function () {
110+
111+
document.addEventListener("DOMContentLoaded", function () {
108112
const toc = document.querySelector('nav[role="doc-toc"]');
109-
const tocLinks = toc.querySelectorAll('a');
110-
const sections = Array.from(tocLinks).map(link => document.querySelector(link.getAttribute('href')));
113+
const tocLinks = toc.querySelectorAll("a");
114+
const sections = Array.from(tocLinks).map((link) =>
115+
document.querySelector(link.getAttribute("href")),
116+
);
111117

112118
// Scroll to specific entry on page load
113119
const hash = window.location.hash;
114120
if (hash) {
115121
const target = document.querySelector(hash);
116122
if (target) {
117-
target.scrollIntoView();
118-
const activeLink = toc.querySelector('a[href="' + hash + '"]');
119-
if (activeLink) {
120-
activeLink.scrollIntoView({ behavior: 'auto', block: "nearest" });
121-
}
123+
requestAnimationFrame(() => {
124+
target.scrollIntoView();
125+
const activeLink = toc.querySelector('a[href="' + hash + '"]');
126+
if (activeLink) {
127+
activeLink.scrollIntoView({ behavior: "auto", block: "nearest" });
128+
}
129+
});
122130
}
123131
}
124132

125133
// Observe each section
126-
const observer = new IntersectionObserver(entries => {
127-
entries.forEach(entry => {
128-
if (entry.isIntersecting) {
129-
const id = entry.target.id;
130-
const activeLink = toc.querySelector('a[href="#' + id + '"]');
131-
if (activeLink) {
132-
tocLinks.forEach(link => link.classList.remove('active'));
133-
activeLink.classList.add('active');
134-
activeLink.scrollIntoView({ behavior: 'auto', block: "nearest" });
134+
const observer = new IntersectionObserver(
135+
(entries) => {
136+
entries.forEach((entry) => {
137+
if (entry.isIntersecting) {
138+
const id = entry.target.id;
139+
const activeLink = toc.querySelector('a[href="#' + id + '"]');
140+
if (activeLink) {
141+
tocLinks.forEach((link) => link.classList.remove("active"));
142+
activeLink.classList.add("active");
143+
requestAnimationFrame(() => {
144+
activeLink.scrollIntoView({ behavior: "auto", block: "nearest" });
145+
});
146+
}
135147
}
136-
}
137-
});
138-
}, {rootMargin: '0px 0px -60% 0px', threshold: 0.5 } );
148+
});
149+
},
150+
{ rootMargin: "0px 0px -60% 0px", threshold: 0.5 },
151+
);
139152

140-
sections.forEach(section => {
153+
sections.forEach((section) => {
141154
if (section) {
142155
observer.observe(section);
143156
}

docs/pages_create.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ docker run -i --rm --mount type=bind,source="$PWD",target="$PWD",readonly --work
5656
--template=assets/template \
5757
--css=assets/theme.css \
5858
--css=assets/fonts.css \
59+
-V lang=en \
5960
pages/index.md >pages/index.html
6061

6162
echo "SUCCESS - generated ../pages/index.html"

0 commit comments

Comments
 (0)