Skip to content

Commit dbdba26

Browse files
committed
Support resolve URL
1 parent fdebba6 commit dbdba26

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

src/get-data/rules/url.js

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

3-
const normalizeUrl = require('normalize-url')
3+
const sanetizeUrl = require('normalize-url')
44
const isString = require('lodash.isstring')
55

6+
const normalizeUrl = url => sanetizeUrl(url, {stripWWW: false})
7+
68
/**
79
* Wrap a rule with validation and formatting logic.
810
*
911
* @param {Function} rule
1012
* @return {Function} wrapped
1113
*/
1214

13-
const wrap = rule => $ => {
14-
let value = rule($)
15+
const wrap = rule => (htmlDom, url) => {
16+
const value = rule(htmlDom)
1517
if (!isString(value)) return
16-
17-
return normalizeUrl(value, {
18-
stripWWW: false
19-
})
18+
return normalizeUrl(value)
2019
}
2120

2221
/**
@@ -27,5 +26,5 @@ module.exports = [
2726
wrap($ => $('meta[property="og:url"]').attr('content')),
2827
wrap($ => $('meta[name="twitter:url"]').attr('content')),
2928
wrap($ => $('link[rel="canonical"]').attr('href')),
30-
wrap(($, url) => url)
29+
($, url) => isString(url) ? normalizeUrl(url) : null
3130
]

test/web/astier/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const fs = require('fs')
99
const getMetaData = require('../../..')
1010
const readFile = promisify(fs.readFile)
1111

12-
const url = 'https://anisse.astier.eu'
12+
const url = 'https://anisse.astier.eu/awk-driven-iot.html'
1313

1414
it('astier', async () => {
1515
const html = await readFile(resolve(__dirname, 'input.html'))

test/web/astier/output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"image": "https://anisse.astier.eu/images/anisse.jpg",
66
"publisher": null,
77
"title": "Linux Engineer's random thoughts - awk driven IoT",
8-
"url": null
8+
"url": "https://anisse.astier.eu/awk-driven-iot.html"
99
}

0 commit comments

Comments
 (0)