diff --git a/packages/site/pages/subfolders/index.mdx b/packages/site/pages/subfolders/index.mdx index 4317fe7..b5e911b 100644 --- a/packages/site/pages/subfolders/index.mdx +++ b/packages/site/pages/subfolders/index.mdx @@ -2,14 +2,3 @@ title: Subfolders description: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam, voluptatibus. --- - -import Link from 'next/link' - - diff --git a/packages/site/pages/subfolders/tabs-example/index.mdx b/packages/site/pages/subfolders/tabs-example/index.mdx index 68da977..e4c06f8 100644 --- a/packages/site/pages/subfolders/tabs-example/index.mdx +++ b/packages/site/pages/subfolders/tabs-example/index.mdx @@ -3,14 +3,3 @@ title: Tabs example description: Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quisquam, voluptatibus. show-tabs: true --- - -import Link from 'next/link' - - diff --git a/packages/theme/components/layout/header/Header.tsx b/packages/theme/components/layout/header/Header.tsx index 33d3b44..042d835 100644 --- a/packages/theme/components/layout/header/Header.tsx +++ b/packages/theme/components/layout/header/Header.tsx @@ -83,9 +83,10 @@ export function Header({colorModes, pageMap, docsDirectories, siteTitle}: Header .flat() .filter(Boolean) .map(({frontMatter, route}: MdxFile) => { + if (!frontMatter) return null const result = { - title: frontMatter.title, - description: frontMatter.description, + title: frontMatter.title ? frontMatter.title : '', + description: frontMatter.description ? frontMatter.description : '', url: route, } return result @@ -104,6 +105,8 @@ export function Header({colorModes, pageMap, docsDirectories, siteTitle}: Header if (inputRef.current.value.length > 2) { const searchTerm = inputRef.current.value.toLowerCase() const results = searchData.filter(data => { + if (!data) return false + if (!data.title) return false const title = data.title.toLowerCase() const description = data.description.toLowerCase() let searchIndex = 0 diff --git a/packages/theme/components/layout/index-cards/IndexCards.module.css b/packages/theme/components/layout/index-cards/IndexCards.module.css new file mode 100644 index 0000000..562f139 --- /dev/null +++ b/packages/theme/components/layout/index-cards/IndexCards.module.css @@ -0,0 +1,3 @@ +.IndexCards { + --brand-Card-maxWidth: 100%; +} diff --git a/packages/theme/components/layout/index-cards/IndexCards.tsx b/packages/theme/components/layout/index-cards/IndexCards.tsx new file mode 100644 index 0000000..ef1b257 --- /dev/null +++ b/packages/theme/components/layout/index-cards/IndexCards.tsx @@ -0,0 +1,37 @@ +import {Card, Grid} from '@primer/react-brand' +import {MdxFile} from 'nextra' + +import styles from './IndexCards.module.css' + +type IndexCardsProps = { + route: string + folderData: DocsItem[] +} + +type DocsItem = MdxFile & { + title: string + type: string + children?: DocsItem[] + firstChildRoute?: string + withIndexPage?: boolean + isUnderCurrentDocsTree?: boolean +} + +export function IndexCards({route, folderData}: IndexCardsProps) { + const filteredData = folderData.filter(item => item.kind === 'MdxPage' && item.route.includes(`${route}/`)) + + return ( + + {filteredData.map((item: DocsItem, index) => { + return ( + + + {item.frontMatter.title} + {item.frontMatter.description} + + + ) + })} + + ) +} diff --git a/packages/theme/components/layout/sidebar/Sidebar.tsx b/packages/theme/components/layout/sidebar/Sidebar.tsx index c46fe2f..67c6f36 100644 --- a/packages/theme/components/layout/sidebar/Sidebar.tsx +++ b/packages/theme/components/layout/sidebar/Sidebar.tsx @@ -104,6 +104,10 @@ export function Sidebar({pageMap}: SidebarProps) { {item.children .sort((a, b) => (a.name === 'index' ? -1 : b.name === 'index' ? 1 : 0)) // puts index page first + .filter( + child => + child.name !== 'index' || (child.name === 'index' && (child as MdxFile).frontMatter['show-tabs']), + ) // only show index page if it has show-tabs .map((child: DocsItem) => { if ((child as MdxFile).kind === 'MdxPage') { return ( diff --git a/packages/theme/index.tsx b/packages/theme/index.tsx index ab36d9e..8a03530 100644 --- a/packages/theme/index.tsx +++ b/packages/theme/index.tsx @@ -30,6 +30,7 @@ import {normalizePages} from 'nextra/normalize-pages' import {Header} from './components/layout/header/Header' import {TableOfContents} from './components/layout/table-of-contents/TableOfContents' import bodyStyles from './css/prose.module.css' +import {IndexCards} from './components/layout/index-cards/IndexCards' const {publicRuntimeConfig} = getConfig() @@ -42,6 +43,7 @@ const {publicRuntimeConfig} = getConfig() export default function Layout({children, pageOpts}: NextraThemeLayoutProps) { const {title, frontMatter, headings, filePath, pageMap, route} = pageOpts const {locale = 'en-US', defaultLocale, basePath} = useRouter() + console.log(basePath) const fsPath = useFSRoute() const [colorMode, setColorMode] = React.useState<'light' | 'dark'>('light') const { @@ -67,6 +69,7 @@ export default function Layout({children, pageOpts}: NextraThemeLayoutProps) { const {siteTitle} = publicRuntimeConfig const isHomePage = route === '/' + const isIndexPage = filePath.endsWith('index.mdx') && !isHomePage && !frontMatter['show-tabs'] const data = !isHomePage && activePath[activePath.length - 2] const filteredTabData: MdxFile[] = @@ -112,7 +115,7 @@ export default function Layout({children, pageOpts}: NextraThemeLayoutProps) { {siteTitle && ( )} - - - {frontMatter.image && ( - - - - )} - {frontMatter.title && ( - - {frontMatter.title} - - )} - {frontMatter.description && ( - - {frontMatter.description} - - )} - {frontMatter['action-1-text'] && ['action-1-link'] && ( - - - - {frontMatter['action-2-text'] && ['action-2-link'] && ( - - )} - - - )} - - + {frontMatter && ( + + + {frontMatter.image && ( + + + + )} + {frontMatter.title && ( + + {frontMatter.title} + + )} + {frontMatter.description && ( + + {frontMatter.description} + + )} + {frontMatter['action-1-text'] && ['action-1-link'] && ( + + + + {frontMatter['action-2-text'] && ['action-2-link'] && ( + + )} + + + )} + + + )} {Boolean(frontMatter['show-tabs']) && } )} -
{children}
+
+ {isIndexPage ? : children} +