Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: leftovers of release notes layout implementation #350

Merged
merged 2 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions packages/gatsby-theme-docs/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ exports.onPreBootstrap = ({ reporter }) => {
});
};

// Inspired by https://github.com/gatsbyjs/gatsby/blob/ead08cc1fd9fa30a46fa8b6b7411141a5c9ba4f8/packages/gatsby-theme-blog-core/gatsby-node.js#L29
const identity = (node) => node;
const resolverPassthrough = ({
typeName = 'Mdx',
fieldName,
resolveNode = identity,
}) => async (source, args, context, info) => {
const type = info.schema.getType(typeName);
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const field = type.getFields()[fieldName];
const result = await field.resolve(resolveNode(mdxNode), args, context, {
fieldName,
});
return result;
};

exports.sourceNodes = ({ actions, schema }) => {
actions.createTypes(`
type NavigationYaml implements Node @dontInfer {
Expand Down Expand Up @@ -89,32 +107,17 @@ exports.sourceNodes = ({ actions, schema }) => {
beta: { type: 'Boolean!' },
body: {
type: 'String!',
resolve(source, args, context, info) {
const type = info.schema.getType('Mdx');
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const mdxField = type.getFields().body;
return mdxField.resolve(mdxNode, {}, context, {
fieldName: 'body',
});
},
resolve: resolverPassthrough({ fieldName: 'body' }),
},
tableOfContents: {
type: 'JSON',
args: {
maxDepth: { type: 'Int' },
},
resolve(source, args, context, info) {
const type = info.schema.getType('Mdx');
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const mdxField = type.getFields().tableOfContents;
return mdxField.resolve(mdxNode, args, context, {
fieldName: 'tableOfContents',
});
maxDepth: {
type: `Int`,
default: 6,
},
},
resolve: resolverPassthrough({ fieldName: 'tableOfContents' }),
},
},
interfaces: ['Node'],
Expand All @@ -136,37 +139,23 @@ exports.sourceNodes = ({ actions, schema }) => {
type: 'Date!',
args: {
formatString: { type: 'String' },
fromNow: { type: 'Boolean' },
difference: { type: 'String' },
locale: { type: 'String' },
},
resolve(source, args, context, info) {
const type = info.schema.getType('Mdx');
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const mdxField = type.getFields().date;
if (mdxField) {
return mdxField.resolve(mdxNode, args, context, {
fieldName: 'date',
});
}
return '';
},
resolve: resolverPassthrough({
typeName: 'MdxFrontmatter',
fieldName: 'date',
resolveNode: (node) => node.frontmatter,
}),
},
description: { type: 'String!' },
type: { type: 'ReleaseNoteType!' },
topics: { type: '[String!]!' },
published: { type: 'Boolean!' },
body: {
type: 'String!',
resolve(source, args, context, info) {
const type = info.schema.getType('Mdx');
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const mdxField = type.getFields().body;
return mdxField.resolve(mdxNode, {}, context, {
fieldName: 'body',
});
},
resolve: resolverPassthrough({ fieldName: 'body' }),
},
},
interfaces: ['Node'],
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-theme-docs/src/hooks/use-layout-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const useLayoutState = () => {
topMenu: {
isTopMenuOpen,
toggleTopMenu,
closeTopMenu,
},
searchDialog: {
isSearchDialogOpen,
Expand Down
19 changes: 12 additions & 7 deletions packages/gatsby-theme-docs/src/layouts/internals/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ const LinkItem = styled.div`
flex-direction: row;
align-items: flex-end;
`;
const linkStyles = `
border-left: ${designSystem.dimensions.spacings.xs} solid ${designSystem.colors.light.surfaceSecondary1};
padding-left: calc(${designSystem.dimensions.spacings.m} - ${designSystem.dimensions.spacings.xs});
const linkStyles = css`
border-left: ${designSystem.dimensions.spacings.xs} solid
${designSystem.colors.light.surfaceSecondary1};
padding-left: calc(
${designSystem.dimensions.spacings.m} -
${designSystem.dimensions.spacings.xs}
);
text-decoration: none;
color: ${designSystem.colors.light.textSecondary};
display: flex;
Expand All @@ -84,8 +88,9 @@ const linkStyles = `
color: ${designSystem.colors.light.linkNavigation} !important;
}
`;
const activeLinkStyles = `
border-left: ${designSystem.dimensions.spacings.xs} solid ${designSystem.colors.light.linkNavigation} !important;
const activeLinkStyles = css`
border-left: ${designSystem.dimensions.spacings.xs} solid
${designSystem.colors.light.linkNavigation} !important;
color: ${designSystem.colors.light.linkNavigation} !important;
`;

Expand Down Expand Up @@ -133,8 +138,8 @@ const SidebarLink = (props) => {
SidebarLink.propTypes = {
to: PropTypes.string.isRequired,
locationPath: PropTypes.string,
customStyles: PropTypes.string,
customActiveStyles: PropTypes.string,
customStyles: PropTypes.object, // emotion css object
customActiveStyles: PropTypes.object, // emotion css object
};

const SidebarLinkWrapper = (props) => {
Expand Down