Skip to content

Commit

Permalink
intital setup
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddotto committed Jan 1, 2018
1 parent d918215 commit bb09637
Show file tree
Hide file tree
Showing 128 changed files with 42,033 additions and 35 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = true
indent_style = tab

[{*.yml,*.json}]
indent_style = space
indent_size = 2
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public/js/bootstrap
public/js/jquery
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "keystone"
}
42 changes: 7 additions & 35 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,31 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity
# Dependency directory
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# dotenv environment variables file
# Ignore .env configuration files
.env

# Ignore .DS_Store files on OS X
.DS_Store
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node keystone.js
58 changes: 58 additions & 0 deletions keystone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Simulate config options from your production environment by
// customising the .env file in your project's root folder.
require('dotenv').config();

// Require keystone
var keystone = require('keystone');
var cons = require('consolidate');
var nunjucks = require('nunjucks');

// Initialise Keystone with your project's configuration.
// See http://keystonejs.com/guide/config for available options
// and documentation.

keystone.init({
'name': 'david.to',
'brand': 'david.to',

'sass': 'public',
'static': 'public',
'favicon': 'public/favicon.ico',
'views': 'templates/views',
'view engine': '.html',
'custom engine': cons.nunjucks,

'auto update': true,
'session': true,
'auth': true,
'user model': 'User',
});

// Load your project's Models
keystone.import('models');

// Setup common locals for your templates. The following are required for the
// bundled templates and layouts. Any runtime locals (that should be set uniquely
// for each request) should be added to ./routes/middleware.js
keystone.set('locals', {
_: require('lodash'),
env: keystone.get('env'),
utils: keystone.utils,
editable: keystone.content.editable,
});

// Load your project's Routes
keystone.set('routes', require('./routes'));


// Configure the navigation bar in Keystone's Admin UI
keystone.set('nav', {
posts: ['posts', 'post-categories'],
users: 'users',
});

// Start Keystone to connect to your database and initialise the web server



keystone.start();
32 changes: 32 additions & 0 deletions models/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* Post Model
* ==========
*/

var Post = new keystone.List('Post', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true },
});

Post.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
image: { type: Types.CloudinaryImage },
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 },
},
categories: { type: Types.Relationship, ref: 'PostCategory', many: true },
});

Post.schema.virtual('content.full').get(function () {
return this.content.extended || this.content.brief;
});

Post.defaultColumns = 'title, state|20%, author|20%, publishedDate|20%';
Post.register();
18 changes: 18 additions & 0 deletions models/PostCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var keystone = require('keystone');

/**
* PostCategory Model
* ==================
*/

var PostCategory = new keystone.List('PostCategory', {
autokey: { from: 'name', path: 'key', unique: true },
});

PostCategory.add({
name: { type: String, required: true },
});

PostCategory.relationship({ ref: 'Post', path: 'posts', refPath: 'categories' });

PostCategory.register();
34 changes: 34 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var keystone = require('keystone');
var Types = keystone.Field.Types;

/**
* User Model
* ==========
*/
var User = new keystone.List('User');

User.add({
name: { type: Types.Name, required: true, index: true },
email: { type: Types.Email, initial: true, required: true, unique: true, index: true },
password: { type: Types.Password, initial: true, required: true },
}, 'Permissions', {
isAdmin: { type: Boolean, label: 'Can access Keystone', index: true },
});

// Provide access to Keystone
User.schema.virtual('canAccessKeystone').get(function () {
return this.isAdmin;
});


/**
* Relationships
*/
User.relationship({ ref: 'Post', path: 'posts', refPath: 'author' });


/**
* Registration
*/
User.defaultColumns = 'name, email, isAdmin';
User.register();
Loading

0 comments on commit bb09637

Please sign in to comment.