forked from hankmander/webplatformdaily-site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
171 lines (158 loc) · 3.68 KB
/
Gruntfile.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
module.exports = function (grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
// File concatenations
concat: {
// Adds the reset style sheet to the front of my main CSS file
css: {
files: {
'styles/daily.css': [
'styles/reset/cssreset-min.css',
'styles/daily.css'
]
}
},
// Merges the components into the main MD file
md: {
files: {
'content/generated/main.md': [
'content/main/head.md',
'content/generated/latest.temp.md'
]
}
}
},
// File deletions
clean: {
temp: ['content/generated/*.temp.md']
},
// Generating the CSS file(s)
sass: {
main: {
options: {
style: 'compressed'
},
files: {
'styles/daily.css': 'styles/daily.sass'
}
}
},
csslint: {
strict: {
// I've disabled this for now; it generates lots of errors by default
// src: ['styles/daily.css']
}
},
// Generating the JavaScript file(s)
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
unused: true,
boss: true,
eqnull: true,
browser: true,
globals: {
jQuery: true,
Markdown: true
}
},
files: 'js/daily.js'
},
uglify: {
options: {
banner: '<%= banner %>'
},
main: {
files: {
'js/daily.min.js': ['js/daily.js']
}
}
},
// Generating the RSS feed XML file
markdown: {
rss: {
files: {
'feed/rss.xml': ['content/generated/latest.temp.md']
},
options: {
template: 'templates/rss_template.xml',
templateContext: {
time: (new Date).toUTCString()
},
preCompile: function (src) {
return src
.replace(/\[@(\\?)(\w+)\]\(\)/g, '[@$1$2](http://twitter.com/$2)')
.replace(/\/img\//g, 'http://webplatformdaily.org/img/');
},
postCompile: function (src) {
var template = grunt.file.read('templates/rss_item_template.xml');
return src.split('<h2>').slice(1).map(function (val) {
var title = val.match(/(.+)<\/h2>/)[1],
id = 'http://webplatformdaily.org/#' + escape(title.replace(/[ ,]/g, ''));
return grunt.template.process(template, {
data: {
title: title,
id: id,
val: val
}
});
}).join('');
},
markdownOptions: {
gfm: true
}
}
}
},
// Local server with live-reload
connect: {
server: {
options: {
port: 9001,
// hostname: '0.0.0.0' // set this when testing on onother device
}
}
},
watch: {
options: {
livereload: true
},
css: {
files: ['styles/*.sass'],
tasks: ['css']
},
js: {
files: ['js/daily.js'],
tasks: ['js']
},
md: {
files: ['content/dailies/*.md', 'content/main/*.md'],
tasks: ['md']
},
files: ['*.html']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-csslint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-markdown');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.registerTask('css', ['sass', 'csslint', 'concat:css']);
grunt.registerTask('js', ['jshint', 'uglify']);
grunt.registerTask('md', ['merge', 'concat:md', 'clean:temp']);
grunt.registerTask('daily', ['merge', 'validate', 'concat:md', 'markdown:rss', 'clean:temp']);
grunt.registerTask('server', ['connect', 'watch']);
grunt.loadTasks('tasks');
};