File tree Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Expand file tree Collapse file tree 3 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import styled from 'styled-components';
5
5
6
6
import { ComponentsMenu } from './components-menu' ;
7
7
import { paths } from '../paths' ;
8
- import { mapComponentName } from '../lib/constants ' ;
8
+ import { isHiddenCategory } from '../lib/guards ' ;
9
9
10
10
export const Layout = ( { children } ) => {
11
11
const data = useStaticQuery ( graphql `
@@ -53,7 +53,7 @@ function createMapping(data) {
53
53
}
54
54
const prefix = data . pathPrefix || '' ;
55
55
56
- if ( component . meta . category !== mapComponentName ) {
56
+ if ( ! isHiddenCategory ( component . meta . category ) ) {
57
57
packages [ component . meta . package ] . push ( {
58
58
...component . meta ,
59
59
path : prefix + paths . componentUsage ( component . meta ) ,
Original file line number Diff line number Diff line change
1
+ import { mapComponentName } from './constants' ;
2
+
3
+ const hiddenCategories = [ mapComponentName , 'hidden' ] ;
4
+
5
+ const hiddenCategory = new RegExp (
6
+ `\\b[A-Za-z]+\\-*(${ hiddenCategories . join ( '|' ) } )$` ,
7
+ 'g' ,
8
+ ) ;
9
+
10
+ export const isHiddenCategory = ( category ) => {
11
+ if ( typeof category !== 'string' ) {
12
+ throw new Error ( 'Category is not a string' ) ;
13
+ }
14
+ return hiddenCategory . test ( category ) ;
15
+ } ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { graphql } from 'gatsby';
3
3
import { MDXRenderer } from 'gatsby-plugin-mdx' ;
4
4
import { pascalCase } from 'change-case' ;
5
5
import { Layout } from '../components/layout' ;
6
- import { mapComponentName } from '../lib/constants ' ;
6
+ import { isHiddenCategory } from '../lib/guards ' ;
7
7
8
8
const installation = ( { package : p } ) =>
9
9
`npm install ${ p }
@@ -12,7 +12,7 @@ yarn add ${p}`;
12
12
13
13
const ComponentPage = ( { data, pageContext } ) => {
14
14
const { frontmatter, body } = data . usage ;
15
- if ( frontmatter . category === mapComponentName ) {
15
+ if ( isHiddenCategory ( frontmatter . category ) ) {
16
16
return < MDXRenderer > { body } </ MDXRenderer > ;
17
17
}
18
18
return (
You can’t perform that action at this time.
0 commit comments