Skip to content

Commit

Permalink
Re-wrap text in README.md to fit better within GitHub’s page layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
chimbori committed Apr 25, 2022
1 parent a40d920 commit a9f4cc8
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Crux

Crux offers a flexible plugin-based API & implementation to extract interesting information from Web pages.
Crux offers a flexible plugin-based API & implementation to extract interesting information from
Web pages.

## Sample Code

Expand All @@ -16,9 +17,11 @@ val htmlContent = """
|<html>
| <head>
| <title>Chimbori</title>
| <meta name="twitter:image" property="og:image" content="https://chimbori.com/media/cover-photo.png">
| <meta name="twitter:image" property="og:image"
| content="https://chimbori.com/media/cover-photo.png">
| <meta name="twitter:site" content="ChimboriApps">
| <link rel="apple-touch-icon-precomposed" sizes="192x192" href="https://chimbori.com/media/favicon.png">
| <link rel="apple-touch-icon-precomposed" sizes="192x192"
| href="https://chimbori.com/media/favicon.png">
| </head>
|</html>
|""".trimMargin()
Expand All @@ -35,7 +38,8 @@ assertEquals("Chimbori", extractedMetadata[TITLE])
// Well-known URLs related to this page are available either as strings or
// OkHttp [HttpUrl]s.
assertEquals("https://chimbori.com/media/favicon.png", extractedMetadata[FAVICON_URL])
assertEquals("https://chimbori.com/media/favicon.png".toHttpUrl(), extractedMetadata.urls[FAVICON_URL])
assertEquals("https://chimbori.com/media/favicon.png".toHttpUrl(),
extractedMetadata.urls[FAVICON_URL])

// Extra markup fields like Twitter Cards metadata or Open Graph metadata are
// available as metadata fields as well.
Expand Down Expand Up @@ -87,46 +91,48 @@ Rewrites URLs generated by the Facebook Redirector Service to their canonical (o

## TrackingParameterRemover

Removes URL parameters typically used by analytics providers to track users’ behavior across the Web.
This plugin is optional because it may break some misconfigured URLs and cause them to return the wrong content.
Removes URL parameters typically used by analytics providers to track users’ behavior across the
Web. This plugin is optional because it may break some misconfigured URLs and cause them to
return the wrong content.

# Design & Features

Crux is designed as a chain of plugins; each one performs a small specific task.

Each plugin receives as input a `Resource` object, which includes a URL and all the fields populated by previous
plugins in the chain. Each plugin can
Each plugin receives as input a `Resource` object, which includes a URL and all the fields
populated by previous plugins in the chain. Each plugin can

- extract new pieces of metadata and add them to the output, or
- overwrite existing fields by setting a new value for the same key, or
- remove existing fields by setting a `null` value for that key.

A small set of well-known key names are defined in the API as `Fields`, but plugins and clients are not restricted to
this set. You can extend Crux for your own applications by defining and using your own string keys for extracted
metadata.
A small set of well-known key names are defined in the API as `Fields`, but plugins and clients are
not restricted to this set. You can extend Crux for your own applications by defining and using
your own string keys for extracted metadata.

Plugins can rewrite URLs, which are then passed on down the chain. This is how HTTP redirects (301 and 302) as well as
static
redirectors (such as those from Google and Facebook) are handled.
Plugins can rewrite URLs, which are then passed on down the chain. This is how HTTP redirects
(301 and 302) as well as static redirectors (such as those from Google and Facebook) are handled.

Each plugin is independent of others. You can pick and choose the ones you want to use. If you use Crux in an Android
app, Proguard or other minification tools can strip out the plugins you don’t use.
Each plugin is independent of others. You can pick and choose the ones you want to use. If you use
Crux in an Android app, Proguard or other minification tools can strip out the plugins you don’t
use.

Crux’s API includes fewer setters/getters (compared to other such libraries), to keep the method count low (this is
important for Android). Its plugin-based architecture makes it cleaner & leaner, compared to other libraries not
explicitly optimized for Android.
Crux’s API includes fewer setters/getters (compared to other such libraries), to keep the method
count low (this is important for Android). Its plugin-based architecture makes it cleaner &
leaner, compared to other libraries not explicitly optimized for Android.

## Writing a Custom Plugin

```kotlin
// If you write a new plugin yourself, you can add any custom fields to the `Resource` object yourself,
// and consume them in your own app.
// If you write a new plugin yourself, you can add any custom fields to the `Resource` object
// yourself, and consume them in your own app.
val customerNumberExtractorPlugin = object : Plugin {
// Indicate that your plugin can handle all URLs on your site, but no others.
override fun canHandle(url: HttpUrl): Boolean = url.topPrivateDomain() == "your-website.com"

// Fields in the returned [Resource] overwrite those in the input [request]. If no changes are to be made, then
// return null from your plugin. Otherwise, only return those fields that are new or changed from the input.
// Fields in the returned [Resource] overwrite those in the input [request]. If no changes are
// to be made, then return null from your plugin. Otherwise, only return those fields that are
// new or changed from the input.
override suspend fun handle(request: Resource) = Resource(
fields = mapOf(CUSTOMER_NUMBER_FIELD to request.url?.queryParameter("customer-number"))
)
Expand Down Expand Up @@ -196,8 +202,10 @@ Crux uses semantic versioning. If the API changes, then the major version will b
Upgrading from one minor version to the next minor version within the same major version should
not require any client code to be modified.

The latest release is available via [Maven Central](https://search.maven.org/artifact/com.chimbori.crux/crux)
or [GitHub Releases](https://github.com/chimbori/crux/releases).
The latest release is available via
[Maven Central](https://search.maven.org/artifact/com.chimbori.crux/crux)
or
[GitHub Releases](https://github.com/chimbori/crux/releases).

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.chimbori.crux/crux/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.chimbori.crux/crux)

Expand Down Expand Up @@ -260,8 +268,9 @@ Crux began as a fork of [Snacktory](http://github.com/karussell/snacktory) with
it more performant on Android devices, but it has quickly gained several new features that are not
available in Snacktory.

Snacktory (and thus Crux) borrow ideas and test cases from [Goose](https://github.com/GravityLabs/goose)
and [JReadability](https://github.com/ifesdjeen/jReadability).
Snacktory (and thus Crux) borrow ideas and test cases from
[Goose](https://github.com/GravityLabs/goose) and
[JReadability](https://github.com/ifesdjeen/jReadability).

# License

Expand Down

0 comments on commit a9f4cc8

Please sign in to comment.