Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/extractors/custom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@ export const ExampleExtractor = {
...
```

If the array includes a callback function as 3rd element, all the results pass through that transformer. Returned values are the result of selector.
For example:

```javascript
date_published: {
selectors: [[
'meta[name="article:published_time"]',
'value',
(item) => moment.from(convertNumbersToEnglish(item), 'fa',
'YYYY/MM/DD - HH:mm').toISOString();
]]
}
```

```javascript


extend: {
tags: {
selectors: [[
'meta[name=\'article:tag\']', 'value', (item) => {
return item.split(/\s*,\s*/);
}]],
allowMultiple: true
}
}
```

This is all you'll need to know to handle most of the fields Mercury parses (titles, authors, date published, etc.). Article content is the exception.

#### Content selectors
Expand Down
16 changes: 9 additions & 7 deletions src/extractors/root-extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ function findMatchingSelector($, selectors, extractHtml, allowMultiple) {
}

const [s, attr] = selector;
return (
(allowMultiple || (!allowMultiple && $(s).length === 1)) &&
$(s).attr(attr) &&
$(s)
.attr(attr)
.trim() !== ''
);
if (attr)
return (
(allowMultiple || (!allowMultiple && $(s).length === 1)) &&
$(s).attr(attr) &&
$(s)
.attr(attr)
.trim() !== ''
);
selector = s;
}

return (
Expand Down