-
Notifications
You must be signed in to change notification settings - Fork 394
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
Move sidebar logic to theme #3133
Conversation
baf3fa9
to
8b92ebe
Compare
function normalizeSidebar({ | ||
function normalizeSidebar( | ||
data, | ||
parentPath, | ||
parentResultRef, | ||
startingPrevRef | ||
}) { | ||
{ parentPath = '', parentResultRef, startingPrevRef } = {} | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small tweak to the signature to make this function more natural to use IMO, the rest of the args are only used in recursive calls so the function's practically unary.
@@ -0,0 +1 @@ | |||
module.exports = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just here to be shadowed
interface ISidebarMenuItemProps { | ||
children?: Array<{ label: string; path: string; source: boolean | string }> | ||
label: string | ||
path: string | ||
source: boolean | string | ||
item: INormalizedSidebarItem | ||
onClick: (isLeafItemClicked: boolean) => void | ||
activePaths?: Array<string> | ||
type?: string | ||
style?: string | ||
icon?: string | ||
} | ||
|
||
const SidebarMenuItem: React.FC<ISidebarMenuItemProps> = ({ | ||
children, | ||
label, | ||
path, | ||
item: { children, label, path, style, icon, type }, | ||
activePaths, | ||
onClick, | ||
style, | ||
icon, | ||
type | ||
onClick |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight signature tweak which makes more sense to me now that we have a type def for sidebar items.
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const normalizeSidebar = require('../../plugins/gatsby-theme-iterative-docs/normalize-sidebar') | ||
const sidebar = require('../../content/docs/sidebar.json') | ||
module.exports = normalizeSidebar(sidebar) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shadowed sidebar file must be present at this specific path and default export a normalized sidebar. It also must be ES5 format to be used in gatsby-node
contexts like remark plugins and server redirects- while non-webpack contexts don't recognize shadows, they can still require this file directly.
0c83a11
to
a24e1d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@rogermparent is it still a draft, should we merge this? |
#3143 was originally part of this, but moved to make reviewing each individual feature easier.
This PR moves all our sidebar logic to our new reusable Gatsby theme.
Since the sidebars and logic have to be imported in both Gatsby Webpack and plain node environments while still being reusable, the sidebar leans on Gatsby Themes but in such a way that it can work in regular node. To help make this possible, sidebar normalization and helpers have been split and the helpers must be called on an imported instance of the sidebar- this helps particularly with plain Node.