--- regenerate: true --- {%- capture cache -%} {% comment %} # ----------------------------------------------------------------------------- # ~/assets/theme/j1/adapter/js/comments.js # Liquid template to adapt the Comments module # # Product/Info: # https://jekyll.one # Copyright (C) 2023, 2024 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE # ----------------------------------------------------------------------------- # Test data: # {{ liquid_var | debug }} # comments_options: {{ comments_options | debug }} # ----------------------------------------------------------------------------- {% endcomment %} {% comment %} Liquid procedures -------------------------------------------------------------------------------- {% endcomment %} {% comment %} Set global settings -------------------------------------------------------------------------------- {% endcomment %} {% assign environment = site.environment %} {% assign asset_path = "/assets/theme/j1" %} {% comment %} Process YML config data ================================================================================ {% endcomment %} {% comment %} Set config files -------------------------------------------------------------------------------- {% endcomment %} {% assign template_config = site.data.j1_config %} {% assign blocks = site.data.blocks %} {% assign modules = site.data.modules %} {% comment %} Set config data (settings only) -------------------------------------------------------------------------------- {% endcomment %} {% assign comments_defaults = modules.defaults.comments.defaults %} {% assign comments_settings = modules.comments.settings %} {% comment %} Set config options (settings only) -------------------------------------------------------------------------------- {% endcomment %} {% assign comments_options = comments_defaults | merge: comments_settings %} {% comment %} Variables -------------------------------------------------------------------------------- {% endcomment %} {% assign comments = comments_options.enabled %} {% assign comments_provider = comments_options.provider %} {% if comments_provider == 'disqus' %} {% assign site_id = comments_options.disqus.site_id %} {% elsif comments_provider == 'hyvor' %} {% assign site_id = comments_options.hyvor.site_id %} {% elsif comments_provider == 'commento' %} {% assign site_id = comments_options.commento.site_id %} {% elsif comments_provider == 'just-comments' %} {% assign site_id = comments_options.just-comments.site_id %} {% elsif comments_provider == 'facebook' %} {% assign site_id = comments_options.facebook.site_id %} {% else %} {% assign site_id = false %} {% endif %} {% comment %} language detection -------------------------------------------------------------------------------- {% endcomment %} {% if site.language == "en" %} {% assign language = "en" %} {% elsif site.language == "de"%} {% assign language = "de" %} {% else %} {% assign language = "en" %} {% endif %} {% if language == "en" %} {% assign comments_headline = comments_options.comments_headline.en %} {% endif %} {% if language == "de" %} {% assign comments_headline = comments_options.comments_headline.de %} {% endif %} {% comment %} Detect prod mode -------------------------------------------------------------------------------- {% endcomment %} {% assign production = false %} {% if environment == 'prod' or environment == 'production' %} {% assign production = true %} {% endif %} /* # ----------------------------------------------------------------------------- # ~/assets/theme/j1/adapter/js/comments.js # J1 Adapter for the comments module # # Product/Info: # https://jekyll.one # # Copyright (C) 2023, 2024 Juergen Adams # # J1 Template is licensed under the MIT License. # For details, see: https://github.com/jekyll-one-org/j1-template/blob/main/LICENSE # ----------------------------------------------------------------------------- # Adapter generated: {{site.time}} # ----------------------------------------------------------------------------- */ // ----------------------------------------------------------------------------- // ESLint shimming // ----------------------------------------------------------------------------- /* eslint indent: "off" */ // ----------------------------------------------------------------------------- "use strict"; j1.adapter.comments = ((j1, window) => { {% comment %} Set global variables ------------------------------------------------------------------------------ {% endcomment %} var environment = '{{environment}}'; var date = new Date(); var timestamp_now = date.toISOString(); var cookie_names = j1.getCookieNames(); var comments_provider = '{{comments_provider}}'; var dqApiScript = document.createElement('script'); var hvApiScript = document.createElement('script'); var hvCallbackScript = document.createElement('script'); var comments_headline = '{{comments_headline}}'; var state = 'not_started'; var providerID; var validProviderID; var commentsDefaults; var commentsSettings; var commentsOptions; var frontmatterOptions; var user_consent; var _this; var logger; var logText; // date|time var startTime; var endTime; var startTimeModule; var endTimeModule; var timeSeconds; // --------------------------------------------------------------------------- // main // --------------------------------------------------------------------------- return { // ------------------------------------------------------------------------- // adapter initializer // ------------------------------------------------------------------------- init: (options) => { // ----------------------------------------------------------------------- // global variable settings // ----------------------------------------------------------------------- // create settings object from frontmatter (page settings) frontmatterOptions = options != null ? $.extend({}, options) : {}; // Load module DEFAULTS|CONFIG commentsDefaults = $.extend({}, {{comments_defaults | replace: 'nil', 'null' | replace: '=>', ':' }}); commentsSettings = $.extend({}, {{comments_settings | replace: 'nil', 'null' | replace: '=>', ':' }}); commentsOptions = $.extend(true, {}, commentsDefaults, commentsSettings, frontmatterOptions); // overload module config from page settings (frontmatter) if (typeof commentsOptions.comments !== 'undefined' ) { commentsOptions.enabled = (commentsOptions.comments) === 'true' ? true : false; } if (commentsOptions.enabled) { // [INFO ] [j1.adapter.comments ] [ detected comments provider (j1_config): {{comments_provider}}} ] // [INFO ] [j1.adapter.comments ] [ start processing load region head, layout: {{page.layout}} ] // --------------------------------------------------------------------- // default module settings // --------------------------------------------------------------------- var settings = $.extend({ module_name: 'j1.adapter.comments', generated: '{{site.time}}' }, options); _this = j1.adapter.comments; logger = log4javascript.getLogger('j1.adapter.comments'); // check the site ID to be used for a provider providerID = (typeof commentsOptions.site_id == "number") ? commentsOptions.site_id.toString() : commentsOptions.site_id; validProviderID = (providerID.includes('your')) ? false : true; // --------------------------------------------------------------------- // module initializer // --------------------------------------------------------------------- {% case comments_provider %} {% when "hyvor" %} // [INFO ] [j1.adapter.comments ] [ place provider: Hyvor Talk ] var dependencies_met_page_ready = setInterval(() => { var j1CoreFinished = (j1.getState() === 'finished') ? true : false; if (j1CoreFinished) { startTimeModule = Date.now(); _this.setState('started'); logger.debug('\n' + 'state: ' + _this.getState()); logger.info('\n' + 'module is being initialized'); if (!validProviderID) { logger.debug('\n' + 'invalid site id detected for Hyvor Talk: ' + providerID); logger.info('\n' + 'skip initialization for provider: ' + comments_provider); clearInterval(dependencies_met_page_ready); return false; } // place|remove initialization code // ----------------------------------------------------------------- user_consent = j1.readCookie(cookie_names.user_consent); if (user_consent.personalization) { // enable Hyvor Talk // --------------------------------------------------------------- $('#main-content').append('