-
Notifications
You must be signed in to change notification settings - Fork 0
/
nico.js
70 lines (61 loc) · 1.63 KB
/
nico.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var path = require('path');
var cheerio = require('cheerio');
var hl = require('highlight.js');
var highlightAuto = hl.highlightAuto;
var open = require('open');
var type = process.env.NODE_ENV;
var package = require("./package.json");
var version = package.version;
//nico setting
exports.site = {
name: 'The Guide of Enterprise Front-end Solution'
};
exports.theme = 'themes';
exports.source = path.join(process.cwd(), 'doc');
var folderName = 'dist';
if (type === 'tag') {
folderName = version;
}
console.log('type = ', type);
exports.output = path.join(process.cwd(), folderName);
exports.permalink = '{{directory}}/{{filename}}';
exports.ignorefilter = function(filepath, subdir) {
var extname = path.extname(filepath);
if (extname === '.tmp' || extname === '.bak') {
return false;
}
if (/\.DS_Store/.test(filepath)) {
return false;
}
if (/^(dist|_theme|node_modules|\.idea|static-src)/.test(subdir)) {
return false;
}
return true;
};
exports.process_write = function(content, filename) {
if (/\.html$/.test(filename)) {
var $ = cheerio.load(content);
$('pre code').replaceWith(function(i, block) {
var $e = $(block);
var text = $e.text();
var klass = $e.attr('class') || '';
var languageType = klass.split('lang-').filter(id);
if (languageType.length) {
return highlightAuto(text, languageType).value;
} else {
return highlightAuto(text).value;
}
$('pre').addClass('hljs');
});
return $.html();
}
return content;
}
function id(type) {
return type;
}
exports.writers = [
"nico.PostWriter",
"nico.FileWriter",
"nico.StaticWriter"
];