Commit Graph
150 Commits
Author SHA1 Message Date
Kevin Kuehler c358844abc Merge pull request #8349 from brave/speedreader_refactor_readability_backend
Speedreader refactor readability backend
2021-03-30 14:49:30 -07:00
Kevin Kuehler 63ec5719a8 speedreader: Update README and cargo fmt
* Run `cargo fmt` in the speedreader root
* Add a section to the README about fetching the test data, since it is
  not retrieved automatically.
2021-03-30 14:18:18 -07:00
Kevin Kuehler 18eaedb18f speedreader: Move kuchiki fork to Brave GH Org 2021-03-30 14:12:17 -07:00
Kevin Kuehler d5c886d654 speedreader: Make PR review changes 2021-03-30 14:12:14 -07:00
Kevin Kuehler e63c6fe9e0 speedreader: cli: call heuristics backend classify
Requested by Pete.
2021-03-30 10:08:39 -07:00
Kevin Kuehler 481b2c97d7 speedreader: Add --speedreader-backend switch
Resolves https://github.com/brave/brave-browser/issues/14959
2021-03-30 10:07:46 -07:00
Kevin Kuehler 956a6e3c6b speedreader: Make legacy tests work with new DOM 2021-03-26 13:55:28 -07:00
Kevin Kuehler 36b9f24eb9 Use clone_element_steal_children() for replacement 2021-03-24 00:47:58 -07:00
Kevin Kuehler d0bbeee6ae speedreader: Unwrap <div> with single <p> node
Some sites, like Slate and the BBC, have <div> elements enclosing single
<p> nodes. This weakens the paragraph's score from propagating higher in
the DOM during the scoring step. In the pre-process step, make this
replacement.

TODO: We may also want to consider doing the same thing for divs with no
block-level elements. I didn't implement it here because the function
_hasChildBlockElement() in Readability.js checks for non-block elements,
so the function in confusing and may be buggy? Not sure.
2021-03-24 00:34:42 -07:00
Kevin Kuehler 2f3174487c speedreader: Improve title extraction results
It is common for extra data to be in the title extracted title. It's
usually metadata after colons, separators (e.g '|', '-', '»', etc). Try
and strip those out, be be mindful of the resulting word length.
2021-03-23 15:26:09 -07:00
Kevin Kuehler 7dc2023106 speedreader: Append related siblings to new body
After the new body node is chosen as the readable root, iterate over
its sibling nodes, and append "related" siblings. This could be article
preambles, content split out by ads that were removed during the
preprocess step, etc.
2021-03-23 15:26:09 -07:00
Kevin Kuehler ad166901e7 speedreader: Remove tree data structures
We are maintaining a very minimal fork of kuchiki-rs at
https://github.com/keur/kuchiki/tree/speedreader. We expose two new
fields to API users: `score` and `is_candidate`. This removes the need
for both the nodes binary tree and the candidates binary tree. Kuchiki
has nice helper methods for accessing parents, descendants, and
ancestors, further removing the need for the Paths. The trees indexed by
`Path` structs were mostly hacking around the lack of API extensibility.
2021-03-23 15:25:53 -07:00
mkarolin 7bb904284b CreateDataPipe overload that takes pointer out-args was removed.
Chromium change:

https://source.chromium.org/chromium/chromium/src/+/3bce5dd0e62e636614521b902e26fb47070e18c9

commit 3bce5dd0e62e636614521b902e26fb47070e18c9
Author: Robert Sesek <rsesek@chromium.org>
Date:   Fri Feb 19 19:27:58 2021 +0000

    mojo: Remove deprecated CreateDataPipe overload that takes pointer out-args

    Bug: 944990
2021-03-23 14:55:32 -04:00
mkarolin c69d9a4e52 Most mojo legacy Binding classes have been removed.
Chromium changes:

https://chromium.googlesource.com/chromium/src.git/+/c56b5b62935046bbc3137fe7e202ee9e80035ab2

