Skip to main content

arch_toolkit/news/
mod.rs

1//! News module for Arch Linux news and security advisories.
2//!
3//! This module provides:
4//!
5//! - **Arch news** — fetch and parse the official news RSS feed
6//!   (`https://archlinux.org/feeds/news/`)
7//! - **Security advisories** — fetch and parse the advisory Atom feed
8//!   (`https://security.archlinux.org/advisory/feed.atom`)
9//! - **Date normalization** — feed dates (RFC 2822 / RFC 3339 / ISO 8601)
10//!   normalized to `YYYY-MM-DD` for lexicographic sorting
11//!
12//! Parse functions are pure (no network), so applications can test against
13//! recorded feeds. Fetch functions take a caller-provided `reqwest::Client`,
14//! keeping timeouts, user agent, and fetch cadence under caller control.
15//!
16//! # Features
17//!
18//! This module requires the `news` feature flag:
19//!
20//! ```toml
21//! [dependencies]
22//! arch-toolkit = { version = "0.2", features = ["news"] }
23//! ```
24//!
25//! # Examples
26//!
27//! ## Fetch Recent News
28//!
29//! ```no_run
30//! use arch_toolkit::news::fetch_arch_news;
31//!
32//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
33//! let client = reqwest::Client::new();
34//! let items = fetch_arch_news(&client, 10, None).await?;
35//! for item in items {
36//!     println!("{} {}", item.date, item.title);
37//! }
38//! # Ok(())
39//! # }
40//! ```
41//!
42//! ## Fetch Security Advisories Since a Date
43//!
44//! ```no_run
45//! use arch_toolkit::news::fetch_security_advisories;
46//!
47//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
48//! let client = reqwest::Client::new();
49//! let advisories = fetch_security_advisories(&client, 50, Some("2026-01-01")).await?;
50//! for advisory in advisories {
51//!     println!("{} [{}] {}", advisory.date, advisory.severity, advisory.title);
52//! }
53//! # Ok(())
54//! # }
55//! ```
56//!
57//! ## Parse a Recorded Feed (no network)
58//!
59//! ```
60//! use arch_toolkit::news::parse_arch_news_rss;
61//!
62//! let rss = "<item><title>Update</title><link>https://archlinux.org/news/u/</link>\
63//!            <pubDate>Thu, 21 Aug 2025 12:00:00 +0000</pubDate></item>";
64//! let items = parse_arch_news_rss(rss, 10, None);
65//! assert_eq!(items[0].date, "2025-08-21");
66//! ```
67
68mod advisories;
69mod arch;
70mod article;
71mod cache;
72mod date;
73
74// Re-export types from types module
75pub use crate::types::news::{AdvisorySeverity, ArchNewsItem, SecurityAdvisory};
76
77// Re-export generic cache boundary
78pub use cache::{FeedCache, InMemoryFeedCache};
79
80// Re-export news functions
81pub use arch::{
82    ARCH_NEWS_FEED_URL, MAX_FEED_RESPONSE_BYTES, fetch_arch_news, fetch_arch_news_cached,
83    fetch_arch_news_cached_from, fetch_arch_news_from, parse_arch_news_rss,
84};
85
86// Re-export article extraction functions
87pub use article::{
88    MAX_ARTICLE_HTML_BYTES, MAX_ARTICLE_TEXT_BYTES, extract_article_text, fetch_article_text,
89};
90
91// Re-export advisory functions
92pub use advisories::{
93    ADVISORY_FEED_URL, fetch_security_advisories, fetch_security_advisories_cached,
94    fetch_security_advisories_cached_from, fetch_security_advisories_from, parse_advisories_atom,
95};
96
97// Re-export date utilities
98pub use date::normalize_feed_date;