forked from oierbravo/necrorol-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
141 lines (116 loc) · 3.95 KB
/
gulpfile.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
var path = require('path');
var gulp = require('gulp');
var remoteSrc = require('gulp-remote-src');
var concat = require('gulp-concat');
var package = require('./package.json');
const nunjucks = require('gulp-nunjucks');
const nunjucksMarkdown = require('nunjucks-markdown');
const markdownIt = require('markdown-it');
const gap = require('gulp-append-prepend');
//var markdownPdf = require("markdown-pdf");
const markdownPdf = require('gulp-markdown-pdf');
var pdf = require('gulp-html-pdf');
var html2pdf = require('gulp-html2pdf');
var listaMds = require('./lista-mds.js');
var listaMdsNames = require('./lista-mds.names.js');
var rename = require("gulp-rename");
var fileinclude = require('gulp-file-include')
var remark = require('gulp-remark')
var htmlRemark = require('remark-html')
const sectionize = require('remark-sectionize')
var normalizeHeadings = require('remark-normalize-headings')
var remark2rehype = require('remark-rehype')
var doc = require('rehype-document')
var format = require('rehype-format')
var html = require('rehype-stringify')
var markdown = require('remark-parse')
var slug = require('remark-slug')
const rehypeInline = require("rehype-inline");
var inlineCss = require('gulp-inline-css');
var section = require('@agentofuser/rehype-section').default
var cheerio = require('gulp-cheerio');
var config = {
destination: './dist',
mdFullFilename: 'necrorol-full.md',
pdfFullFilename: 'necrorol-full.pdf'
}
function configMarkdown(env) {
const renderer = markdownIt().render.bind(markdownIt());
nunjucksMarkdown.register(env, renderer);
}
gulp.task('remote-md-full', function() {
return remoteSrc(listaMds, {
base: null
})
.pipe(concat(config.mdFullFilename))
.pipe(gulp.dest(config.destination));
})
gulp.task('remote-md-items', function(cb) {
for (index in listaMdsNames){
console.log(listaMdsNames[index].name);
remoteSrc(listaMdsNames[index].url, {
base: null
})
.pipe(rename({
dirname: "items",
basename: listaMdsNames[index].name,
prefix: index + '-',
extname: ".md"
}))
.pipe(gulp.dest(config.destination));
};
cb() ;
});
gulp.task('remote-remark', function() {
return remoteSrc(listaMds, {
base: null
})
.pipe(
remark()
.use(normalizeHeadings)
.use(sectionize)
.use(slug)
.use(htmlRemark))
.pipe(gap.appendText('<div style="page-break-after: always;"></div>'))
.pipe(cheerio(function ($, file) {
var h1Id = $('h1').attr('id');
$('h1').parent().addClass('container h1');
$('section h2').each(function () {
var section = $(this);
var h2Id = $(this).attr('id');
section.parent().addClass('h2 part part-' + h2Id);
});
}))
.pipe(concat('remark.html'))
.pipe(gulp.dest(config.destination));
})
gulp.task('remote-remark-inject', function() {
return gulp.src(['templates/necrorol.html'])
.pipe(fileinclude({
prefix: '@@',
basepath: '@file'
}))
.pipe(rename({
basename: "necrorol.v" + package.version
}))
.pipe(gulp.dest(config.destination));
})
gulp.task('remote-remark-pdf', function() {
return gulp.src('./dist/necrorol.v' + package.version + '.html')
.pipe(pdf({ format: "A4", orientation: "portrait"}))
.pipe(rename({
basename: "necrorol.v" + package.version
}))
.pipe(gulp.dest(config.destination));
})
gulp.task('css',function(){
return gulp.src(['./node_modules/gutenberg-css/dist/gutenberg.css','templates/styles.css','./node_modules/bootstrap/dist/css/bootstrap.css'])
.pipe(gulp.dest(config.destination));
})
gulp.task('index',function(){
return gulp.src('templates/index.html')
.pipe(nunjucks.compile({version: package.version}))
.pipe(gulp.dest(config.destination));
});
gulp.task('remark', gulp.series(['remote-remark','remote-remark-inject','remote-remark-pdf']));
gulp.task('build', gulp.series(['css','remark','index']));