
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
keystone-menus
Advanced tools
To install, simply add keystone-menus to the list of dependencies in your Keystone application's package.json and run npm install.
1. In your application's keystone.js file, include the module, import its models, and add the models to your Keystone admin UI:
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').load();
// Require keystone
var keystone = require('keystone');
var KeystoneMenus = require('keystone-menus');
// etc...
keystone.import('models');
KeystoneMenus.import(keystone);
// etc...
keystone.set('nav', {
// Your application's models that are loaded into the admin UI would be here.
'menus': ['menus', 'menu-items']
});
keystone.start();
2. Start up your application and add the menus and menu items that you will be using in the admin UI. Reference the Objects section for details on the Menu and MenuItem objects and their fields.
3. In your routes (most likely in middleware.js, unless the menus only need to load on certain pages) initialize the MenuBuilder object, then use it to build a menu. Once the menu is built, render it.
var KeystoneMenus = require('keystone-menus');
exports.initLocals = function(req, res, next) {
var locals = res.locals;
var builder = KeystoneMenus.builder();
builder.build('navLinks')
.then(function(menu){
locals.navLinks = menu.render(req.path, {'class': 'nav navbar-left visible-md-block visible-lg-block'}, {}, {});
});
builder.build('subNavLinks')
.then(function(menu){
locals.subNavLinks = menu.render(req.path, {'class': ' nav navbar-right visible-md-block visible-lg-block'}, {}, {});
});
// etc.
};
The render function has 4 parameters:
4. Reference your rendered menu templates in your views.
.navbar-links
!= navLinks
FAQs
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.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.