mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added format option to gh-format-post-time helper
fixes https://github.com/TryGhost/Team/issues/1940 The passed format was not used by the helper. This is fixed now.
This commit is contained in:
parent
14f91093eb
commit
cd4e4d7003
3 changed files with 12 additions and 7 deletions
|
@ -24,7 +24,7 @@
|
|||
</span>
|
||||
<span class="gh-content-entry-date">
|
||||
{{#if this.isHovered}}
|
||||
{{gh-format-post-time @post.updatedAtUTC "D MMM YYYY"}}
|
||||
{{gh-format-post-time @post.updatedAtUTC format="D MMM YYYY"}}
|
||||
{{else}}
|
||||
{{gh-format-post-time @post.updatedAtUTC draft=true}}
|
||||
{{/if}}
|
||||
|
@ -65,7 +65,7 @@
|
|||
<span class="gh-content-entry-date" {{on "mouseover" (fn (mut this.isDateHovered) true)}} {{on "mouseleave" (fn (mut this.isDateHovered) false)}}>
|
||||
{{gh-format-post-time @post.updatedAtUTC draft=true}}
|
||||
{{#if this.isDateHovered}}
|
||||
<span {{css-transition "anim-fade-in-scale"}}>on {{gh-format-post-time @post.updatedAtUTC "D MMM YYYY"}}</span>
|
||||
<span {{css-transition "anim-fade-in-scale"}}>on {{gh-format-post-time @post.updatedAtUTC format="D MMM YYYY"}}</span>
|
||||
{{/if}}
|
||||
</span>
|
||||
{{!-- {{#if @post.lexical}}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
in <span class="midgrey-l2 fw5">{{@post.primaryTag.name}}</span>
|
||||
{{/if}}
|
||||
|
||||
• <span data-tooltip="{{gh-format-post-time @post.updatedAtUTC "D MMM YYYY"}}">{{gh-format-post-time @post.updatedAtUTC draft=true}}</span>
|
||||
• <span data-tooltip="{{gh-format-post-time @post.updatedAtUTC format="D MMM YYYY"}}">{{gh-format-post-time @post.updatedAtUTC draft=true}}</span>
|
||||
|
||||
</span>
|
||||
</p>
|
||||
|
@ -43,7 +43,7 @@
|
|||
in <span class="midgrey-l2 fw5">{{@post.primaryTag.name}}</span>
|
||||
{{/if}}
|
||||
|
||||
• <span data-tooltip="{{gh-format-post-time @post.updatedAtUTC "D MMM YYYY"}}">{{gh-format-post-time @post.updatedAtUTC draft=true}}</span>
|
||||
• <span data-tooltip="{{gh-format-post-time @post.updatedAtUTC format="D MMM YYYY"}}">{{gh-format-post-time @post.updatedAtUTC draft=true}}</span>
|
||||
|
||||
</span>
|
||||
</p>
|
||||
|
|
|
@ -3,13 +3,18 @@ import moment from 'moment';
|
|||
import {assert} from '@ember/debug';
|
||||
import {inject as service} from '@ember/service';
|
||||
|
||||
export function formatPostTime(timeago, {timezone = 'etc/UTC', draft, scheduled, published}) {
|
||||
export function formatPostTime(timeago, {timezone = 'etc/UTC', format, draft, scheduled, published}) {
|
||||
if (draft) {
|
||||
// No special handling for drafts, just use moment.from
|
||||
return moment(timeago).from(moment.utc());
|
||||
}
|
||||
|
||||
let time = moment.tz(timeago, timezone);
|
||||
|
||||
if (format) {
|
||||
return time.format(format);
|
||||
}
|
||||
|
||||
let now = moment.tz(moment.utc(), timezone);
|
||||
|
||||
let utcOffset;
|
||||
|
@ -44,8 +49,8 @@ export function formatPostTime(timeago, {timezone = 'etc/UTC', draft, scheduled,
|
|||
}
|
||||
|
||||
// Else, render just the date if published, or the time & date if scheduled
|
||||
let format = scheduled ? `[at] HH:mm [${utcOffset}] [on] DD MMM YYYY` : 'DD MMM YYYY';
|
||||
return time.format(format);
|
||||
let f = scheduled ? `[at] HH:mm [${utcOffset}] [on] DD MMM YYYY` : 'DD MMM YYYY';
|
||||
return time.format(f);
|
||||
}
|
||||
|
||||
export default class GhFormatPostTimeHelper extends Helper {
|
||||
|
|
Loading…
Add table
Reference in a new issue