Skip to content

Commit 97973d8

Browse files
committed
feat: Allow generating page titles from file names without directory
1 parent fdc8fae commit 97973d8

File tree

5 files changed

+1125
-5
lines changed

5 files changed

+1125
-5
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,20 @@ You can use the reporter programmatically to process accessibility results as an
2424
const report = require('grunt-html-html-reporter')
2525
const input = fs.readFileSync('report.json', 'utf-8')
2626
const results = JSON.parse(input)
27-
const output = report(results)
27+
const output = report(results, {
28+
showFileNameOnly: false
29+
})
2830
fs.writeFileSync('report.html', output, 'utf-8')
2931
```
3032

33+
### Options
34+
35+
#### showFileNameOnly
36+
Type: `Boolean`
37+
Default value: `false`
38+
39+
Cuts the directory from tested HTML files, when creating page titles from in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp `true`.
40+
3141
## Usage with grunt-html
3242

3343
The value of the [`reporter`] property of the [`htmllint`] task has to be a path to this module, relative to the `Gruntfile.js`, in which the task is used:
@@ -51,6 +61,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
5161

5262
## Release History
5363

64+
* 2018-03-05 v2.2.0 Allow generating page titles from file names without directory
5465
* 2018-03-04 v2.1.0 Add filtering and accessibility to the reports
5566
* 2018-03-01 v2.0.0 Change the HTML format to look like Koa11y reports
5667
* 2018-03-01 v1.0.0 Release a stable version using a simple HTML format

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ function formatFile (file) {
5454
return content
5555
}
5656

57-
module.exports = function (results) {
57+
module.exports = function (results, options) {
58+
const showFileNameOnly = options && options.showFileNameOnly
5859
const files = {}
5960
var errorCount = 0
6061
var warningCount = 0
@@ -64,10 +65,16 @@ module.exports = function (results) {
6465
const name = path.normalize(result.file)
6566
const severity = result.type
6667
var file = files[name]
67-
var issues
68+
var fileName, issues
6869
if (!file) {
70+
if (showFileNameOnly) {
71+
fileName = path.parse(name)
72+
fileName = fileName.name + fileName.ext
73+
} else {
74+
fileName = name
75+
}
6976
file = files[name] = {
70-
name: name,
77+
name: fileName,
7178
errors: [],
7279
warnings: [],
7380
notices: []
File renamed without changes.

0 commit comments

Comments
 (0)