Skip to content

Commit

Permalink
Merge pull request #1 from martindale/release
Browse files Browse the repository at this point in the history
Initial Release
  • Loading branch information
martindale committed Dec 29, 2015
2 parents c52f3ea + 0070437 commit 525f27d
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 37 deletions.
1 change: 1 addition & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
service_name: travis-ci
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.12'
services:
- mongodb
after_script: istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
19 changes: 17 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
# blog.soundtrack.io
Simple blog for the soundtrack.io website.
melody
======
[![Build Status](https://img.shields.io/travis/martindale/melody.svg?branch=master&style=flat-square)](https://travis-ci.org/martindale/melody)
[![Coverage Status](https://img.shields.io/coveralls/martindale/melody.svg?style=flat-square)](https://coveralls.io/r/martindale/melody)
[![Community](https://chat.maki.io/badge.svg)](https://chat.maki.io/)

simple, self-hosted publishing platform.

## Quick Start
After running `npm install`, simply type `npm start`. If it's your first time,
melody will automatically create an admin user and generate a random password.

Extra config values, such as character limit and allowing public registrations,
are available in `config/index.js` for your convenience.

## Hosting
We strongly recommend using `pm2` to manage melody in production.
23 changes: 21 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
module.exports = {
service: {
name: 'melody',
icon: 'music'
name: 'Your Stream Name', // change this!
synopsis: 'Thoughts and musings from me.', // and this...
mission: 'Self-hosted writing and content sharing, powered by Maki', // also
icon: 'write' // pick from: http://semantic-ui.com/elements/icon.html
},
config: {
allowPublicRegistration: false, // let other people register
characterLimit: false // set to a number, such as 140.
},
users: { // users will be created on startup, password logged to console
'admin': { // admin username will be 'admin', change if you'd like
roles: ['admin'] // what roles this user will have
}
},
database: {
name: 'melody' // only change if you know what you're doing
},
services: {
http: {
port: 13005 // you might want this to be 80, or 3000
}
}
};
38 changes: 26 additions & 12 deletions lib/melody.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,39 @@ var passport = new Passport({

var Auth = require('maki-auth-simple');
var auth = new Auth({
resource: 'People'
resource: 'Person',
// capabilities are named arrays of the roles that inherit them
// for example, `'write': ['admin']` indicates that anyone with the 'admin'
// role will inherit the 'write' capability, whatever you decide that means.
capabilities: {
'write': ['admin']
}
});

melody.use(passport);
melody.use(auth);

var PostSchema = {
title: { type: String , max: 240 , slug: true },
content: { type: String },
created: { type: Date , default: Date.now },
_author: {
type: melody.mongoose.SchemaTypes.ObjectId,
ref: 'Person',
populate: ['query', 'get'],
required: true
}
};

if (config.config.characterLimit) {
PostSchema.content.max = config.config.characterLimit;
}

var Post = melody.define('Post', {
auth: ['admin'],
attributes: {
title: { type: String , max: 240 , slug: true },
content: { type: String },
created: { type: Date , default: Date.now },
_author: {
type: melody.mongoose.SchemaTypes.ObjectId,
ref: 'Person',
populate: ['query', 'get'],
required: true
}
auth: {
'create': 'admin'
},
attributes: PostSchema,
icon: 'file text'
});

Expand Down
27 changes: 27 additions & 0 deletions melody.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var config = require('./config');
var crypto = require('crypto');
var melody = require('./lib/melody');

melody.start(function(err) {
var Person = melody.resources.Person;
var usernames = Object.keys(config.users);

usernames.forEach(function(username) {
Person.get({
username: username
}, function(err, person) {
if (err || person) return;
var user = config.users[username];
var password = crypto.randomBytes(12).toString('base64');

user.username = username;
user.password = password;

Person.create(user, function(err, person) {
if (err) return console.error(err);
console.log('Created user "'+person.username+'", password:', password);
});

});
});
});
17 changes: 12 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "melody",
"version": "0.0.0",
"version": "0.1.0",
"description": "simple publishing platform",
"main": "index.js",
"main": "lib/melody.js",
"scripts": {
"test": "mocha",
"start": "node -e \"require('./').start()\""
"test": "NODE_ENV=test mocha --recursive",
"coverage": "NODE_ENV=test istanbul cover _mocha -- --recursive",
"start": "node melody.js"
},
"repository": {
"type": "git",
Expand All @@ -29,8 +30,14 @@
},
"homepage": "https://github.com/martindale/melody",
"dependencies": {
"async": "^1.5.0",
"maki": "git://github.com/martindale/maki",
"maki-auth-simple": "0.0.1",
"maki-auth-simple": "0.1.1",
"maki-passport-local": "0.0.4"
},
"devDependencies": {
"coveralls": "^2.11.6",
"istanbul": "^0.4.1",
"mocha": "^2.3.4"
}
}
9 changes: 9 additions & 0 deletions test/Melody.integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
describe('Melody', function() {
this.timeout(5000);
describe('web server', function() {
it('should run', function(done) {
var melody = require('../lib/melody');
melody.start(done);
});
});
});
6 changes: 3 additions & 3 deletions views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ extends layouts/default
block content
.ui.fluid.column
.ui.grid
.row
.column
if (user)
if (user && user.capabilities && ~user.capabilities.indexOf('write'))
.row
.column
include forms/post-create

.row
Expand Down
40 changes: 37 additions & 3 deletions views/layouts/default.jade
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,48 @@ html.no-js

.row
.column.content(data-for="viewport")

include ../partials/flash

block content

.row
.ui.one.column.stackable.center.aligned
p
small Built with <a href="http://github.com/martindale/maki">Maki</a>.
small powered by <a href="http://github.com/martindale/melody">melody</a>.

script.
$(document).on('click', '*[data-intent=edit]', function(e) {
e.preventDefault();

var $self = $(this);

$.getJSON('/posts/'+$self.data('id'), function(post) {
var editFunction = _.debounce(submitEdits, 250);

var $form = $('<form class="ui form"><div class="field"><textarea rows="20"></textarea></field></form>');
$form.find('textarea').val(post.content).on('keyup', editFunction);

$('*[data-bind='+$self.data('target')+'][data-id='+$self.data('id')+']').replaceWith($form);

function submitEdits() {
var content = $form.find('textarea').val();

$.ajax({
type: 'patch',
url: '/posts/'+$self.data('id'),
dataType: 'json',
headers: {
Accept: 'application/json'
},
data: {
content: content
}
});
}
});


return false;
});

block scripts
6 changes: 0 additions & 6 deletions views/partials/navbar.jade
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,3 @@
a.item(href="/", title="#{config.service.name} Homepage", ng-class="{ active: isActive('/')}")
i.home.icon
| Home
each resource in resources
if (!resource.internal)
a.item(href="#{resource.routes.query}")
if (resource.options.icon)
i.icon(class="#{resource.options.icon}")
| #{resource.plural}
3 changes: 2 additions & 1 deletion views/partials/person.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
a.ui.card(href="/people/#{person.slug}")
.content
.header #{person.username}
.meta joined #{moment(person.created).fromNow()}
.meta joined
abbr.tooltipped(title="#{person.created}") #{moment(person.created).fromNow()}
13 changes: 10 additions & 3 deletions views/partials/post.jade
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
.ui.card.fluid
.content
a.right.floated(href="/people/#{post._author.slug}") #{post._author.username}
h3.header #{post.title}
.right.floated
.ui.buttons
if (user && user.capabilities && ~user.capabilities.indexOf('write'))
a.ui.mini.button(href="#", data-intent="edit", data-target="post-description", data-id="#{post.slug}")
i.icon.edit
| edit
a.ui.mini.button(href="/people/#{post._author.slug}") #{post._author.username}
h3.header
a(href="/posts/#{post.slug}") #{post.title}
.meta
a(href="/posts/#{post.slug}") #{moment(post.created).fromNow()}
.description !{markdown(post.content)}
.description(data-bind="post-description", data-id="#{post.slug}") !{markdown(post.content)}

0 comments on commit 525f27d

Please sign in to comment.