Files
ttrss-plugin-af-fulltext/lib/Fetcher.php
Michal 9bc854ec44 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
2026-08-25 00:16:16 +01:00

30 lines
874 B
PHP

<?php
namespace AfFulltext;
final class FetchResult {
public function __construct(
public readonly string $html = '',
public readonly string $effective_url = '',
public readonly int $status = 0,
public readonly ?string $error = null,
) {}
public function ok(): bool {
return $this->error === null && $this->html !== '';
}
}
/**
* How a page's HTML is obtained. Kept behind an interface so the extraction
* pipeline is identical whether the markup came from a plain HTTP GET or from a
* headless browser -- and so the engine can be exercised from the CLI without
* tt-rss present.
*/
interface Fetcher {
/** @param array<string,string> $headers extra request headers (lowercased names) */
public function fetch(string $url, array $headers = []): FetchResult;
/** Short identifier used in logs and the prefs UI. */
public function name(): string;
}