Skip to content

Commit

Permalink
Add condition to stop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Aug 28, 2018
1 parent 8766f13 commit e49a85c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/metascraper-lang/__snapshots__/index.js.snap-shot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exports['html lang property 1'] = {
"lang": "pl",
"author": "Jakub Majmurek",
"title": "Churchill, bohater naszych czasów / Film / dwutygodnik.com",
"publisher": "Film | Dwutygodnik | Dwutygodnik",
"publisher": "Dwutygodnik",
"image": "http://www.dwutygodnik.com/public/media/article/image_full/7615.png",
"date": "2018-01-01T12:00:00.000Z",
"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",
Expand Down
5 changes: 4 additions & 1 deletion packages/metascraper-publisher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const wrap = rule => ({ htmlDom }) => {

const getFromTitle = (text, regex) => {
const matches = regex.exec(text)
return matches ? matches[1] : false
if (!matches) return false
let result = matches[1]
while (regex.test(result)) result = regex.exec(result)[1]
return result
}

/**
Expand Down
20 changes: 12 additions & 8 deletions packages/metascraper-publisher/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const should = require('should')

const metascraper = require('metascraper')([require('..')()])

const getHtml = title => `
Expand All @@ -20,13 +19,18 @@ const getHtml = title => `

describe('metascraper-publisher', () => {
describe('from title', async () => {
;['Murcia | Wikipedia', 'Murcia - Wikipedia', '| Wikipedia'].forEach(
title =>
it(`${title} → Wikipedia`, async () => {
const url = 'https://en.wikipedia.org/wiki/Murcia'
const { publisher } = await metascraper({ html: getHtml(title), url })
should(publisher).be.equal('Wikipedia')
})
;[
'Murcia | Wikipedia',
'Murcia - Wikipedia',
'| Wikipedia',
'San Antonio Spurs guard Manu Ginobili... - San Antonio Spurs | Wikipedia',
'San Antonio Spurs guard Manu Ginobili... | San Antonio Spurs - Wikipedia'
].forEach(title =>
it(`${title} → Wikipedia`, async () => {
const url = 'https://en.wikipedia.org/wiki/Murcia'
const { publisher } = await metascraper({ html: getHtml(title), url })
should(publisher).be.equal('Wikipedia')
})
)
})
})

0 comments on commit e49a85c

Please sign in to comment.