Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-content-router

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-content-router

Generate express router from js files in a directory

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

express-content-router

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 Structure

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')
    }
}

Page Object Spec

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?"
    }
}

Roadmap / TODOs

  • 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

Keywords

FAQs

Package last updated on 03 May 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc