Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
gatsby-plugin-universal-menus
Advanced tools
Gatsby plugin universal menus. Unlimited nested menus. source from local markdown files or source from anywhere
A menu plugin for Gatsby that allows for infinitely nested menus. Can also be extended to load menus from any source.
Full support for extracting menus defined in markdown from soiurce-filesystem.
:Martin Andersen marander@pm.me (@webmaistro)
`npm install --save gatsby-plugin-universal-menus`
// gatsby-config.js
plugins: [
{
resolve: 'gatsby-plugin-universal-menus',
options: {
// static definition of menu items (optional)
menus: {
main: // identifier of menu container
[ // array of contained children menu items
{
identifier: 'myId', // identifier for this item (optional)
title: 'Title for page',
url: '/page-1/',
weight: 1
}
]
},
// Gatsby node types from which we extract menus (optional, see "Advanced usage")
sourceNodeType: 'MarkdownRemark',
// the relative node path where we can find the 'menus' container (optional)
sourceDataPath: 'frontmatter',
// the relative node path where we can find the page's URL (required)
sourceUrlPath: 'fields.url',
// custom menu loading function (optional)
menuLoader: customLoaderFunction,
// the property to use for injecting to the page context (optional, see "Advanced usage")
pageContextProperty: 'menus',
},
},
],
By default, all Markdown pages can define which menus contain them.
See Advanced usage to learn how to extract menus from other sources.
There are several supported ways to add a page to a menu:
---
title: Lorem Ipsum
menus: main # identifier of menu container
---
---
title: Lorem Ipsum
menus:
- main
- footer
---
---
title: Lorem Ipsum
menus:
main:
identifier: myId # identifier for this item (optional)
title: Go to Lorem Ipsum # override title for this item
weight: 1
---
A sample GraphQL query to get menus:
{
menus {
main {
identifier
title
url
items {
identifier
title
url
}
}
footer {
identifier
title
url
}
}
}
The field items
contains the sub-menu items if available. The query should nest to accommodate the maximum hierarchy needed.
Items within a menu are first ordered by their defined weight
(both from static and page menu items). If weights are equal, then menu items defined in the plugin options (static) are placed first by their appearance order, followed by page menu items ordered by their page's creation time (birthTime).
The plugin defines the following options to customize where menu information is extracted from:
sourceNodeType
- The Gatsby node type we want to extract menus from (default: MarkdownRemark)
sourceDataPath
- The relative path in the node where we expect to find the menus
item which contains menu information. In case there is no explicit title defined for the menu item, we attempt to find the default title under ${sourceDataPath}.title
. (default: frontmatter)
sourceUrlPath
- The relative path in the node where we expect to find the page's URL. This option is always required.
If more flexibility is needed for deciding how menus are loaded, a custom function should be defined.
It is possible to override the default behavior of extracting menu items from Markdown pages by providing your own custom loader function.
// gatsby-config.js
plugins: [
{
resolve: 'gatsby-plugin-universal-menus',
options: {
...// custom menu loading function (optional)
menuLoader: customLoaderFunction,
},
},
],
customLoaderFunction = (loaderActions) => {
const { getNodesByType, getNode } = loaderActions
...
return {
main: [
{
identifier: 'myId',
title: 'Title for page',
url: '/page-1/',
weight: 1,
data: {
... // custom data that will be made available via graphql
}
}
]
}
}
Menu items created from Markdown pages expose additional information about the page they were generated from. We can use that information to include other information that was defined in the Markdown page's frontmatter.
---
title: Lorem Ipsum
moreInfo: Additional pieces of information
menus: main
---
{
menus {
main {
identifier
title
url
page {
frontmatter {
moreInfo
}
}
}
}
}
The plugin can be used to inject the menus structure directly into the context of your Gatsby pages.
To enable this, set the pageContextProperty
option:
// gatsby-config.js
pageContextProperty: 'menus'
And the menus will be available in the page's context:
this.props.pageContext.menus
FAQs
Gatsby plugin universal menus. Unlimited nested menus. source from local markdown files or source from anywhere
We found that gatsby-plugin-universal-menus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.