New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

keystone-blog

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

keystone-blog

A Node.js module for quickly and easily loading a blog into an existing Keystone.js implementation.

  • 1.1.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Keystone Blog

Installation

To install, simply add keystone-blog to the list of dependencies in your Keystone application's package.json and run npm install.

Usage

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 KeystoneBlog = require('keystone-blog');

// etc...

keystone.import('models');
KeystoneBlog.import(keystone);

// etc...

keystone.set('nav', {
	// Your application's models that are loaded into the admin UI would be here.
	'blog': ['tags', 'blog-posts'],
  // and here
});

keystone.start();

2. In your index.js route, initialize a PostController and use it to either render the jade templates provided with this module or get a list of posts. Either way, do this step as a middleware function. (The module is set up to only need one route, and any request parameters are treated as a slug for the blog post. Also, a slug of "popular" will show the index of the blog, but sorted by popularity. ie. {your-app-url}/blog would return the index and {your-app-url}/blog/post-1 would display the blog post with the title "Post 1")

var keystone = require('keystone')
	, express = keystone.express
	, api = express.Router()
	, middleware = require('./middleware')
	, PostController = require('keystone-blog').PostController
	, blogController = new PostController("true", 4, 4, "LL");
// etc.

// Common Middleware
keystone.pre('routes', middleware.initErrorHandlers);
keystone.pre('routes', middleware.initLocals);
keystone.pre('render', middleware.flashMessages);


// Import Route Controllers
var routes = {
	views: importRoutes('./views'),
	api: importRoutes('./api')
};

// Setup Route Bindings
exports = module.exports = function(app) {
  // etc.
	app.get('/blog/:post?', blogController.request, routes.views.blog);
	// etc.
};

The PostController constructor has 4 (optional) parameters:

  • render Whether the keystone-blog module should render jade templates. If "true", a rendered template is returned. If "false", index methods will return a list of Post instances and show methods will return Post instances. Defaults to "true". (This field must be a string rather than a boolean or else it will always default to true)
  • perPage The number of blog posts to show on a single index page. Defaults to 10.
  • maxPages The number of pages to show in the pagination navigation. Defaults to 5.
  • dateFormat The format to show the blog date. Defaults to "llll". See http://momentjs.com/#format-dates

3. Create a route file and view for your blog page. In the route file, attach either req.renderedTemplate or req.post(s) (depending on whether your render parameter in the PostController is true) to locals, and it can then be used in your jade template.

./routes/views/blog.js

var keystone = require('keystone');

exports = module.exports = function(req, res) {
	var view = new keystone.View(req, res);
	var locals = res.locals;
	locals.section = 'blog';
	locals.path = req.path;
  // render = true
	locals.renderedTemplate = req.renderedTemplate;
  // render = false
  if(req.posts) {
    locals.posts = req.posts;
  } else {
    locals.post = req.post;
  }
	view.render('blog');
};

./templates/views/blog.jade

.blog
  != renderedTemplate

Or

if posts
  .blog
    each post in posts
    //- etc
else
  .post
  //- etc

4. Style to your heart's content in your application's stylesheets and start blogging through the Keystone admin UI!

Objects

Tag
  • Name: The name of the tag
  • Slug: Auto-generated by Name. This value can be used to filter the blog posts by adding "?tag={slug}" to the blog index url
BlogPost
  • Name: The name of the post
  • Author: The author of the post. The type of this model is pulled from your keystone configuration as your user model
  • Slug: Auto-generated by Name. This is used for the route that links directly to the post
  • Tags: Tags that specify the category or topic of the post.
  • Featured image: An image that can be uploaded. If you choose to use the module's rendered template this image will be shown in the index above each blog post.
  • Preview: The text that is shown for each post in the blog index
  • Body: The body of the blog.
  • Created At: Datetime when the post was made.
  • Views: How many times the post has been viewed. This is session-specific.

Keywords

FAQs

Package last updated on 11 Feb 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