commit c56b5b62935046bbc3137fe7e202ee9e80035ab2
Author: Daniel Cheng <dcheng@chromium.org>
Date:   Fri Feb 5 01:24:35 2021 +0000

    [mojo] Remove most legacy Binding classes.

    AssociatedBinding is left as a followup, since AssociatedReceiver is
    implemented in terms of AssociatedBinding.

    Bug: 955171

https://chromium.googlesource.com/chromium/src.git/+/770cdcba6162c417af2e9700bf67e113903f99a1

commit 770cdcba6162c417af2e9700bf67e113903f99a1
Author: Daniel Cheng <dcheng@chromium.org>
Date:   Thu Feb 4 23:10:54 2021 +0000

    [mojo] Remove BindingSet helpers (replaced by *ReceiverSet equivalents).

    Bug: 955171
2021-03-23 14:55:16 -04:00
Kevin Kuehler f306650920 speedreader: Use text density when cleaning
Fix logic errors in the cleaning algorithm.
2021-03-21 21:03:47 -07:00
Kevin Kuehler ceb3b432c3 speedreader: Implement alternative candidates
This is another step towards algorithmic parity with Readability.js.

In the current implementation, we root the new DOM at top scoring
candidate. With this patch, we keep 1 top candidate and 4 alternative
candidates. If 3/4 of those candidates have a score near the top
candidate, we start iterating backwards starting from the top candidate.
If there is a shared parent with any 3 of the alternative candidates, we
make that the new root.

This is important, because some articles on Vanity Fair score very high
with a deeply nested top candidate, and real content is deleted from the
new DOM.
2021-03-21 21:03:47 -07:00
Kevin Kuehler d9d0d01fee speedreader: Don't indiscriminately clean text
This breaks the DOM structure and even gets rid of important content
spaces. We have a test case to cover a &nbsp; being deleted. Found on
rpp.pe

Refactor the test helper functions out of the main module.
2021-03-21 21:03:43 -07:00
Kevin Kuehler 129310abaf Remove outdated comment
This only applies to the Rcdom
2021-03-21 15:48:28 -07:00
Kevin Kuehler b5b6d56e71 delete markup5ever dependency 2021-03-21 15:45:38 -07:00
Kevin Kuehler b448ad7676 Compiling and tests passing 2021-03-21 15:45:38 -07:00
Kevin Kuehler 9464d7289c speedreader/readability: Use rust 2018 edition 2021-03-21 15:45:38 -07:00
Kevin Kuehler 8c11eedca9 speedreader: Have classifier use kuchiki DOM
The RcDom is deprecated and not recommended for production use.

Servo provides no guarantees about the stabality and security of the
Rcdom https://github.com/servo/html5ever/issues/385
2021-03-21 15:44:26 -07:00
Kevin Kuehler 47cb6a5e44 Merge pull request #8157 from brave/speedreader_heuristics_styling
Speedreader heuristic: Improve final render
2021-03-08 12:20:04 -08:00
Kevin Kuehler 5b03a9e47b speedreader: style changes and minimize clones 2021-03-08 12:08:06 -08:00
Kevin Kuehler c4be4ce188 speedreader: Unwrap images from <noscript> blocks
Some sites, such as Medium and BBC, put <img> tags as text inside of a
<noscript> tag. They use this to achieve a blurred image effect, where
the original blurred image is replaced with the higher resolution image
after some Javascript on the page runs.

