(pages: Page[], library: Library)
| 201 | * Sorts sections with 'Components' first. |
| 202 | */ |
| 203 | export function buildSectionsFromPages(pages: Page[], library: Library): Section[] { |
| 204 | const filteredPages = pages.filter( |
| 205 | page => getLibraryFromPage(page) === library && !page.exports?.hideFromSearch |
| 206 | ); |
| 207 | |
| 208 | const components = filteredPages.map(transformPageToComponentItem); |
| 209 | |
| 210 | const sectionNames = Array.from(new Set(components.map(c => c.section || 'Components'))); |
| 211 | |
| 212 | return sectionNames |
| 213 | .map(sectionName => ({ |
| 214 | id: sectionName.toLowerCase(), |
| 215 | name: sectionName, |
| 216 | children: components.filter(c => (c.section || 'Components') === sectionName) |
| 217 | })) |
| 218 | .sort((a, b) => { |
| 219 | if (a.id === 'components') { |
| 220 | return -1; |
| 221 | } |
| 222 | if (b.id === 'components') { |
| 223 | return 1; |
| 224 | } |
| 225 | let ai = END_SECTIONS.indexOf(a.id); |
| 226 | let bi = END_SECTIONS.indexOf(b.id); |
| 227 | if (ai >= 0) { |
| 228 | return bi < 0 ? 1 : ai - bi; |
| 229 | } |
| 230 | if (bi >= 0) { |
| 231 | return ai < 0 ? -1 : bi - ai; |
| 232 | } |
| 233 | return a.name.localeCompare(b.name); |
| 234 | }); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Gets items for a given section selection (handles 'all' and specific sections). |
no test coverage detected