2022-07-04 15:33:40 +02:00
|
|
|
const {SafeString} = require('../services/handlebars');
|
|
|
|
const {config, urlUtils, getFrontendKey, labs} = require('../services/proxy');
|
|
|
|
|
2022-07-07 11:10:01 +02:00
|
|
|
async function comments(options) {
|
2022-07-05 15:12:47 +02:00
|
|
|
// todo: For now check on the comment id to exclude normal pages (we probably have a better way to do this)
|
2022-07-04 15:33:40 +02:00
|
|
|
|
2022-07-07 11:10:01 +02:00
|
|
|
const commentId = this.comment_id;
|
|
|
|
|
2022-07-04 15:33:40 +02:00
|
|
|
if (!commentId) {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-07 11:10:01 +02:00
|
|
|
|
|
|
|
let colorScheme = 'auto';
|
|
|
|
if (options.hash.color_scheme === 'dark' || options.hash.color_scheme === 'light') {
|
|
|
|
colorScheme = options.hash.color_scheme;
|
|
|
|
}
|
2022-07-04 15:33:40 +02:00
|
|
|
|
|
|
|
const frontendKey = await getFrontendKey();
|
|
|
|
|
|
|
|
const data = {
|
2022-07-04 16:12:35 +02:00
|
|
|
'ghost-comments': urlUtils.getSiteUrl(),
|
2022-07-04 15:33:40 +02:00
|
|
|
api: urlUtils.urlFor('api', {type: 'content'}, true),
|
2022-07-05 15:30:00 +02:00
|
|
|
admin: urlUtils.urlFor('admin', true),
|
2022-07-04 15:33:40 +02:00
|
|
|
key: frontendKey,
|
2022-07-05 15:12:47 +02:00
|
|
|
'post-id': this.id,
|
2022-07-07 11:10:01 +02:00
|
|
|
'sentry-dsn': '', /* todo: insert sentry dsn key here */
|
|
|
|
'color-scheme': colorScheme
|
2022-07-04 15:33:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|