Skip to content

Commit 2e56b54

Browse files
committed
Updating custom tasks
Updating robots.txt Gruntfile typo
1 parent a89c6eb commit 2e56b54

File tree

9 files changed

+176
-176
lines changed

9 files changed

+176
-176
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
node_modules
22
build
33
tmp
4-
.idea

Gruntfile.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ module.exports = function(grunt) {
66
grunt.initConfig({
77
// server port, used to serve the site and run tests
88
server_port: 5678,
9+
// wiki url
10+
wiki_url: 'https://github.com/gruntjs/grunt.wiki.git',
11+
// wiki file check, file that exists in the wiki for sure
12+
wiki_file: 'grunt.md',
913

1014
// clean directories
1115
clean: {
1216
build: ['build/'],
1317
tmp: ['tmp/']
1418
},
15-
jshint: {
16-
all: ['Gruntfile.js']
17-
},
1819
// compile less -> css
1920
less: {
2021
development: {
@@ -35,7 +36,7 @@ module.exports = function(grunt) {
3536
}
3637
}
3738
},
38-
// watch
39+
3940
watch: {
4041
less: {
4142
files: 'src/less/*.less',
@@ -54,6 +55,7 @@ module.exports = function(grunt) {
5455
tasks: ['default']
5556
}
5657
},
58+
5759
// compile page layouts
5860
jade: {
5961
notfound: {
@@ -82,6 +84,25 @@ module.exports = function(grunt) {
8284
}
8385
},
8486

87+
jshint: {
88+
all: ['Gruntfile.js', 'tasks/*.js'],
89+
options: {
90+
curly: true,
91+
eqeqeq: true,
92+
immed: true,
93+
latedef: true,
94+
newcap: true,
95+
noarg: true,
96+
sub: true,
97+
undef: true,
98+
unused: true,
99+
boss: true,
100+
eqnull: true,
101+
node: true,
102+
es5: true
103+
}
104+
},
105+
85106
// copy site source files
86107
copy: {
87108
assets: {
@@ -112,9 +133,8 @@ module.exports = function(grunt) {
112133
// Load local tasks
113134
grunt.loadTasks('tasks'); // getWiki, docs tasks
114135

115-
grunt.registerTask('build', ['clean', 'copy', 'jade', 'docs', 'plugins', 'concat']);
136+
grunt.registerTask('build', ['clean', 'copy', 'jade', 'docs', 'blog', 'plugins', 'concat']);
116137
grunt.registerTask('default', ['build', 'less:production']);
117138
grunt.registerTask('dev', ['build', 'less:development', 'jshint', 'watch']);
118139
grunt.registerTask('test', ['nodeunit']);
119-
120140
};

src/robots.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
User-agent: *
2-
Disallow: /

tasks/blog.js

+47-90
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
* Licensed under the MIT license.
77
*/
88

9-
var fs = require('fs'),
10-
jade = require('jade'),
11-
highlighter = require('highlight.js'),
12-
marked = require('marked');
13-
149
module.exports = function (grunt) {
1510
'use strict';
1611

12+
var jade = require('jade'),
13+
highlighter = require('highlight.js'),
14+
marked = require('marked'),
15+
blog = require('./lib/blog').init(grunt);
16+
1717
/**
18-
* Custom task to generate grunt documentation
18+
* Custom task to generate the grunt blog
1919
*/
2020
grunt.registerTask('blog', 'Compile Grunt Blog', function () {
21-
var done = this.async();
2221
grunt.log.ok('Generating blog...');
2322

2423
// Set default marked options
2524
marked.setOptions({
2625
gfm:true,
2726
anchors:true,
28-
base:"/",
27+
base:'/',
2928
pedantic:false,
3029
sanitize:true,
3130
// callback for code highlighter
@@ -40,18 +39,10 @@ module.exports = function (grunt) {
4039
base = 'tmp/wiki/',
4140
files = grunt.file.expand({cwd:base}, ['Blog-*.md']);
4241

43-
function formatBlogDate(postDate) {
44-
var postDate = postDate.split('-'),
45-
monthNames = [ "January", "February", "March", "April", "May", "June",
46-
"July", "August", "September", "October", "November", "December" ];
47-
return monthNames[parseInt(postDate[1], 10) - 1] + ' ' + postDate[2] + ', ' + postDate[0];
48-
}
49-
5042
names = files.map(function (name) {
5143
return name.substring(5, name.length - 3);
5244
}).reverse();
5345

54-
5546
// REVERSE the list, generate short article list
5647
files.reverse().forEach(function (file, i) {
5748
var name = names[i],
@@ -60,9 +51,9 @@ module.exports = function (grunt) {
6051
destName = name.toLowerCase();
6152

6253
articleList.push({
63-
url: destName,
64-
title:postTitle,
65-
postDate: formatBlogDate(postDate)
54+
url:destName,
55+
title:postTitle,
56+
postDate:blog.formatDate(postDate)
6657
});
6758
});
6859

@@ -77,26 +68,21 @@ module.exports = function (grunt) {
7768

7869
grunt.file.copy(src, dest, {
7970
process:function (src) {
80-
try {
81-
var file = 'src/tmpl/blog.jade',
82-
templateData = {
83-
page:'news',
84-
singlePost: true,
85-
url: destName,
86-
title:postTitle,
87-
postDate: formatBlogDate(postDate),
88-
postRawDate: postDate,
89-
articleList: articleList,
90-
content:marked(src),
91-
rawSrc: src
92-
};
93-
shortList.push(templateData);
94-
95-
return jade.compile(grunt.file.read(file), {filename:file})(templateData);
96-
} catch (e) {
97-
grunt.log.error(e);
98-
grunt.fail.warn('Jade failed to compile.');
99-
}
71+
var file = 'src/tmpl/blog.jade',
72+
templateData = {
73+
page:'news',
74+
singlePost:true,
75+
url:destName,
76+
title:postTitle,
77+
postDate:blog.formatDate(postDate),
78+
postRawDate:postDate,
79+
articleList:articleList,
80+
content:marked(src),
81+
rawSrc:src
82+
};
83+
shortList.push(templateData);
84+
85+
return jade.compile(grunt.file.read(file), {filename:file})(templateData);
10086
}
10187
});
10288
});
@@ -105,72 +91,43 @@ module.exports = function (grunt) {
10591
* Generate the blog page with a list of posts
10692
*/
10793
grunt.log.ok('Generating blog front page..');
108-
try {
109-
var src = 'src/tmpl/blog.jade',
110-
templateData = {
111-
page:'blog',
112-
title:"The Grunt Blog",
113-
content:shortList,
114-
articleList: articleList
115-
};
116-
grunt.file.write(
117-
'build/blog.html',
118-
jade.compile(grunt.file.read(src), {filename:src})(templateData));
119-
} catch (e) {
120-
grunt.log.error(e);
121-
grunt.fail.warn('Jade failed to compile.');
122-
}
123-
94+
var blogTpl = 'src/tmpl/blog.jade';
95+
var blogOut = jade.compile(grunt.file.read(blogTpl), {filename:blogTpl})({
96+
page:'blog',
97+
title:'The Grunt Blog',
98+
content:shortList,
99+
articleList:articleList
100+
});
101+
grunt.file.write('build/blog.html', blogOut);
124102

125103
/**
126104
* Generate the RSS feed
127105
*/
128106
grunt.log.ok('Generating rss feed...');
129-
130107
// remove anchors from RSS setting
131108
marked.setOptions({
132-
anchors: false
109+
anchors:false
133110
});
134111
// generate the feed items with different 'marked' settings
135-
shortList.forEach(function(item) {
112+
shortList.forEach(function (item) {
136113
item.rssSrc = marked(item.rawSrc);
137114
});
138-
139-
try {
140-
var src = 'src/tmpl/rss.jade',
141-
templateData = {
142-
page:'rss',
143-
posts: shortList
144-
};
145-
grunt.file.write(
146-
'build/atom.xml',
147-
jade.compile(grunt.file.read(src), {filename:src})(templateData));
148-
} catch (e) {
149-
grunt.log.error(e);
150-
grunt.fail.warn('Jade failed to compile.');
151-
}
152-
115+
var rssTpl = 'src/tmpl/rss.jade';
116+
var rssOut = jade.compile(grunt.file.read(rssTpl), {filename:rssTpl})({
117+
page:'rss',
118+
posts:shortList
119+
});
120+
grunt.file.write('build/atom.xml', rssOut);
153121

154122
/**
155123
* Generate the front page
156124
*/
157125
grunt.log.ok('Generating the front page...');
158-
try {
159-
var src = 'src/tmpl/index.jade',
160-
templateData = {
161-
page:'index',
162-
news: shortList.splice(0,5)
163-
};
164-
grunt.file.write(
165-
'build/index.html',
166-
jade.compile(grunt.file.read(src), {filename:src})(templateData));
167-
} catch (e) {
168-
grunt.log.error(e);
169-
grunt.fail.warn('Jade failed to compile.');
170-
}
171-
172-
173-
grunt.log.ok('Created ' + names.length + ' files.');
174-
done(true);
126+
var indexTpl = 'src/tmpl/index.jade';
127+
var indexOut = jade.compile(grunt.file.read(indexTpl), {filename:indexTpl})({
128+
page:'index',
129+
news:shortList.splice(0, 5)
130+
});
131+
grunt.file.write('build/index.html', indexOut);
175132
});
176133
};

0 commit comments

Comments
 (0)