File tree Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- const normalizeUrl = require ( 'normalize-url' )
3
+ const sanetizeUrl = require ( 'normalize-url' )
4
4
const isString = require ( 'lodash.isstring' )
5
5
6
+ const normalizeUrl = url => sanetizeUrl ( url , { stripWWW : false } )
7
+
6
8
/**
7
9
* Wrap a rule with validation and formatting logic.
8
10
*
9
11
* @param {Function } rule
10
12
* @return {Function } wrapped
11
13
*/
12
14
13
- const wrap = rule => $ => {
14
- let value = rule ( $ )
15
+ const wrap = rule => ( htmlDom , url ) => {
16
+ const value = rule ( htmlDom )
15
17
if ( ! isString ( value ) ) return
16
-
17
- return normalizeUrl ( value , {
18
- stripWWW : false
19
- } )
18
+ return normalizeUrl ( value )
20
19
}
21
20
22
21
/**
@@ -27,5 +26,5 @@ module.exports = [
27
26
wrap ( $ => $ ( 'meta[property="og:url"]' ) . attr ( 'content' ) ) ,
28
27
wrap ( $ => $ ( 'meta[name="twitter:url"]' ) . attr ( 'content' ) ) ,
29
28
wrap ( $ => $ ( 'link[rel="canonical"]' ) . attr ( 'href' ) ) ,
30
- wrap ( ( $ , url ) => url )
29
+ ( $ , url ) => isString ( url ) ? normalizeUrl ( url ) : null
31
30
]
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ const fs = require('fs')
9
9
const getMetaData = require ( '../../..' )
10
10
const readFile = promisify ( fs . readFile )
11
11
12
- const url = 'https://anisse.astier.eu'
12
+ const url = 'https://anisse.astier.eu/awk-driven-iot.html '
13
13
14
14
it ( 'astier' , async ( ) => {
15
15
const html = await readFile ( resolve ( __dirname , 'input.html' ) )
Original file line number Diff line number Diff line change 5
5
"image" : " https://anisse.astier.eu/images/anisse.jpg" ,
6
6
"publisher" : null ,
7
7
"title" : " Linux Engineer's random thoughts - awk driven IoT" ,
8
- "url" : null
8
+ "url" : " https://anisse.astier.eu/awk-driven-iot.html "
9
9
}
You can’t perform that action at this time.
0 commit comments