diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js b/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js index 5e9a082279..f0494c1327 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/input/posts.js @@ -92,18 +92,11 @@ function defaultRelations(frame) { } function setDefaultOrder(frame) { - let includesOrderedRelations = false; - - if (frame.options.withRelated) { - const orderedRelations = ['author', 'authors', 'tag', 'tags']; - includesOrderedRelations = _.intersection(orderedRelations, frame.options.withRelated).length > 0; - } - - if (!frame.options.order && !includesOrderedRelations && frame.options.filter) { + if (!frame.options.order && frame.options.filter) { frame.options.autoOrder = slugFilterOrder('posts', frame.options.filter); } - if (!frame.options.order && !frame.options.autoOrder && !includesOrderedRelations) { + if (!frame.options.order && !frame.options.autoOrder) { frame.options.order = 'published_at desc'; } } diff --git a/ghost/core/test/e2e-api/content/__snapshots__/posts.test.js.snap b/ghost/core/test/e2e-api/content/__snapshots__/posts.test.js.snap index afd79779a3..c2f42af62e 100644 --- a/ghost/core/test/e2e-api/content/__snapshots__/posts.test.js.snap +++ b/ghost/core/test/e2e-api/content/__snapshots__/posts.test.js.snap @@ -786,100 +786,6 @@ Object { }, }, "posts": Array [ - Object { - "access": true, - "authors": Array [ - Object { - "bio": "bio", - "cover_image": null, - "facebook": null, - "id": "1", - "location": "location", - "meta_description": null, - "meta_title": null, - "name": "Joe Bloggs", - "profile_image": "https://example.com/super_photo.jpg", - "slug": "joe-bloggs", - "twitter": null, - "url": "http://127.0.0.1:2369/author/joe-bloggs/", - "website": null, - }, - Object { - "bio": "bio", - "cover_image": null, - "facebook": null, - "id": "6193c685e792de832cd08141", - "location": "location", - "meta_description": null, - "meta_title": null, - "name": "Slimer McEctoplasm", - "profile_image": null, - "slug": "slimer-mcectoplasm", - "twitter": null, - "url": "http://127.0.0.1:2369/404/", - "website": null, - }, - ], - "canonical_url": null, - "codeinjection_foot": null, - "codeinjection_head": null, - "comment_id": "618ba1ffbe2896088840a6e7", - "comments": false, - "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, - "custom_excerpt": null, - "custom_template": null, - "email_subject": null, - "excerpt": " * Lorem - * Aliquam - * Tortor - * Morbi - * Praesent - * Pellentesque - -Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. - -1234abcdefghijkl - -Definition listConsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim venia", - "feature_image": null, - "feature_image_alt": null, - "feature_image_caption": null, - "featured": true, - "frontmatter": null, - "html": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

1234
abcd
efgh
ijkl
Definition list
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

", - "id": "618ba1ffbe2896088840a6e7", - "meta_description": null, - "meta_title": null, - "og_description": null, - "og_image": null, - "og_title": null, - "primary_author": Object { - "bio": "bio", - "cover_image": null, - "facebook": null, - "id": "1", - "location": "location", - "meta_description": null, - "meta_title": null, - "name": "Joe Bloggs", - "profile_image": "https://example.com/super_photo.jpg", - "slug": "joe-bloggs", - "twitter": null, - "url": "http://127.0.0.1:2369/author/joe-bloggs/", - "website": null, - }, - "published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, - "reading_time": 1, - "slug": "not-so-short-bit-complex", - "title": "Not so short, bit complex", - "twitter_description": null, - "twitter_image": null, - "twitter_title": null, - "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, - "url": "http://127.0.0.1:2369/not-so-short-bit-complex/", - "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, - "visibility": "public", - }, Object { "access": true, "authors": Array [ @@ -1386,6 +1292,100 @@ Most successful subscription businesses publish a mix of free and paid posts to "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, "visibility": "public", }, + Object { + "access": true, + "authors": Array [ + Object { + "bio": "bio", + "cover_image": null, + "facebook": null, + "id": "1", + "location": "location", + "meta_description": null, + "meta_title": null, + "name": "Joe Bloggs", + "profile_image": "https://example.com/super_photo.jpg", + "slug": "joe-bloggs", + "twitter": null, + "url": "http://127.0.0.1:2369/author/joe-bloggs/", + "website": null, + }, + Object { + "bio": "bio", + "cover_image": null, + "facebook": null, + "id": "6193c685e792de832cd08141", + "location": "location", + "meta_description": null, + "meta_title": null, + "name": "Slimer McEctoplasm", + "profile_image": null, + "slug": "slimer-mcectoplasm", + "twitter": null, + "url": "http://127.0.0.1:2369/404/", + "website": null, + }, + ], + "canonical_url": null, + "codeinjection_foot": null, + "codeinjection_head": null, + "comment_id": "618ba1ffbe2896088840a6e7", + "comments": false, + "created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, + "custom_excerpt": null, + "custom_template": null, + "email_subject": null, + "excerpt": " * Lorem + * Aliquam + * Tortor + * Morbi + * Praesent + * Pellentesque + +Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. + +1234abcdefghijkl + +Definition listConsectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim venia", + "feature_image": null, + "feature_image_alt": null, + "feature_image_caption": null, + "featured": true, + "frontmatter": null, + "html": "

Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.

1234
abcd
efgh
ijkl
Definition list
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Lorem ipsum dolor sit amet
Consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

", + "id": "618ba1ffbe2896088840a6e7", + "meta_description": null, + "meta_title": null, + "og_description": null, + "og_image": null, + "og_title": null, + "primary_author": Object { + "bio": "bio", + "cover_image": null, + "facebook": null, + "id": "1", + "location": "location", + "meta_description": null, + "meta_title": null, + "name": "Joe Bloggs", + "profile_image": "https://example.com/super_photo.jpg", + "slug": "joe-bloggs", + "twitter": null, + "url": "http://127.0.0.1:2369/author/joe-bloggs/", + "website": null, + }, + "published_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, + "reading_time": 1, + "slug": "not-so-short-bit-complex", + "title": "Not so short, bit complex", + "twitter_description": null, + "twitter_image": null, + "twitter_title": null, + "updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000\\\\\\+\\\\d\\{2\\}:\\\\d\\{2\\}/, + "url": "http://127.0.0.1:2369/not-so-short-bit-complex/", + "uuid": StringMatching /\\[a-f0-9\\]\\{8\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{4\\}-\\[a-f0-9\\]\\{12\\}/, + "visibility": "public", + }, Object { "access": true, "authors": Array [ diff --git a/ghost/core/test/e2e-api/content/posts.test.js b/ghost/core/test/e2e-api/content/posts.test.js index 38ce3db2bb..f5280b7a72 100644 --- a/ghost/core/test/e2e-api/content/posts.test.js +++ b/ghost/core/test/e2e-api/content/posts.test.js @@ -159,7 +159,7 @@ describe('Posts Content API', function () { const jsonResponse = res.body; - assert.equal(jsonResponse.posts[0].slug, 'not-so-short-bit-complex', 'The API orders by number of matched authors'); + assert.equal(jsonResponse.posts[0].slug, 'welcome', 'The API orders by number of matched authors, then by published_at desc, then by id desc'); const primaryAuthors = jsonResponse.posts.map((post) => { return post.primary_author.slug;