Skip to content

Commit 1c04966

Browse files
authored
feat: can hide any category (#14)
1 parent b0831ed commit 1c04966

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

gatsby-theme-woly/src/components/layout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styled from 'styled-components';
55

66
import { ComponentsMenu } from './components-menu';
77
import { paths } from '../paths';
8-
import { mapComponentName } from '../lib/constants';
8+
import { isHiddenCategory } from '../lib/guards';
99

1010
export const Layout = ({ children }) => {
1111
const data = useStaticQuery(graphql`
@@ -53,7 +53,7 @@ function createMapping(data) {
5353
}
5454
const prefix = data.pathPrefix || '';
5555

56-
if (component.meta.category !== mapComponentName) {
56+
if (!isHiddenCategory(component.meta.category)) {
5757
packages[component.meta.package].push({
5858
...component.meta,
5959
path: prefix + paths.componentUsage(component.meta),

gatsby-theme-woly/src/lib/guards.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
};

gatsby-theme-woly/src/templates/usage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { graphql } from 'gatsby';
33
import { MDXRenderer } from 'gatsby-plugin-mdx';
44
import { pascalCase } from 'change-case';
55
import { Layout } from '../components/layout';
6-
import { mapComponentName } from '../lib/constants';
6+
import { isHiddenCategory } from '../lib/guards';
77

88
const installation = ({ package: p }) =>
99
`npm install ${p}
@@ -12,7 +12,7 @@ yarn add ${p}`;
1212

1313
const ComponentPage = ({ data, pageContext }) => {
1414
const { frontmatter, body } = data.usage;
15-
if (frontmatter.category === mapComponentName) {
15+
if (isHiddenCategory(frontmatter.category)) {
1616
return <MDXRenderer>{body}</MDXRenderer>;
1717
}
1818
return (

0 commit comments

Comments
 (0)