MCPcopy Index your code
hub / github.com/gridstack/gridstack.js / reorderSidebarNavigation

Function reorderSidebarNavigation

scripts/reorder-html-docs.js:132–178  ·  view source on GitHub ↗
(html)

Source from the content-addressed store, hash-verified

130}
131
132function reorderSidebarNavigation(html) {
133 // Also reorder the sidebar navigation to match the main content
134 const sidebarRegex = /<details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Classes"[^>]*>[\s\S]*?<span>Classes<\/span><\/summary><div>([\s\S]*?)<\/div><\/details>/;
135 const sidebarMatch = html.match(sidebarRegex);
136
137 if (sidebarMatch) {
138 const sidebarContent = sidebarMatch[1];
139
140 // Extract sidebar items
141 const sidebarItemRegex = /<a href="[^"]*"[^>]*>[\s\S]*?<span>([^<]+)<\/span><\/a>/g;
142 const sidebarItems = [];
143 let match;
144
145 while ((match = sidebarItemRegex.exec(sidebarContent)) !== null) {
146 sidebarItems.push({
147 name: match[1].replace(/<wbr\/>/g, ''),
148 content: match[0]
149 });
150 }
151
152 // Reorder sidebar classes
153 const classPriorityOrder = ['GridStack', 'GridStackEngine', 'Utils'];
154 const priorityClasses = [];
155 const otherClasses = [];
156
157 sidebarItems.forEach(item => {
158 if (classPriorityOrder.includes(item.name)) {
159 priorityClasses.push(item);
160 } else {
161 otherClasses.push(item);
162 }
163 });
164
165 priorityClasses.sort((a, b) => {
166 const aIndex = classPriorityOrder.indexOf(a.name);
167 const bIndex = classPriorityOrder.indexOf(b.name);
168 return aIndex - bIndex;
169 });
170
171 const reorderedSidebar = [...priorityClasses, ...otherClasses];
172 const newSidebarContent = reorderedSidebar.map(item => item.content).join('');
173
174 html = html.replace(sidebarMatch[0], sidebarMatch[0].replace(sidebarContent, newSidebarContent));
175 }
176
177 return html;
178}
179
180// Update the HTML content
181let updatedContent = reorderMainContent(content);

Callers 1

Calls 1

sortMethod · 0.80

Tested by

no test coverage detected