mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 20:03:12 +03:00
Sort revision list by createdAt.
refs https://ghost.slack.com/archives/C02G9E68C/p1682941387256079?thread_ts=1682507718.761429&cid=C02G9E68C https://github.com/TryGhost/Team/issues/3123 This commit modifies the revisionList method to sort the revisions array by createdAt property in descending order, instead of reversing the order of the array. This makes the code more intuitive and easier to follow for future developers. Additionally, the published_latest key-value pair is renamed to initial_publish to better reflect its meaning. This key-value pair is added to the revision object at the index where the post status changed from 'draft' to 'published', indicating the initial publication of the post.
This commit is contained in:
parent
d6794e6c43
commit
904a03f81a
@ -63,7 +63,7 @@
|
|||||||
<span class="gh-post-history-version-tag current">Latest</span>
|
<span class="gh-post-history-version-tag current">Latest</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if (eq revision.published_latest true)}}
|
{{#if (eq revision.initial_publish true)}}
|
||||||
<span class="gh-post-history-version-tag published">Published</span>
|
<span class="gh-post-history-version-tag published">Published</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
|
@ -52,9 +52,14 @@ export default class ModalPostHistory extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get revisionList() {
|
get revisionList() {
|
||||||
const revisions = this.post.get('postRevisions').toArray().reverse();
|
// sort revisions by createdAt date
|
||||||
const latestPublishedIndex = revisions.findIndex(
|
const revisions = this.post.get('postRevisions').toArray().sort((a, b) => b.get('createdAt') - a.get('createdAt'));
|
||||||
revision => revision.get('postStatus') === 'published' && revision.get('reason') === 'published'
|
// finds the initial published version
|
||||||
|
const publishedIndex = revisions.findIndex(
|
||||||
|
(revision, index, arr) => (
|
||||||
|
revision.get('postStatus') === 'published' &&
|
||||||
|
arr[index + 1]?.get('postStatus') === 'draft'
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
return revisions.map((revision, index) => {
|
return revisions.map((revision, index) => {
|
||||||
@ -72,7 +77,7 @@ export default class ModalPostHistory extends Component {
|
|||||||
},
|
},
|
||||||
postStatus: revision.get('postStatus'),
|
postStatus: revision.get('postStatus'),
|
||||||
reason: revision.get('reason'),
|
reason: revision.get('reason'),
|
||||||
published_latest: latestPublishedIndex !== -1 && latestPublishedIndex === index
|
initial_publish: publishedIndex !== -1 && index === publishedIndex
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user