Exoplanet.Filters (Exoplanet v0.4.0)

Copy Markdown View Source

Per-feed content filters: HTML sanitization, category allow/block lists, image stripping, and summary truncation. The sanitizer removes dangerous tags and style attributes but the default configuration does not filter attribute-based injection vectors such as on* event handlers or javascript: URIs.

Summary

Functions

Applies the merged filter map to a list of Exoplanet.Post structs.

Built-in default filter map. Used by Exoplanet.Config as the baseline for default_filters and as the starting point that user-supplied default_filters are merged onto.

Merges a per-feed filter map onto a default filter map.

Types

t()

@type t() :: %{
  allow_categories: [String.t()],
  block_categories: [String.t()],
  strip_images: boolean(),
  excerpt_length: pos_integer() | nil,
  sanitize_html: boolean(),
  drop_tags: [String.t()],
  drop_attrs: [String.t()]
}

Functions

apply(posts, filters)

@spec apply([Exoplanet.Post.t()], t()) :: [Exoplanet.Post.t()]

Applies the merged filter map to a list of Exoplanet.Post structs.

Returns the filtered list. Posts dropped by category filters are removed entirely. The sanitize_html and strip_images filters modify each post's :body and :summary. The excerpt_length filter modifies only :summary. Sanitization runs first, then image stripping, then excerpt generation. When both HTML filters are enabled they share a single tree walk.

defaults()

@spec defaults() :: t()

Built-in default filter map. Used by Exoplanet.Config as the baseline for default_filters and as the starting point that user-supplied default_filters are merged onto.

merge(defaults, per_feed)

@spec merge(t(), map() | nil) :: t()

Merges a per-feed filter map onto a default filter map.

allow_categories and block_categories REPLACE the default value when the per-feed map sets them to a list. Other keys override field-by-field. Per-feed keys set to nil leave the default in place.