@@ -589,14 +589,47 @@ export function generateBaseUIApiPages() {
589
589
) {
590
590
const { components, hooks } = markdownHeaders ;
591
591
592
+ const tokens = markdown . pathname . split ( '/' ) ;
593
+ const name = tokens [ tokens . length - 1 ] ;
594
+ const importStatement = `docs/data${ markdown . pathname } /${ name } .md` ;
595
+ const demosSource = `
596
+ import * as React from 'react';
597
+ import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
598
+ import AppFrame from 'docs/src/modules/components/AppFrame';
599
+ import * as pageProps from '${ importStatement } ?@mui/markdown';
600
+
601
+ export default function Page(props) {
602
+ const { userLanguage, ...other } = props;
603
+ return <MarkdownDocs {...pageProps} {...other} />;
604
+ }
605
+
606
+ Page.getLayout = (page) => {
607
+ return <AppFrame>{page}</AppFrame>;
608
+ };
609
+ ` ;
610
+
611
+ const componentPageDirectory = `docs/pages/${ productName } -ui/react-${ componentName } /` ;
612
+ if ( ! fs . existsSync ( componentPageDirectory ) ) {
613
+ fs . mkdirSync ( componentPageDirectory , { recursive : true } ) ;
614
+ }
615
+ writePrettifiedFile (
616
+ path . join ( process . cwd ( ) , `${ componentPageDirectory } /index.js` ) ,
617
+ demosSource ,
618
+ ) ;
619
+
620
+ if ( ( ! components || components . length === 0 ) && ( ! hooks || hooks . length === 0 ) ) {
621
+ // Early return if it's a markdown file without components/hooks.
622
+ return ;
623
+ }
624
+
592
625
let apiTabImportStatements = '' ;
593
626
let staticProps = 'export const getStaticProps = () => {' ;
594
627
let componentsApiDescriptions = '' ;
595
628
let componentsPageContents = '' ;
596
629
let hooksApiDescriptions = '' ;
597
630
let hooksPageContents = '' ;
598
631
599
- if ( components ) {
632
+ if ( components && components . length > 0 ) {
600
633
components . forEach ( ( component : string ) => {
601
634
const componentNameKebabCase = kebabCase ( component ) ;
602
635
apiTabImportStatements += `import ${ component } ApiJsonPageContent from '../../api/${ componentNameKebabCase } .json';` ;
@@ -613,7 +646,7 @@ export function generateBaseUIApiPages() {
613
646
} ) ;
614
647
}
615
648
616
- if ( hooks ) {
649
+ if ( hooks && hooks . length > 0 ) {
617
650
hooks . forEach ( ( hook : string ) => {
618
651
const hookNameKebabCase = kebabCase ( hook ) ;
619
652
apiTabImportStatements += `import ${ hook } ApiJsonPageContent from '../../api/${ hookNameKebabCase } .json';` ;
@@ -645,25 +678,6 @@ export function generateBaseUIApiPages() {
645
678
646
679
staticProps += ` },},};};` ;
647
680
648
- const tokens = markdown . pathname . split ( '/' ) ;
649
- const name = tokens [ tokens . length - 1 ] ;
650
- const importStatement = `docs/data${ markdown . pathname } /${ name } .md` ;
651
- const demosSource = `
652
- import * as React from 'react';
653
- import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
654
- import AppFrame from 'docs/src/modules/components/AppFrame';
655
- import * as pageProps from '${ importStatement } ?@mui/markdown';
656
-
657
- export default function Page(props) {
658
- const { userLanguage, ...other } = props;
659
- return <MarkdownDocs {...pageProps} {...other} />;
660
- }
661
-
662
- Page.getLayout = (page) => {
663
- return <AppFrame>{page}</AppFrame>;
664
- };
665
- ` ;
666
-
667
681
const tabsApiSource = `
668
682
import * as React from 'react';
669
683
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocsV2';
@@ -691,24 +705,14 @@ export const getStaticPaths = () => {
691
705
${ staticProps }
692
706
` ;
693
707
694
- const componentPageDirectory = `docs/pages/${ productName } -ui/react-${ componentName } /` ;
695
- if ( ! fs . existsSync ( componentPageDirectory ) ) {
696
- fs . mkdirSync ( componentPageDirectory , { recursive : true } ) ;
697
- }
698
- const demosSourcePath = path . join ( process . cwd ( ) , `${ componentPageDirectory } /index.js` ) ;
699
- writePrettifiedFile ( demosSourcePath , demosSource ) ;
700
-
701
- if ( ( components ?? [ ] ) . length === 0 && ( hooks ?? [ ] ) . length === 0 ) {
702
- // Early return if it's a markdown file without components/hooks.
703
- return ;
704
- }
705
-
706
708
const docsTabsPagesDirectory = `${ componentPageDirectory } /[docsTab]` ;
707
709
if ( ! fs . existsSync ( docsTabsPagesDirectory ) ) {
708
710
fs . mkdirSync ( docsTabsPagesDirectory , { recursive : true } ) ;
709
711
}
710
- const tabsApiPath = path . join ( process . cwd ( ) , `${ docsTabsPagesDirectory } /index.js` ) ;
711
- writePrettifiedFile ( tabsApiPath , tabsApiSource ) ;
712
+ writePrettifiedFile (
713
+ path . join ( process . cwd ( ) , `${ docsTabsPagesDirectory } /index.js` ) ,
714
+ tabsApiSource ,
715
+ ) ;
712
716
}
713
717
} ) ;
714
718
}
0 commit comments