mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Updated collection card post fetching to use Content API (#18121)
closes https://github.com/TryGhost/Product/issues/3874 - fetch Content API key if we don't already have it - use the `frontend` service to fetch posts via the Content API - uses same ordering and published-only filtering as default front-end requests
This commit is contained in:
parent
12621d8157
commit
f06f83c45b
@ -131,6 +131,7 @@ const WordCountPlugin = (props) => {
|
||||
export default class KoenigLexicalEditor extends Component {
|
||||
@service ajax;
|
||||
@service feature;
|
||||
@service frontend;
|
||||
@service ghostPaths;
|
||||
@service session;
|
||||
@service store;
|
||||
@ -138,7 +139,9 @@ export default class KoenigLexicalEditor extends Component {
|
||||
@service membersUtils;
|
||||
|
||||
@inject config;
|
||||
|
||||
offers = null;
|
||||
contentKey = null;
|
||||
|
||||
get pinturaJsUrl() {
|
||||
if (!this.settings.pintura) {
|
||||
@ -241,13 +244,20 @@ export default class KoenigLexicalEditor extends Component {
|
||||
};
|
||||
|
||||
const fetchCollectionPosts = async (collectionSlug) => {
|
||||
const collectionPostsEndpoint = this.ghostPaths.url.api('posts');
|
||||
const {posts} = await this.ajax.request(collectionPostsEndpoint, {
|
||||
data: {
|
||||
collection: collectionSlug,
|
||||
limit: 12
|
||||
}
|
||||
});
|
||||
if (!this.contentKey) {
|
||||
const integrations = await this.store.findAll('integration');
|
||||
const contentIntegration = integrations.findBy('slug', 'ghost-core-content');
|
||||
this.contentKey = contentIntegration?.contentKey.secret;
|
||||
}
|
||||
|
||||
const postsUrl = new URL(this.frontend.getUrl('/ghost/api/content/posts/'));
|
||||
postsUrl.searchParams.append('key', this.contentKey);
|
||||
postsUrl.searchParams.append('collection', collectionSlug);
|
||||
postsUrl.searchParams.append('limit', 12);
|
||||
|
||||
const response = await this.frontend.fetch(postsUrl.toString());
|
||||
const {posts} = await response.json();
|
||||
|
||||
return posts;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user