Skip to content

Commit df96522

Browse files
committed
Normalize meta property tag
1 parent 5c70cdb commit df96522

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/metascraper/src/load-html.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
'use strict'
22

3+
const { forEach, flow, isEmpty, toLower } = require('lodash')
34
const sanitizeHtml = require('sanitize-html')
4-
const { flow, isNil } = require('lodash')
55
const cheerio = require('cheerio')
66

7-
const normalizeAttributes = propName => (tagName, attribs) => {
8-
if (!isNil(attribs[propName])) {
9-
attribs[propName] = attribs[propName].toLowerCase()
10-
}
7+
const normalizeAttributes = props => (tagName, attribs) => {
8+
forEach(props, propName => {
9+
if (!isEmpty(attribs[propName])) attribs[propName] = toLower(attribs[propName])
10+
})
1111
return { tagName, attribs }
1212
}
1313

1414
const sanitize = html =>
1515
sanitizeHtml(html, {
16-
allowedTags: false,
17-
allowedAttributes: false,
16+
allowedTags: false, // allow all tags
17+
allowedAttributes: false, // allow all attributes
1818
transformTags: {
19-
meta: normalizeAttributes('name'),
20-
a: normalizeAttributes('href'),
21-
link: normalizeAttributes('rel')
19+
meta: normalizeAttributes(['name', 'property']),
20+
a: normalizeAttributes(['href']),
21+
link: normalizeAttributes(['rel'])
2222
}
2323
})
2424

0 commit comments

Comments
 (0)