|
| 1 | +--- |
| 2 | +import { getCollection, render } from 'astro:content' |
| 3 | +import { Title, PageSection, Content as PFContent } from '@patternfly/react-core' |
| 4 | +import MainLayout from '../../../layouts/Main.astro' |
| 5 | +import { content } from "../../../content" |
| 6 | +import { kebabCase } from 'change-case' |
| 7 | +import { componentTabs, tabNames, buildTab, sortTabs } from '../../../globals'; |
| 8 | +
|
| 9 | +export async function getStaticPaths() { |
| 10 | + const collections = await Promise.all(content.map(async (entry) => await getCollection(entry.name as 'textContent'))) |
| 11 | +
|
| 12 | + const flatCol = collections.flat().map((entry) => { |
| 13 | + // Build tabs dictionary |
| 14 | + let tab = entry.data.tab; |
| 15 | + if(tab) { // check for demos/deprecated |
| 16 | + if(entry.id.includes('demos')) { |
| 17 | + tab = `${tab}-demos`; |
| 18 | + } else if (entry.id.includes('deprecated')) { |
| 19 | + tab = `${tab}-deprecated`; |
| 20 | + } |
| 21 | + } |
| 22 | + buildTab(entry, tab); |
| 23 | +
|
| 24 | + return { |
| 25 | + params: { page: kebabCase(entry.data.id), section: entry.data.section, tab }, |
| 26 | + props: { entry, ...entry.data }, |
| 27 | + } |
| 28 | + }) |
| 29 | +
|
| 30 | + sortTabs() |
| 31 | + return flatCol; |
| 32 | +} |
| 33 | +
|
| 34 | +const { entry } = Astro.props |
| 35 | +const { title, id, section } = entry.data |
| 36 | +const { Content } = await render(entry) |
| 37 | +const currentPath = Astro.url.pathname; |
| 38 | +--- |
| 39 | + |
| 40 | +<MainLayout> |
| 41 | + { |
| 42 | + title && ( |
| 43 | + <Title headingLevel="h1" size="4xl"> |
| 44 | + {title} |
| 45 | + </Title> |
| 46 | + ) |
| 47 | + } |
| 48 | + {componentTabs[id] && ( |
| 49 | + <PageSection id="ws-sticky-nav-tabs" stickyOnBreakpoint={{ default: 'top' }} type="tabs"> |
| 50 | + <div class="pf-v6-c-tabs pf-m-page-insets pf-m-no-border-bottom"> |
| 51 | + <ul class="pf-v6-c-tabs__list"> |
| 52 | + {componentTabs[id].map((tab: string) => ( |
| 53 | + // eslint-disable-next-line react/jsx-key |
| 54 | + <li |
| 55 | + class={`pf-v6-c-tabs__item${currentPath === `/${section}/${kebabCase(id)}/${tab}` ? ' pf-m-current' : ''}`} |
| 56 | + > |
| 57 | + <a class="pf-v6-c-tabs__link" href={`/${section}/${kebabCase(id)}/${tab}`}> |
| 58 | + {tabNames[tab]} |
| 59 | + </a> |
| 60 | + </li> |
| 61 | + ))} |
| 62 | + </ul> |
| 63 | + </div> |
| 64 | + </PageSection> |
| 65 | + )} |
| 66 | + <PageSection id="main-content" isFilled> |
| 67 | + <PFContent> |
| 68 | + <Content /> |
| 69 | + </PFContent> |
| 70 | + </PageSection> |
| 71 | +</MainLayout> |
0 commit comments