0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Added "index" built in collection

closes https://github.com/TryGhost/Team/issues/3425

- Index collection is needed to support one of the usecases we have in the near future where we'd hold all posts that would be displayed on the "index" page.
This commit is contained in:
Naz 2023-06-12 12:57:52 +07:00
parent 6421e202e5
commit bb4e2fcadb
No known key found for this signature in database
4 changed files with 75 additions and 8 deletions

View file

@ -1,4 +1,11 @@
module.exports = [{
title: 'Index',
slug: 'index',
description: 'Collection with all posts',
type: 'automatic',
deletable: false,
filter: 'status:published'
}, {
title: 'Featured Posts',
slug: 'featured',
description: 'Collection of featured posts',

View file

@ -39,12 +39,14 @@ class CollectionsServiceWrapper {
}
async init() {
const featuredCollections = await this.api.getAll({filter: 'slug:featured'});
const existingBuiltins = await this.api.getAll({filter: 'slug:featured'});
if (!featuredCollections.data.length) {
require('./built-in-collections').forEach((collection) => {
this.api.createCollection(collection);
});
if (!existingBuiltins.data.length) {
const builtInCollections = require('./built-in-collections');
for (const collection of builtInCollections) {
await this.api.createCollection(collection);
}
}
}
}

View file

@ -182,6 +182,63 @@ Object {
exports[`Collections API Can browse Collections 1: [body] 1`] = `
Object {
"collections": Array [
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": "Collection with all posts",
"feature_image": null,
"filter": "status:published",
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"posts": Array [
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
Object {
"id": StringMatching /\\[a-f0-9\\]\\{24\\}/,
"sort_order": Any<Number>,
},
],
"slug": "index",
"title": "Index",
"type": "automatic",
"updated_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
},
Object {
"created_at": StringMatching /\\\\d\\{4\\}-\\\\d\\{2\\}-\\\\d\\{2\\}T\\\\d\\{2\\}:\\\\d\\{2\\}:\\\\d\\{2\\}\\\\\\.000Z/,
"description": "Collection of featured posts",
@ -217,12 +274,12 @@ Object {
],
"meta": Object {
"pagination": Object {
"limit": 2,
"limit": 3,
"next": null,
"page": 1,
"pages": 1,
"prev": null,
"total": 2,
"total": 3,
},
},
}
@ -232,7 +289,7 @@ exports[`Collections API Can browse Collections 2: [headers] 1`] = `
Object {
"access-control-allow-origin": "http://127.0.0.1:2369",
"cache-control": "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0",
"content-length": "725",
"content-length": "1530",
"content-type": "application/json; charset=utf-8",
"content-version": StringMatching /v\\\\d\\+\\\\\\.\\\\d\\+/,
"etag": StringMatching /\\(\\?:W\\\\/\\)\\?"\\(\\?:\\[ !#-\\\\x7E\\\\x80-\\\\xFF\\]\\*\\|\\\\r\\\\n\\[\\\\t \\]\\|\\\\\\\\\\.\\)\\*"/,

View file

@ -84,6 +84,7 @@ describe('Collections API', function () {
})
.matchBodySnapshot({
collections: [
buildMatcher(11, {withSortOrder: true}),
buildMatcher(2, {withSortOrder: true}),
buildMatcher(0)
]