Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
express-content-router
Advanced tools
Generate an express.js router object from a specially formed directory of content object files.
Expects to be used at any mount point as an express router.
Basic usage:
var app = express();
var router = require('express-content-router')(__dirname + "/content");
app.use('/mountpoint/', router);
Also supports an options hash as the second param. Currently only option supported is "sitemap" which should be a valid express view file name reference, to render a test sitemap page at the /sitemap path.
Content is specified in a specific directory, and the actual directory structure determines the page URLs.
Example:
You want an /index.html and /about-us/index.html to be the URLs on your application.
Your directory structure would be the following:
/content/index.js
/content/about-us/index.js
Any level of nesting can be used.
One important caveat - Don't name a file the same thing as a directory at the same level - the directory's content will overwrite the file. This is due to the default behavior of the require-dir module with respect to recursion.
If you do want to have similarly named URLs generated from a filename and directory (both /about.html and /about/detail.html for example), prefix the filename with "@" to avoid the conflict. The library will compensate and generate the expected URL paths.
If you want to have individual blocks of content that are shared between pages (common header/footer, contact, etc), you can put that directly in an underscore-prefixed file at any level, and require it in your main page content object. The underscored files will be ignored by the router, but will be required into each page automatically.
... directory setup
/content/_footer-links.js
/content/page.js
... and in page.js
module.exports = {
...
content: {
footerLinks: require('./_footer-links')
}
}
An object that defines a page should resemble the following:
module.exports = {
// view defines the express view file in your application to render this page
view: "view-file-name",
// page title is used for the <head><title> content
title: "Page Title",
// content is passed to the express view template for rendering
// can contain whatever you need for your project.
content: {
title: "My Awesome Page",
leadParagraph: "Isn't it awesome?"
}
}
Support more features and auto-generated content for building page navigation structures.
Support meta tag definition in the page spec
Global configuration scheme for common site things across all pages. Meta tags, Titles, navigation
Support storing content in a database of some kind instead of the file system.
Support passing in optional global properties for view rendering
Option flag to auto-generate navigation object data
FAQs
Generate express router from js files in a directory
The npm package express-content-router receives a total of 0 weekly downloads. As such, express-content-router popularity was classified as not popular.
We found that express-content-router 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.