af_fulltext: rule-driven extraction with a pluggable renderer

Replaces subscribing feeds through a self-hosted Full-Text RSS proxy. Feed URLs
go back to being real feed URLs and extraction happens inside tt-rss, using the
same ftr-site-config rules the proxy used.

The engine in lib/ has no tt-rss dependencies, so rules can be developed and
audited from the command line; init.php is a thin adapter over it.

Two findings from measuring the real subscription first, both of which shaped
the design:

- Firecrawl's own onlyMainContent is far too coarse to extract with (73KB of
  chrome on a Cloudflare post), but it is an excellent renderer. So it is used
  for rawHtml only and the rule engine does the extraction.
- A body rule that stops matching after a redesign falls through to Readability
  and still produces a plausible article, so the breakage is invisible. Every
  extraction now records which rule matched and whether it fell back; auditing
  the 34 live feeds surfaced five community rules that match nothing.

Custom rules included for the sites that needed them, including three comics
where the article is an image and text-scoring extractors return the wrong thing
or nothing at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011sSJdftQx5bW5HZHgUKF3i
This commit is contained in:
Michal
2026-08-25 00:16:16 +01:00
commit 9bc854ec44
146 changed files with 30221 additions and 0 deletions

68
lib/Rule.php Normal file
View File

@@ -0,0 +1,68 @@
<?php
namespace AfFulltext;
/**
* A parsed FiveFilters site-config rule.
*
* Field names track the ftr-site-config directive names so a rule file and this
* object read the same way. Directives that may repeat accumulate into arrays,
* exactly as Full-Text RSS treats them.
*/
final class Rule {
/** @var string[] */ public array $titles = [];
/** @var string[] */ public array $bodies = [];
/** @var string[] */ public array $authors = [];
/** @var string[] */ public array $dates = [];
/** @var string[] */ public array $strips = [];
/** @var string[] */ public array $strip_id_or_class = [];
/** @var string[] */ public array $strip_image_src = [];
/** @var string[] */ public array $dissolve = [];
/** @var string[] */ public array $single_page_links = [];
/** @var string[] */ public array $next_page_links = [];
/** @var string[] */ public array $find_strings = [];
/** @var string[] */ public array $replace_strings = [];
/** @var string[] */ public array $test_urls = [];
/** @var array<string,string> */ public array $http_headers = [];
/** @var array<string,string> map of xpath => wrapper spec e.g. "div.foo" */
public array $wrap_in = [];
public bool $prune = true;
public bool $tidy = true;
public bool $autodetect_on_failure = true;
/**
* Files this rule was assembled from, nearest-match first. Surfaced in the
* UI so a stale rule is visible rather than silently falling through to
* Readability -- the exact failure mode that hid a broken comic rule for
* years.
*
* @var string[]
*/
public array $sources = [];
public function is_empty(): bool {
return !$this->bodies && !$this->strips && !$this->strip_id_or_class
&& !$this->strip_image_src && !$this->titles && !$this->dissolve;
}
/** Merge $other UNDER $this: existing scalars win, list directives concatenate. */
public function merge_under(self $other): self {
$m = clone $this;
foreach (['titles', 'bodies', 'authors', 'dates', 'single_page_links', 'next_page_links'] as $f)
if (!$m->$f) $m->$f = $other->$f;
foreach (['strips', 'strip_id_or_class', 'strip_image_src', 'dissolve', 'test_urls'] as $f)
$m->$f = array_values(array_unique([...$m->$f, ...$other->$f]));
// find/replace are positional pairs -- appending keeps them aligned.
$m->find_strings = [...$m->find_strings, ...$other->find_strings];
$m->replace_strings = [...$m->replace_strings, ...$other->replace_strings];
$m->http_headers = $m->http_headers + $other->http_headers;
$m->wrap_in = $m->wrap_in + $other->wrap_in;
$m->sources = [...$m->sources, ...$other->sources];
return $m;
}
}