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

ctrl-content-manager

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ctrl-content-manager

An abstraction around contentful.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ctrl-content-manager

Build Status Codacy Badge Codacy Badge

An abstraction around contentful.

Installation

Yarn is recommended for installation.

$ yarn add ctrl-content-manager

But you can still use npm:

$ npm install --save ctrl-content-manager

Usage

const _ = require('lodash')
const CtrlContentManager = require('ctrl-content-manager')

const cm = new CtrlContentManager({
  accessTokens: {
    production: 'contentful_production_token'
  , preview: 'contentful_preview_token'
  }
, fetchInterval: 60 * 60 * 1000
, isProduction: process.env.NODE_ENV === 'production'
, space: 'contentful_space_id'
, parsing: {
    keyed: {
      tags: 'title'
    , authors: 'name'
    }
  , singles: [
      'globalElements'
    , 'blogPostElements'
    ]
  }
})

cm.startFetchInterval()

// Psuedo blog server code
http.get('/blog/?slug', (request, reply) {
  // Get URL Slug.
  const slug = request.params.slug

  // Lookup the blog post by slug.
  const blogPost = cm.find('blogPosts', {slug})

  // If that post doesn't exist, show a 404 page with 3 random post suggestions.
  if (!blogPost) {
    return reply('404-template', {
      suggestedBlogs: _.sampleSize(cm.get('blogPosts'), 3)
    })
  }

  // Otherwise
  // Get generic blog post elements. (E.g., nav buttons, colors, section titles)
  const blogPostElements = cm.get('blogPostElements')
  // Get the page title suffix. (E.g., ' - My Blog')
  const titleSuffix = cm.get('globalElements.titleSuffix')
  // Get tags that aren't already tagged on this post.
  const otherTags = _.omit(cm.get('tags'), _.map(blogPost.tags, 'title'))
  // Get authors that aren't this post's author.
  const otherAuthors = _.omit(cm.get('authors'), blogPost.author.name)

  // Render and serve the blog post.
  return reply('blog-post-template', {
    blogPost
  , blogPostElements
  , titleSuffix
  , otherTags
  , otherAuthors
  })
})

Methods

Full documentation to come soon!

License

Copyright (c) 2016 Martin Experiments LLC

MIT (https://www.opensource.org/licenses/MIT)

Keywords

FAQs

Package last updated on 11 May 2017

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