{"size": 969, "ext": "js", "max_stars_repo_path": "index.js", "max_stars_repo_name": "maaaaarco/hexo-plausible-analytics", "max_stars_repo_stars_event_min_datetime": "2021-05-04T06:33:00.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-15T15:35:09.000Z", "max_issues_repo_path": "index.js", "max_issues_repo_name": "maaaaarco/hexo-plausible-analytics", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "index.js", "max_forks_repo_name": "maaaaarco/hexo-plausible-analytics", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.0714285714, "max_line_length": 98, "alphanum_fraction": 0.653250774}
/*
 * Copyright (c) 2021 Marco
 * Licensed under MIT license.
 * For full license text, see LICENSE file in the repo root or https://opensource.org/licenses/MIT
 * If you would like to contribute https://github.com/maaaaarco/hexo-plausible-analytics
 */

/* global hexo */
const injector = require('./lib/plausible');

function run(config) {
  if (!config) {
    // plugin is not configured
    return;
  }

  const { enable, pages, domain } = config;

  if (!enable) {
    return;
  }

  if (!domain) {
    console.log('ERROR  hexo-plausible-analytics: _domain_ cannot be blank');
    return;
  }

  if (Array.isArray(pages)) {
    // registers injector only on specified pages
    pages.forEach((page) => {
      hexo.extend.injector.register('head_end', injector(hexo), page);
    });
  }

  if (!pages || pages === 'default') {
    // registers injector on all pages
    hexo.extend.injector.register('head_end', injector(hexo));
  }
}

run(hexo.config.plausible);
