@@ -4,66 +4,30 @@ import { Title, PageSection, Content as PFContent } from '@patternfly/react-core
44import MainLayout from ' ../../../layouts/Main.astro'
55import { content } from " ../../../content"
66import { kebabCase } from ' change-case'
7- import { componentTabs , tabNames } from ' ../../../globals' ;
7+ import { componentTabs , tabNames , buildTab , sortTabs } from ' ../../../globals' ;
88
99export async function getStaticPaths() {
1010 const collections = await Promise .all (content .map (async (entry ) => await getCollection (entry .name as ' textContent' )))
1111
1212 const flatCol = collections .flat ().map ((entry ) => {
1313 // Build tabs dictionary
1414 let tab = entry .data .tab ;
15- if (tab === ' react ' || tab === ' html ' ) { // if tab is default repo value, check for demos/deprecated
15+ if (tab ) { // check for demos/deprecated
1616 if (entry .id .includes (' demos' )) {
1717 tab = ` ${tab }-demos ` ;
1818 } else if (entry .id .includes (' deprecated' )) {
1919 tab = ` ${tab }-deprecated ` ;
2020 }
2121 }
22-
23- // if no dictionary entry exists, and tab data exists
24- if (componentTabs [entry .data .id ] === undefined && tab ) {
25- componentTabs [entry .data .id ] = [tab ];
26- // if dictionary entry & tab data exists, and entry does not include tab
27- } else if (componentTabs [entry .data .id ] && tab && ! componentTabs [entry .data .id ].includes (tab )) {
28- componentTabs [entry .data .id ] = [... componentTabs [entry .data .id ], tab ];
29- }
22+ buildTab (entry , tab );
3023
3124 return {
3225 params: { page: kebabCase (entry .data .id ), section: entry .data .section , tab },
33- props: { entry , title: entry . data . title , component: entry . data . id , package: entry .data . package },
26+ props: { entry , ... entry .data },
3427 }
3528 })
3629
37- const defaultOrder = 50 ;
38- const sourceOrder: any = {
39- react: 1 ,
40- ' react-next' : 1.1 ,
41- ' react-demos' : 2 ,
42- ' react-deprecated' : 2.1 ,
43- html: 3 ,
44- ' html-demos' : 4 ,
45- ' design-guidelines' : 99 ,
46- ' accessibility' : 100 ,
47- ' upgrade-guide' : 101 ,
48- ' release-notes' : 102 ,
49- };
50-
51- const sortSources = (s1 : string , s2 : string ) => {
52- const s1Index = sourceOrder [s1 ] || defaultOrder ;
53- const s2Index = sourceOrder [s2 ] || defaultOrder ;
54- if (s1Index === defaultOrder && s2Index === defaultOrder ) {
55- return s1 .localeCompare (s2 );
56- }
57-
58- return s1Index > s2Index ? 1 : - 1 ;
59- }
60-
61- // Sort tabs entries based on above sort order
62- // Ensures all tabs are displayed in a consistent order & which tab gets displayed for a component route without a tab
63- Object .values (componentTabs ).map ((tabs : any ) => {
64- tabs .sort (sortSources )
65- })
66-
30+ sortTabs ()
6731 return flatCol ;
6832}
6933
0 commit comments