@@ -88,44 +88,49 @@ const { sections, title = "Main Features" } = Astro.props;
8888</style >
8989
9090<script >
91- // Intersection Observer to highlight active section
92- const observerOptions = {
93- root: null,
94- rootMargin: "-20px",
95- threshold: 1,
96- };
91+ // Only run this script if the server sidebar exists on the page
92+ const serverSidebar = document.querySelector('.server-sidebar');
93+ if (serverSidebar) {
94+ // Intersection Observer to highlight active section
95+ const observerOptions = {
96+ root: null,
97+ rootMargin: "-20px",
98+ threshold: 1,
99+ };
97100
98- const observer = new IntersectionObserver((entries) => {
99- entries.forEach((entry) => {
100- const id = entry.target.getAttribute("id");
101- const link = document.querySelector(`[data-section="${id}"]`);
102-
103- if (entry.isIntersecting) {
104- link?.classList.add("active");
105- } else {
106- link?.classList.remove("active");
107- }
108- });
109- }, observerOptions);
101+ const observer = new IntersectionObserver((entries) => {
102+ entries.forEach((entry) => {
103+ const id = entry.target.getAttribute("id");
104+ const link = document.querySelector(`[data-section="${id}"]`);
105+
106+ if (entry.isIntersecting) {
107+ link?.classList.add("active");
108+ } else {
109+ link?.classList.remove("active");
110+ }
111+ });
112+ }, observerOptions);
110113
111- // Observe all sections
112- document.querySelectorAll("section[id]").forEach((section) => {
113- observer.observe(section);
114- });
114+ // Only observe sections on the server page (those with specific IDs)
115+ const serverSections = document.querySelectorAll("#server-page section[id]");
116+ serverSections.forEach((section) => {
117+ observer.observe(section);
118+ });
115119
116- // Smooth scroll for navigation
117- document.querySelectorAll(".server-sidebar a").forEach((link) => {
118- link.addEventListener("click", (e) => {
119- e.preventDefault();
120- const targetId = link.getAttribute("href")?.substring(1);
121- const targetElement = document.getElementById(targetId!);
122-
123- if (targetElement) {
124- targetElement.scrollIntoView({
125- behavior: "smooth",
126- block: "start",
127- });
128- }
120+ // Smooth scroll for navigation
121+ document.querySelectorAll(".server-sidebar a").forEach((link) => {
122+ link.addEventListener("click", (e) => {
123+ e.preventDefault();
124+ const targetId = link.getAttribute("href")?.substring(1);
125+ const targetElement = document.getElementById(targetId!);
126+
127+ if (targetElement) {
128+ targetElement.scrollIntoView({
129+ behavior: "smooth",
130+ block: "start",
131+ });
132+ }
133+ });
129134 });
130- });
131- </script >
135+ }
136+ </script >
0 commit comments