Permalink
Browse files

page editing is working! no adding new pages as yet...

  • Loading branch information...
jaredly committed Jan 21, 2015
1 parent 8b652f7 commit 2b5f8529585fc2a6e9afe451f36af6e355a88e66
Showing with 26 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. +12 −12 api.js
  3. +5 −5 client/editor.js
  4. +2 −1 client/page.js
  5. +1 −1 client/pages.js
  6. +1 −1 client/router.js
  7. +4 −3 update.js
View
@@ -4,3 +4,4 @@ www/bundle.js
docs/demo/admin/bundle.js
public
db.json
*.swp
View
24 api.js
@@ -1,6 +1,8 @@
var path = require('path')
var fs = require('fs')
var update = require('./update')
var updateAny = require('./update')
, updatePage = updateAny.bind(null, 'Page')
, update = updateAny.bind(null, 'Post')
function addIsDraft(post) {
post.isDraft = post.source.indexOf('_draft') === 0
@@ -46,22 +48,23 @@ module.exports = function (app) {
use('tags-and-categories', function (req, res) {
res.done(tagsAndCategories())
});
use('pages/list', function (req, res) {
var page = hexo.model('Page')
res.done(page.toArray().map(addIsDraft));
});
/** NOT WORKING. Is there a fn in hexo for creating a page?
use('pages/new', function (req, res, next) {
if (req.method !== 'Page') return next()
if (req.method !== 'POST') return next()
if (!req.body) {
return res.send(400, 'No page body given');
}
if (!req.body.title) {
return res.send(400, 'No title given');
}
hexo.page.create({title: req.body.title, layout: 'draft', date: new Date()}, function (err, filename, content) {
hexo.post.create({title: req.body.title, layout: 'page', date: new Date()}, function (err, filename, content) {
if (err) {
console.error(err, err.stack)
return res.send(500, 'Failed to create page')
@@ -74,20 +77,17 @@ module.exports = function (app) {
});
});
});
**/
use('pages/', function (req, res, next) {
var url = req.url
console.log('in pages', url)
if (url[url.length - 1] === '/') {
url = url.slice(0, -1)
}
var parts = url.split('/')
var last = parts[parts.length-1]
if (last === 'publish') {
return publish(parts[parts.length-2], req.body, res)
}
if (last === 'unpublish') {
return unpublish(parts[parts.length-2], req.body, res)
}
// not currently used?
if (last === 'remove') {
return remove(parts[parts.length-2], req.body, res)
}
@@ -104,7 +104,7 @@ module.exports = function (app) {
return res.send(400, 'No page body given');
}
update(id, req.body, function (err, page) {
updatePage(id, req.body, function (err, page) {
if (err) {
return res.send(400, err);
}
@@ -114,7 +114,7 @@ module.exports = function (app) {
})
});
});
use('posts/list', function (req, res) {
var post = hexo.model('Post')
res.done(post.toArray().map(addIsDraft));
View
@@ -10,6 +10,7 @@ var ConfigDropper = require('./config-dropper')
var Editor = React.createClass({
propTypes: {
post: PT.object,
raw: PT.string,
onChangeTitle: PT.func,
title: PT.string,
@@ -40,18 +41,17 @@ var Editor = React.createClass({
className='editor_title'
value={this.props.title}
onChange={this.handleChangeTitle}/>
<ConfigDropper
{!this.props.isPage && <ConfigDropper
post={this.props.post}
page={this.props.page}
tagsAndCategories={this.props.tagsAndCategories}
onChange={this.props.onChange}/>
{this.props.isDraft ?
onChange={this.props.onChange}/>}
{!this.props.isPage && (this.props.isDraft ?
<button className="editor_publish" onClick={this.props.onPublish}>
Publish
</button> :
<button className="editor_unpublish" onClick={this.props.onUnpublish}>
Unpublish
</button>}
</button>)}
</div>
<div className="editor_main">
<div className="editor_edit">
View
@@ -97,7 +97,8 @@ var Page = React.createClass({
}
var permaLink = '/' + page.path
return Editor({
page: this.state.page,
isPage: true,
post: this.state.page,
raw: this.state.initialRaw,
wordCount: this.state.raw ? this.state.raw.split(' ').length : 0,
isDraft: page.isDraft,
View
@@ -48,7 +48,7 @@ var Pages = React.createClass({
var current = this.state.pages[this.state.selected] || {}
return <div className="posts">
<ul className='posts_list'>
<Newpage onNew={this._onNew}/>
{/** not working atm <Newpage onNew={this._onNew}/> **/}
{
this.state.pages.map((page, i) =>
<li key={page._id} className={cx({
View
@@ -11,8 +11,8 @@ module.exports = () => {
return <Route handler={App}>
<Route name="posts" handler={Posts} path="/"/>
<Route name="post" handler={Post} path="/posts/:postId"/>
<Route name="pages" handler={Pages} path="/pages"/>
<Route name="page" handler={Page} path="/pages/:pageId"/>
<Route name="pages" handler={Pages} path="/pages"/>
<Route name="about" handler={About}/>
</Route>
}
View
@@ -10,12 +10,13 @@ var fs = require('fs'),
* Updates a post.
*
* @method update
* @param {str} model the type of model being updated
* @param {Object} post a post model
* @param {Object} update attributes to update
* @param {Function} callback
*/
module.exports = function (id, update, callback) {
var post = hexo.model('Post').get(id)
module.exports = function (model, id, update, callback) {
var post = hexo.model(model).get(id)
if (!post) {
return callback('Post not found');
}
@@ -61,7 +62,7 @@ module.exports = function (id, update, callback) {
}
hexo.source.process([post.source], function () {
console.log(post.full_source, post.source)
callback(null, hexo.model('Post').get(id));
callback(null, hexo.model(model).get(id));
});
});
});

0 comments on commit 2b5f852

Please sign in to comment.