0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added {{comments}} helper

refs https://github.com/TryGhost/Team/issues/1664

- added `comments:url` config for a similar setup to Portal
- added `{{comments}}` helper that's behind the `comments` labs flag
  - currently outputs a `<script>` tag that points to the comments script with API location+key data attributes
This commit is contained in:
Kevin Ansfield 2022-07-04 15:33:40 +02:00
parent da3d32e2ed
commit dc49871837
2 changed files with 47 additions and 0 deletions

View file

@ -0,0 +1,44 @@
const {SafeString} = require('../services/handlebars');
const {config, urlUtils, getFrontendKey, labs} = require('../services/proxy');
async function comments() {
const commentId = this.comment_id;
if (!commentId) {
return;
}
const frontendKey = await getFrontendKey();
const data = {
ghost: urlUtils.getSiteUrl(),
api: urlUtils.urlFor('api', {type: 'content'}, true),
key: frontendKey,
'comment-id': commentId
};
let dataAttributes = '';
Object.entries(data).forEach(([key, value]) => {
dataAttributes += `data-${key}="${value}" `;
});
return new SafeString(`
<script defer src="${config.get('comments:url')}" ${dataAttributes} crossorigin="anonymous"></script>
`);
}
module.exports = async function commentsLabsWrapper() {
const self = this;
const args = arguments;
return labs.enabledHelper({
flagKey: 'comments',
flagName: 'Comments',
helperName: 'comments'
}, () => {
return comments.apply(self, args);
});
};
module.exports.async = true;

View file

@ -143,5 +143,8 @@
},
"gravatar": {
"url": "https://www.gravatar.com/avatar/{hash}?s={size}&r={rating}&d={_default}"
},
"comments": {
"url": "https://unpkg.com/@tryghost/comments@~0.0.0/umd/portal.min.js"
}
}