Skip to content

Commit

Permalink
feat(clayui.com): source md/mdx files from package directories
Browse files Browse the repository at this point in the history
  • Loading branch information
bryceosterhaus committed Apr 22, 2020
1 parent 17dd74c commit fc6e798
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
9 changes: 8 additions & 1 deletion clayui.com/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ module.exports = {
},
{
options: {
name: 'packages',
name: 'content',
path: `${__dirname}/content`,
},
resolve: 'gatsby-source-filesystem',
},
{
options: {
name: 'packages',
path: path.join(__dirname, '../packages'),
},
resolve: 'gatsby-source-filesystem',
},
{
options: {
extensions: ['.mdx'],
Expand Down
5 changes: 4 additions & 1 deletion clayui.com/gatsby/createPages.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ module.exports = async ({actions, graphql}) => {
return Promise.reject(errors);
}

const blacklist = data.allMdx.edges.filter(
const blacklist = [
...data.allMdx.edges,
...data.allMarkdownRemark.edges,
].filter(
({
node: {
fields: {sibling},
Expand Down
18 changes: 17 additions & 1 deletion clayui.com/gatsby/onCreateNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = exports.onCreateNode = ({actions, getNode, node}) => {
title,
version,
} = node.frontmatter;

const {relativePath, sourceInstanceName} = getNode(node.parent);

let slug = permalink;
Expand All @@ -63,6 +64,21 @@ module.exports = exports.onCreateNode = ({actions, getNode, node}) => {
}

if (!slug) {
if (sourceInstanceName === 'packages' && title) {
const fileName = path.basename(relativePath).split('.')[0];

if (relativePath.includes('README')) {
slug = `docs/components/${packageNpm.replace(
'@clayui/',
''
)}.html`;
} else {
slug = `docs/components/${fileName
.replace('_', '-')
.toLowerCase()}.html`;
}
}

if (relativePath.includes('docs')) {
if (relativePath.endsWith('.md')) {
slug = relativePath.replace('.md', '.html');
Expand Down Expand Up @@ -171,7 +187,7 @@ module.exports = exports.onCreateNode = ({actions, getNode, node}) => {
createNodeField({
name: 'slug',
node,
value: slug,
value: slug || '',
});

createNodeField({
Expand Down
6 changes: 3 additions & 3 deletions clayui.com/src/templates/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default props => {
)}
</div>
<div className="col-12">
{tab ? (
{tab && tab.html ? (
<ul
className="border-bottom nav nav-clay nav-underline"
role="tablist"
Expand Down Expand Up @@ -511,10 +511,10 @@ export const pageQuery = graphql`
}
}
}
mdTab: markdownRemark(fields: {slug: {eq: $sibling}}) {
mdTab: markdownRemark(fields: {slug: {ne: "", eq: $sibling}}) {
html
}
mdxTab: mdx(fields: {slug: {eq: $sibling}}) {
mdxTab: mdx(fields: {slug: {ne: "", eq: $sibling}}) {
code {
body
}
Expand Down
20 changes: 0 additions & 20 deletions packages/clay-css/src/index.md

This file was deleted.

0 comments on commit fc6e798

Please sign in to comment.