Skip to content

Commit 5b1ffdc

Browse files
tsriramgr2m
authored andcommitted
test for insensitive wording using alex.js (hoodiehq#333)
1 parent 2a93489 commit 5b1ffdc

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ The new hood.ie Website doesn't need to be deployed after making changes. (Only
134134
- run `bundle exec jekyll serve --watch --drafts` in your terminal and wait until it says `server running`
135135
- go to `localhost:4000/blog`. All currently available drafts are then just displayed as regular Blog posts. You can now check your draft and edit it in your editor. (Note: Jekyll is sometimes a bit slow, so this may take a little bit.)
136136

137+
### Checking for insensitive content in the post
138+
* [Alex.js](http://alexjs.com/) is used to check for any insensitve content
139+
* When you want to check if the draft contains any insensitive content,
140+
- run `npm run alex -- -f _posts/<your-post-filename>.md`
141+
- look into reported issues and try to resolve them where it makes sense
142+
- you can also do `npm run alex -- -d _drafts` to check for insensitive content in all posts inside _drafts folder
143+
137144
### Publishing the drafted Blog post
138145

139146
From the command line –

bin/language-checker.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Utility to run files through Alex.js (http://alexjs.com/)
2+
// run using `npm run alex`
3+
var fs = require('fs')
4+
var path = require('path')
5+
var toVFile = require('to-vfile')
6+
var argv = require('argv')
7+
var alex = require('alex')
8+
var colors = require('colors/safe')
9+
10+
colors.setTheme({
11+
info: 'green',
12+
warn: 'yellow',
13+
error: 'red'
14+
})
15+
16+
var options = [
17+
{
18+
name: 'dir',
19+
short: 'd',
20+
type: 'path',
21+
description: 'directory to run through Alex.js',
22+
example: 'npm run alex -- -d _posts'
23+
},
24+
{
25+
name: 'file',
26+
short: 'f',
27+
type: 'path',
28+
description: 'file to run through Alex.js',
29+
example: 'npm run alex -- -f _posts/2013-06-08-hacker-news-thread-about-hoodie.md'
30+
}
31+
]
32+
33+
var args = argv.option(options).run()
34+
35+
if (args.options.dir) {
36+
scanDir(args.options.dir)
37+
}
38+
39+
if (args.options.file) {
40+
scanFile(args.options.file)
41+
}
42+
43+
function scanFile (file) {
44+
try {
45+
var vfile = toVFile.readSync(file)
46+
var messages = alex.markdown(vfile).messages
47+
if (messages.length) {
48+
console.log(colors.warn(messages))
49+
} else {
50+
console.log(colors.info('alex.js says ' + file + ' looks good!'))
51+
}
52+
} catch (error) {
53+
console.error(colors.error('Error in reading file ' + file + ' - ' + error.message))
54+
}
55+
}
56+
57+
function scanDir (dir) {
58+
try {
59+
var files = fs.readdirSync(dir)
60+
files.forEach(function (file) {
61+
scanFile(dir + path.sep + file)
62+
})
63+
} catch (error) {
64+
console.log(colors.error('Error in reading directory ' + dir + ' - ' + error.message))
65+
}
66+
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
"version": "0.1.0",
44
"scripts": {
55
"start": "grunt",
6-
"build": "grunt build"
6+
"build": "grunt build",
7+
"alex": "node ./bin/language-checker.js"
78
},
89
"devDependencies": {
10+
"alex": "^4.0.1",
11+
"argv": "0.0.2",
12+
"colors": "^1.1.2",
913
"grunt": "^0.4.5",
1014
"grunt-autoprefixer": "^1.0.1",
1115
"grunt-cli": "^0.1.13",
@@ -16,7 +20,8 @@
1620
"grunt-contrib-watch": "^0.6.1",
1721
"grunt-sass": "^1.0.0",
1822
"grunt-string-replace": "^1.0.0",
19-
"time-grunt": "^1.0.0"
23+
"time-grunt": "^1.0.0",
24+
"to-vfile": "^2.1.1"
2025
},
2126
"frontend": {
2227
"name": "Hood.ie Sass/JS",

0 commit comments

Comments
 (0)