index.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 8

Size

Lines of Code 112
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 91
mnd 7
bc 7
fnc 1
dl 0
loc 112
rs 10
bpm 7
cpm 8
noi 4
c 0
b 0
f 0
1
// Copyright © 2016 TangDongxin
2
3
// Permission is hereby granted, free of charge, to any person obtaining
4
// a copy of this software and associated documentation files (the "Software"),
5
// to deal in the Software without restriction, including without limitation
6
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
// and/or sell copies of the Software, and to permit persons to whom the
8
// Software is furnished to do so, subject to the following conditions:
9
10
// The above copyright notice and this permission notice shall be included
11
// in all copies or substantial portions of the Software.
12
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21
"use strict";
22
23
var fs = require("hexo-fs");
24
var pathFn = require("path");
25
var Hexo = require("hexo");
26
var log = require("hexo-log")({
27
  debug: false,
28
  silent: false
29
});
30
31
hexo.extend.filter.register("after_generate", function(post) {
0 ignored issues
show
Unused Code introduced by
The parameter post is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Bug introduced by
The variable hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
32
  var libPath = pathFn.join(
33
    pathFn.join(pathFn.join(hexo.base_dir, "node_modules"), "hexo-tag-cloud"),
0 ignored issues
show
Bug introduced by
The variable hexo seems to be never declared. If this is a global, consider adding a /** global: hexo */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
34
    "lib"
35
  );
36
37
  var tagcanvasPubPath = pathFn.join(
38
    pathFn.join(hexo.public_dir, "js"),
39
    "tagcanvas.js"
40
  );
41
  var tagcloudPubPath = pathFn.join(
42
    pathFn.join(hexo.public_dir, "js"),
43
    "tagcloud.js"
44
  );
45
46
  log.info("---- START COPYING TAG CLOUD FILES ----");
47
  fs.copyFile(pathFn.join(libPath, "tagcanvas.js"), tagcanvasPubPath);
48
49
  var textFont = "Helvetica";
50
  var textColor = "#333";
51
  var textHeight = "15";
52
  var outlineColor = "#E2E1C1";
53
  var maxSpeed = "0.03";
54
  var pauseOnSelected = true;
55
56
  if (hexo.config.tag_cloud) {
57
    if (hexo.config.tag_cloud.textColor) {
58
      textColor = hexo.config.tag_cloud.textColor;
59
    }
60
    if (hexo.config.tag_cloud.textFont) {
61
      textFont = hexo.config.tag_cloud.textFont;
62
    }
63
    if (hexo.config.tag_cloud.textHeight) {
64
      textHeight = hexo.config.tag_cloud.textHeight;
65
    }
66
    if (hexo.config.tag_cloud.outlineColor) {
67
      outlineColor = hexo.config.tag_cloud.outlineColor;
68
    }
69
    if (hexo.config.tag_cloud.maxSpeed) {
70
      maxSpeed = hexo.config.tag_cloud.maxSpeed;
71
    }
72
    if (hexo.config.tag_cloud.pauseOnSelected != undefined) {
0 ignored issues
show
Best Practice introduced by
Comparing hexo.config.tag_cloud.pauseOnSelected to undefined using the != operator is not safe. Consider using !== instead.
Loading history...
73
      pauseOnSelected = hexo.config.tag_cloud.pauseOnSelected;
74
    }
75
  }
76
77
  var tagCloudJsContent =
78
    " function addLoadEvent(func) {\n" +
79
    "     var oldonload = window.onload;\n" +
80
    "     if (typeof window.onload != 'function') {\n" +
81
    "         window.onload = func;\n" +
82
    "     } else {\n" +
83
    "         window.onload = function() {\n" +
84
    "             oldonload();\n" +
85
    "             func();\n" +
86
    "         }\n" +
87
    "     }\n" +
88
    " }\n" +
89
    "\n" +
90
    " addLoadEvent(function() {\n" +
91
    "     console.log('tag cloud plugin rock and roll!');\n" +
92
    "\n" +
93
    "     try {\n" +
94
    "         TagCanvas.textFont = '${textFont}';\n" +
95
    "         TagCanvas.textColour = '${textColor}';\n" +
96
    "         TagCanvas.textHeight = ${textHeight};\n" +
97
    "         TagCanvas.outlineColour = '${outlineColor}';\n" +
98
    "         TagCanvas.maxSpeed = ${maxSpeed};\n" +
99
    "         TagCanvas.freezeActive = ${pauseOnSelected};\n" +
100
    "         TagCanvas.outlineMethod = 'block';\n" +
101
    "         TagCanvas.minBrightness = 0.2;\n" +
102
    "         TagCanvas.depth = 0.92;\n" +
103
    "         TagCanvas.pulsateTo = 0.6;\n" +
104
    "         TagCanvas.initial = [0.1,-0.1];\n" +
105
    "         TagCanvas.decel = 0.98;\n" +
106
    "         TagCanvas.reverse = true;\n" +
107
    "         TagCanvas.hideTags = false;\n" +
108
    "         TagCanvas.shadow = '#ccf';\n" +
109
    "         TagCanvas.shadowBlur = 3;\n" +
110
    "         TagCanvas.weight = false;\n" +
111
    "         TagCanvas.imageScale = null;\n" +
112
    "         TagCanvas.fadeIn = 1000;\n" +
113
    "         TagCanvas.clickToFront = 600;\n" +
114
    "         TagCanvas.lock = false;\n" +
115
    "         TagCanvas.Start('resCanvas');\n" +
116
    "         TagCanvas.tc['resCanvas'].Wheel(true)\n" +
117
    "     } catch(e) {\n" +
118
    "         console.log(e);\n" +
119
    "         document.getElementById('myCanvasContainer').style.display = 'none';\n" +
120
    "     }\n" +
121
    " });\n";
122
123
  tagCloudJsContent = tagCloudJsContent.replace("${textFont}", textFont);
124
  tagCloudJsContent = tagCloudJsContent.replace("${textColor}", textColor);
125
  tagCloudJsContent = tagCloudJsContent.replace("${textHeight}", textHeight);
126
  tagCloudJsContent = tagCloudJsContent.replace("${outlineColor}", outlineColor);
127
  tagCloudJsContent = tagCloudJsContent.replace("${maxSpeed}", maxSpeed);
128
  tagCloudJsContent = tagCloudJsContent.replace("${pauseOnSelected}", pauseOnSelected);
129
130
  fs.writeFile(tagcloudPubPath, tagCloudJsContent);
131
  log.info("---- END COPYING TAG CLOUD FILES ----");
132
});
133