Enabled collections rendering (#18150)

refs TryGhost/Product#3883
- passes endpoint through to the lexical renderer for collections
rendering
- ghost still needs a `kg-default-nodes` and `kg-lexical-html-renderer`
update to support this completely
This commit is contained in:
Steve Larson 2023-09-14 20:22:18 -05:00 committed by GitHub
parent 384c232b1a
commit 488af56ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,6 +3,8 @@ const errors = require('@tryghost/errors');
const urlUtils = require('../../shared/url-utils');
const config = require('../../shared/config');
const storage = require('../adapters/storage');
const getPostServiceInstance = require('../services/posts/posts-service');
const postsService = getPostServiceInstance();
let nodes;
let lexicalHtmlRenderer;
@ -28,6 +30,13 @@ module.exports = {
},
async render(lexical, userOptions = {}) {
const getCollectionPosts = async (collectionSlug, postCount) => {
const transacting = userOptions.transacting;
const {data} = await postsService.browsePosts({collection: collectionSlug, limit: postCount, transacting});
let posts = data.map(p => p.toJSON());
return posts;
};
const options = Object.assign({
siteUrl: config.get('url'),
imageOptimization: config.get('imageOptimization'),
@ -43,7 +52,8 @@ module.exports = {
createDocument() {
const {JSDOM} = require('jsdom');
return (new JSDOM()).window.document;
}
},
getCollectionPosts
}, userOptions);
return await this.lexicalHtmlRenderer.render(lexical, options);
@ -94,4 +104,4 @@ module.exports = {
});
}
}
};
};