Skip to content

Commit

Permalink
feat: Allow generating page titles from file names without directory
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Mar 4, 2018
1 parent fdc8fae commit 97973d8
Show file tree
Hide file tree
Showing 5 changed files with 1,125 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@ You can use the reporter programmatically to process accessibility results as an
const report = require('grunt-html-html-reporter')
const input = fs.readFileSync('report.json', 'utf-8')
const results = JSON.parse(input)
const output = report(results)
const output = report(results, {
showFileNameOnly: false
})
fs.writeFileSync('report.html', output, 'utf-8')
```

### Options

#### showFileNameOnly
Type: `Boolean`
Default value: `false`

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`.

## Usage with grunt-html

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:
Expand All @@ -51,6 +61,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

* 2018-03-05 v2.2.0 Allow generating page titles from file names without directory
* 2018-03-04 v2.1.0 Add filtering and accessibility to the reports
* 2018-03-01 v2.0.0 Change the HTML format to look like Koa11y reports
* 2018-03-01 v1.0.0 Release a stable version using a simple HTML format
Expand Down
13 changes: 10 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function formatFile (file) {
return content
}

module.exports = function (results) {
module.exports = function (results, options) {
const showFileNameOnly = options && options.showFileNameOnly
const files = {}
var errorCount = 0
var warningCount = 0
Expand All @@ -64,10 +65,16 @@ module.exports = function (results) {
const name = path.normalize(result.file)
const severity = result.type
var file = files[name]
var issues
var fileName, issues
if (!file) {
if (showFileNameOnly) {
fileName = path.parse(name)
fileName = fileName.name + fileName.ext
} else {
fileName = name
}
file = files[name] = {
name: name,
name: fileName,
errors: [],
warnings: [],
notices: []
Expand Down
File renamed without changes.
Loading

0 comments on commit 97973d8

Please sign in to comment.