closes #195 posts date on content page

- adds dateFormat handlebars helper for client side with extra option to format in time since style
- adds this extra dateFormat option to existing server side helper.
- adds scss for draft and scheduled status
- adds true/false values to post for draft  and published to validate in handlebars
- changes admin>content post collection query to order posts by updated_at values in router.js
- adds minified moment.js and links to moment.js and helper.js for clientside
This commit is contained in:
cobbspur 2013-07-04 19:42:49 +01:00
parent 3b96c7d591
commit 8bbacd9ec9
9 changed files with 53 additions and 5 deletions

View File

@ -0,0 +1,16 @@
/*globals Handlebars, moment
*/
(function () {
"use strict";
Handlebars.registerHelper('dateFormat', function (context, block) {
var f = block.hash.format || "MMM Do, YYYY",
timeago = block.hash.timeago,
date;
if (timeago) {
date = moment(context).fromNow();
} else {
date = moment(context).format(f);
}
return date;
});
}());

View File

@ -9,6 +9,10 @@
},
parse: function (resp) {
if (resp.status) {
resp.published = !!(resp.status === "published");
resp.draft = !!(resp.status === "draft");
}
if (resp.tags) {
// TODO: parse tags into it's own collection on the model (this.tags)
return resp;

View File

@ -16,7 +16,7 @@
blog: function () {
var posts = new Ghost.Collections.Posts();
posts.fetch({ data: { status: 'all' } }).then(function () {
posts.fetch({ data: { status: 'all', orderBy: ['updated_at', 'DESC'] } }).then(function () {
Ghost.currentView = new Ghost.Views.Blog({ el: '#main', collection: posts });
});
},

File diff suppressed because one or more lines are too long

View File

@ -1164,3 +1164,11 @@ main {
}
}
.status-draft {
color: $red;
}
.status-scheduled {
color: $orange;
}

View File

@ -1,7 +1,12 @@
<a class="permalink{{#if featured}} featured{{/if}}" href="#">
<h3 class="entry-title">{{title}}</h3>
<section class="entry-meta">
<time datetime="2013-01-04" class="date">5 minutes ago</time>
<time datetime="2013-01-04" class="date">
{{#if published}}Published
{{#if updated_at}}{{dateFormat updated_at timeago="True"}}
{{else}}{{dateFormat published_at timeago="True"}}{{/if}}
{{else}}<span class="status-draft">Draft</span>{{/if}}
</time>
{{!<span class="views">1,934</span>}}
</section>
</a>

View File

@ -3,7 +3,7 @@
<span class="hidden">Star</span>
</a>
{{! TODO: JavaScript toggle featured/unfeatured}}
<span class="status">Published</span>
<span class="status">{{#if published}}Published{{else}}Written{{/if}}</span>
<span class="normal">by</span>
<span class="author">Joe Bloggs</span>
<section class="post-controls">

View File

@ -53,6 +53,8 @@
<script src="/core/admin/assets/js/admin-ui-temp.js"></script>
<script src="/core/admin/assets/js/markdown-actions.js"></script>
<script src="/core/admin/assets/js/tagui.js"></script>
<script src="/core/admin/assets/lib/moment.js"></script>
<script src="/core/admin/assets/js/helpers/index.js"></script>
<!-- // require '/core/admin/assets/js/models/*' -->
<script src="/core/admin/assets/js/models/post.js"></script>

View File

@ -15,8 +15,15 @@ coreHelpers = function (ghost) {
* @return {Object} A Moment time / date object
*/
ghost.registerThemeHelper('dateFormat', function (context, block) {
var f = block.hash.format || "MMM Do, YYYY";
return moment(context).format(f);
var f = block.hash.format || "MMM Do, YYYY",
timeago = block.hash.timeago,
date;
if (timeago) {
date = moment(context).fromNow();
} else {
date = moment(context).format(f);
}
return date;
});
/**