In reader mode we aren't interested in that functionality. For all
<noscript> tags, we parse the text and check if there is a single image
element embedded inside of it. If there is, we pull that into our DOM
during the preprocess step and replace the <noscript> with the <img>. If
the <noscript> tag had an <img> element as the preceding sibling we
remove that image to avoid rendering both the blurred and final image.
2021-03-08 00:13:28 -08:00
Kevin Kuehler ef8c5a6473 Include title in the final DOM
Previously it was returned as part of the product string and not used at
all.
2021-03-05 15:39:13 -08:00
Kevin Kuehler 17776bc492 speedreader: Prefer meta to title when possible
Also include the title extraction test files as inlined code since they
are so small.
2021-03-05 15:37:09 -08:00
Kevin Kuehler 6244a33879 speedreader: Make streaming heuristic apply style
The CSS is included, but the article identifier is never applied to the
candidate node.
2021-03-05 10:53:48 -08:00
Terry Mancey 8c70a77b39 Merge pull request #8086 from brave/issues/14377
Change default ads per hour via variations service
2021-03-04 10:03:41 +00:00
Anton Lazarev c46d3d2f78 update native-tls to fix speedreader tests 2021-03-03 11:00:10 -08:00
Terry Mancey 4cc3db726d Change default ads per hour via variations service 2021-03-03 14:04:00 +00:00
renovate[bot]andRenovate Bot 10603f0ff8 Update Rust crate thiserror to 1.0.24 (#8029)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-22 19:03:38 +00:00
renovate[bot]andRenovate Bot 3d631a883e Update Rust crate reqwest to 0.11.1 (#8025)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-22 19:03:01 +00:00
bridiver 663372e943 lint fixes 2021-02-17 12:05:46 -07:00
bridiver 8c6024676d ensure rust libs are rebuilt when listed files change
add rust templates to simplify configuration
fix https://github.com/brave/brave-browser/issues/13320
2021-02-17 12:03:14 -07:00
Anton Lazarev 38560e586d cleanup outdated lockfiles (#7934) 2021-02-12 07:31:57 +00:00
renovate[bot]andRenovate Bot 9038bb4d0c Update Rust crate tokio to 1.2 (#7878)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-09 11:48:38 +00:00
renovate[bot]andRenovate Bot 7c9d94bd2b Update Rust crate serde_json to 1.0.62 (#7873)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-08 20:53:42 +00:00
renovate[bot]andRenovate Bot d3019581d6 Update Rust crate libc to 0.2.86 (#7872)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-08 19:58:20 +00:00
renovate[bot]andRenovate Bot 7069de07ad Update Rust crate flate2 to 1.0.20 (#7871)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
2021-02-08 19:35:29 +00:00
bridiver fb3c0f5561 buildtools/checkdeps/checkdeps.py brave --extra-repos=brave runs succesfully 2021-02-06 13:34:00 -07:00
Anton Lazarev 484e77fb14 update hyper to 0.14.4 2021-02-05 16:52:01 -08:00
mkarolin c869c58dff FilePathWatcher::Watch now takes an enum for recursive param.
Chromium change:

https://source.chromium.org/chromium/chromium/src/+/989852ed58f849453d062bcd3f3eecb5ccc14df0

commit 989852ed58f849453d062bcd3f3eecb5ccc14df0
Author: Greg Thompson <grt@chromium.org>
Date:   Mon Nov 23 22:32:27 2020 +0000

    [FilePathWatcher] Use an enum rather than a bool for the type of watch.

    No functional changes. This is in preparation for adding a new type for
    macOS. An overload of the Watch method that takes a bool is left behind
    for compatibility reasons. As a consequence, necessary casting is
    introduced to pick the correct overload when using base::Bind*.

    BUG=1147071
2021-02-04 23:52:08 -05:00
Anton Lazarev f62898f086 cleanup remaining lockfile diff 2021-01-29 11:51:05 -08:00
Anton Lazarev 9a03f8299e clean up speedreader dependencies 2021-01-28 10:01:09 -08:00
Anton Lazarev e690269b44 Merge pull request #7740 from brave/update-tokio-futures
Update tokio and reqwest dev-dependencies
2021-01-28 08:51:03 -08:00
Anton Lazarev 27424fa482 update tokio/reqwest dev-dependencies 2021-01-28 08:44:37 -08:00
Anton Lazarev d303064dc4 Merge pull request #7729 from brave/renovate/rust-serde_json-1.x
Update Rust crate serde_json to 1.0.61
2021-01-27 14:00:17 -08:00
Renovate Bot c6729c98a7 Update Rust crate serde_json to 1.0.61 2021-01-27 21:58:01 +00:00
Anton Lazarev 5977e4f8cc Merge pull request #7730 from brave/renovate/rust-thiserror-1.x
Update Rust crate thiserror to 1.0.23
2021-01-27 13:53:58 -08:00