forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspot-content-flaws.js
32 lines (28 loc) · 1.07 KB
/
spot-content-flaws.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
// This middleware, exclusively in 'development' tries to spot flaws in
// the content you're actively viewing.
// The hopeful assumption is that if you're actively viewing this
// page on localhost, you're actively working on its content.
import path from 'path'
import kleur from 'kleur'
export default async function spotContentFlaws(req, res, next) {
const { page } = req.context
if (process.env.NODE_ENV === 'development' && page) {
const trailingSlashRedirects = (page.redirect_from || []).filter(
(uri) => uri.endsWith('/') && uri.startsWith('/')
)
if (trailingSlashRedirects.length > 0) {
console.warn(
`The page ${kleur.bold(path.relative(process.cwd(), page.fullPath))} has ${
trailingSlashRedirects.length
} redirect_from entries that have a trailing slash\n ${kleur.yellow(
trailingSlashRedirects.join('\n ')
)}`
)
console.log(
"If you're actively working on this page, consider",
kleur.bold('deleting all trailing slashes in redirect_from.\n')
)
}
}
return next()
}