Skip to content

Commit

Permalink
v7.0.0rc2
Browse files Browse the repository at this point in the history
  • Loading branch information
ndaidong committed Jul 9, 2022
1 parent 36f74c7 commit f6e3ffd
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 111 deletions.
66 changes: 33 additions & 33 deletions dist/article-parser.browser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/article-parser.browser.js.map

Large diffs are not rendered by default.

96 changes: 48 additions & 48 deletions dist/cjs/article-parser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/cjs/article-parser.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "article-parser-cjs",
"version": "7.0.0rc1",
"version": "7.0.0rc2",
"main": "./article-parser.js"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "7.0.0rc1",
"version": "7.0.0rc2",
"name": "article-parser",
"description": "To extract main article from given URL",
"homepage": "https://ndaidong.github.io/article-parser-demo/",
Expand Down
37 changes: 13 additions & 24 deletions src/utils/extractWithReadability.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,27 @@ import { Readability } from '@mozilla/readability'
import { DOMParser } from 'linkedom'

import { isValid as isHTMLString } from './html.js'
import { error } from './logger.js'

/**
* @param html {string}
* @param inputUrl {string}
* @returns {string|null}
*/
export default (html, inputUrl = '') => {
try {
if (!isHTMLString(html)) return null
const doc = new DOMParser().parseFromString(html, 'text/html')
const base = doc.createElement('base')
base.setAttribute('href', inputUrl)
doc.head.appendChild(base)
const reader = new Readability(doc)
const result = reader.parse() ?? {}
return result.textContent ? result.content : null
} catch (err) {
error(err.message)
return null
}
if (!isHTMLString(html)) return null
const doc = new DOMParser().parseFromString(html, 'text/html')
const base = doc.createElement('base')
base.setAttribute('href', inputUrl)
doc.head.appendChild(base)
const reader = new Readability(doc)
const result = reader.parse() ?? {}
return result.textContent ? result.content : null
}

export function extractTitleWithReadability (html) {
try {
if (!isHTMLString(html)) return null
const doc = new DOMParser().parseFromString(html, 'text/html')
const reader = new Readability(doc)
// noinspection JSUnresolvedFunction
return reader._getArticleTitle()
} catch (err) {
error(err.message)
return ''
}
if (!isHTMLString(html)) return null
const doc = new DOMParser().parseFromString(html, 'text/html')
const reader = new Readability(doc)
// noinspection JSUnresolvedFunction
return reader._getArticleTitle()
}

0 comments on commit f6e3ffd

Please sign in to comment.