<commit_before>const {SafeString} = require('../services/handlebars');
const {config, urlUtils, getFrontendKey, labs} = require('../services/proxy');

async function comments(options) {
    // todo: For now check on the comment id to exclude normal pages (we probably have a better way to do this)

    const commentId = this.comment_id;
        
    if (!commentId) {
        return;
    }
    
    let colorScheme = 'auto';
    if (options.hash.color_scheme === 'dark' || options.hash.color_scheme === 'light') {
        colorScheme = options.hash.color_scheme;
    }

    const frontendKey = await getFrontendKey();

    const data = {
        'ghost-comments': urlUtils.getSiteUrl(),
        api: urlUtils.urlFor('api', {type: 'content'}, true),
        admin: urlUtils.urlFor('admin', true),
        key: frontendKey,
        'post-id': this.id,
        'sentry-dsn': '', /* todo: insert sentry dsn key here */
        'color-scheme': colorScheme
    };

    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;<commit_msg>Added avatar saturation parameter to comments helper<commit_after>const {SafeString} = require('../services/handlebars');
const {config, urlUtils, getFrontendKey, labs} = require('../services/proxy');

async function comments(options) {
    // todo: For now check on the comment id to exclude normal pages (we probably have a better way to do this)

    const commentId = this.comment_id;
        
    if (!commentId) {
        return;
    }
    
    let colorScheme = 'auto';
    if (options.hash.color_scheme === 'dark' || options.hash.color_scheme === 'light') {
        colorScheme = options.hash.color_scheme;
    }

    let avatarSaturation = parseInt(options.hash.avatar_saturation);
    if (isNaN(avatarSaturation)) {
        avatarSaturation = 50;
    }

    const frontendKey = await getFrontendKey();

    const data = {
        'ghost-comments': urlUtils.getSiteUrl(),
        api: urlUtils.urlFor('api', {type: 'content'}, true),
        admin: urlUtils.urlFor('admin', true),
        key: frontendKey,
        'post-id': this.id,
        'sentry-dsn': '', /* todo: insert sentry dsn key here */
        'color-scheme': colorScheme,
        'avatar-saturation': avatarSaturation
    };

    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;
{'fraction_non_alphanumeric': 0.1490046838407494, 'fraction_numerical': 0.000585480093676815, 'mean_word_length': 2.8653846153846154, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3725112', 'n_tokens_mistral': 1019, 'n_tokens_neox': 985, 'n_words': 244}