Skip to content

Commit e49a85c

Browse files
committed
Add condition to stop
1 parent 8766f13 commit e49a85c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

packages/metascraper-lang/__snapshots__/index.js.snap-shot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exports['html lang property 1'] = {
22
"lang": "pl",
33
"author": "Jakub Majmurek",
44
"title": "Churchill, bohater naszych czasów / Film / dwutygodnik.com",
5-
"publisher": "Film | Dwutygodnik | Dwutygodnik",
5+
"publisher": "Dwutygodnik",
66
"image": "http://www.dwutygodnik.com/public/media/article/image_full/7615.png",
77
"date": "2018-01-01T12:00:00.000Z",
88
"description": "Wysyp filmów o Churchillu w pobrexitowej Brytanii, wydaje się czymś zrozumiałym. Uosabia on ostatni moment prawdziwej wielkości Zjednoczonego Królestwa – wspomnienie tej historycznej chwili pozwala oswoić traumy i lęki",

packages/metascraper-publisher/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const wrap = rule => ({ htmlDom }) => {
2222

2323
const getFromTitle = (text, regex) => {
2424
const matches = regex.exec(text)
25-
return matches ? matches[1] : false
25+
if (!matches) return false
26+
let result = matches[1]
27+
while (regex.test(result)) result = regex.exec(result)[1]
28+
return result
2629
}
2730

2831
/**

packages/metascraper-publisher/test/index.js

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

33
const should = require('should')
4-
54
const metascraper = require('metascraper')([require('..')()])
65

76
const getHtml = title => `
@@ -20,13 +19,18 @@ const getHtml = title => `
2019

2120
describe('metascraper-publisher', () => {
2221
describe('from title', async () => {
23-
;['Murcia | Wikipedia', 'Murcia - Wikipedia', '| Wikipedia'].forEach(
24-
title =>
25-
it(`${title} → Wikipedia`, async () => {
26-
const url = 'https://en.wikipedia.org/wiki/Murcia'
27-
const { publisher } = await metascraper({ html: getHtml(title), url })
28-
should(publisher).be.equal('Wikipedia')
29-
})
22+
;[
23+
'Murcia | Wikipedia',
24+
'Murcia - Wikipedia',
25+
'| Wikipedia',
26+
'San Antonio Spurs guard Manu Ginobili... - San Antonio Spurs | Wikipedia',
27+
'San Antonio Spurs guard Manu Ginobili... | San Antonio Spurs - Wikipedia'
28+
].forEach(title =>
29+
it(`${title} → Wikipedia`, async () => {
30+
const url = 'https://en.wikipedia.org/wiki/Murcia'
31+
const { publisher } = await metascraper({ html: getHtml(title), url })
32+
should(publisher).be.equal('Wikipedia')
33+
})
3034
)
3135
})
3236
})

0 commit comments

Comments
 (0)