Skip to main content

Article

Struct Article 

Source
pub struct Article {
    pub title: Option<String>,
    pub content: Option<String>,
    pub text_content: Option<String>,
    pub length: usize,
    pub excerpt: Option<String>,
    pub byline: Option<String>,
    pub image: Option<String>,
    pub dir: Option<String>,
    pub site_name: Option<String>,
    pub lang: Option<String>,
    pub published_time: Option<String>,
    pub raw_content: Option<String>,
}
Expand description

Represents a successfully parsed article with extracted content and metadata.

The Article struct contains all the extracted information from a web page, including the main content (both HTML and plain text), metadata (title, author, publish date), and other article properties.

§Fields

All fields are optional (Option<String>) because not all web pages contain all metadata fields. The length field is always present and represents the character count of the extracted text.

§Serialization

This struct implements Serialize and Deserialize from serde, making it easy to save articles to JSON or other formats:

use readabilityrs::{Readability, Article};

if let Some(article) = readability.parse() {
    let json = serde_json::to_string_pretty(&article).unwrap();
    println!("{}", json);
}

Fields§

§title: Option<String>

The article title extracted from metadata or the document.

The title is extracted by checking multiple sources in priority order: JSON-LD structured data is checked first, followed by OpenGraph and Twitter Card meta tags. If neither is available, the <title> tag is used after cleaning it of the site name. As a final fallback, the first <h1> tag in the document is used.

§content: Option<String>

Cleaned HTML content of the article.

This contains the main article content with:

  • Ads and navigation removed
  • Unwanted elements filtered out
  • Relative URLs converted to absolute
  • Empty elements cleaned up
§text_content: Option<String>

Plain text content with all HTML tags removed.

This is the text-only version of the article content, useful for previews, search indexing, or analysis.

§length: usize

Length of the article in characters.

This is the character count of the plain text content, useful for reading time estimation or content validation.

§excerpt: Option<String>

Article description or short excerpt.

The excerpt is extracted from JSON-LD description if available, otherwise from OpenGraph or Twitter description meta tags. If no metadata is found, the meta description tag is used. As a fallback, the first paragraph of the extracted article content is used as the excerpt.

§byline: Option<String>

Author name(s).

The author is extracted from various sources, checking JSON-LD author data first, then meta author tags. If neither is available, elements with rel="author" or itemprop="author" attributes are examined. Finally, elements with classes like “byline” or “author” are checked. Multiple authors may be included and are separated by commas.

§image: Option<String>

The image is extracted from various sources, checking JSON-LD structured data first (supporting simple URLs, ImageObject with url property, and arrays of images). If not found, Open Graph meta tags are checked in priority order: og:image:secure_url, og:image:url, then og:image. Twitter card meta tags (twitter:image) and generic thumbnail or image meta tags are examined next. Finally, elements with link[rel="image_src"] or itemprop="image" attributes are checked as fallbacks. The first valid URL encountered in this priority order is used.

§dir: Option<String>

Text direction hint: “ltr” (left-to-right), “rtl” (right-to-left), or “auto”.

Extracted from the dir attribute on the <html> element.

§site_name: Option<String>

Name of the website or publication.

The site name is extracted from the OpenGraph og:site_name tag or the JSON-LD publisher name field.

§lang: Option<String>

Language code of the content (e.g., “en”, “es”, “fr”).

Extracted from the lang attribute on the <html> element or Content-Language meta tag.

§published_time: Option<String>

Publication or modification timestamp.

The publication time is extracted from the JSON-LD datePublished field or the article:published_time meta tag. The format varies depending on the source but is typically ISO 8601.

§raw_content: Option<String>

Raw HTML content before final post-processing.

This is the extracted content before the final cleaning steps, useful for debugging or custom post-processing.

Implementations§

Source§

impl Article

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Clone for Article

Source§

fn clone(&self) -> Article

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Article

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Article

Source§

fn default() -> Article

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Article

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Article

Source§

fn eq(&self, other: &Article) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Article

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Article

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,