-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 969 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* 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);