From 7014f6359d60797c212822f73b89bc3ca4802206 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Tue, 5 Mar 2024 06:51:02 +0000 Subject: [PATCH] Make featured post temporary Also remove factorio since it posts so frequently --- README.md | 4 ++++ featured_feeds.txt | 3 +-- src/index_generator.rs | 15 +++++++++++---- src/main.rs | 7 ++----- src/utilities.rs | 7 +++++-- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 04d7d3d..805b9d4 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # Anson's Aggregated Feed Anson's Aggregated Feed is a Rust application designed to aggregate content from multiple RSS feeds, creating a personalized news page. It fetches articles from specified RSS feed URLs, generates HTML cards for each entry, and outputs a single, styled HTML page. This project showcases the use of Rust for web content aggregation and manipulation, leveraging several powerful crates for parsing RSS feeds, handling dates and times, making HTTP requests, and rendering HTML. + +## Featured Feeds + +These are feeds that are extremely high quality and don't post on a regular schedule. There are blogs (factorio for example) that I think are consistently high quality but I want to save this space for very special posts. \ No newline at end of file diff --git a/featured_feeds.txt b/featured_feeds.txt index 9380a0b..1d6db40 100644 --- a/featured_feeds.txt +++ b/featured_feeds.txt @@ -1,2 +1 @@ -https://ciechanow.ski/atom.xml -https://factorio.com/blog/rss \ No newline at end of file +https://ciechanow.ski/atom.xml \ No newline at end of file diff --git a/src/index_generator.rs b/src/index_generator.rs index 7ee4233..6939a2f 100644 --- a/src/index_generator.rs +++ b/src/index_generator.rs @@ -75,7 +75,7 @@ fn create_featured_card(entry: &Entry) -> Markup { } footer { a class="grid" href=(link.href) style="--pico-text-decoration: none;" { - button class="outline primary" { "Read Post" } + button class="outline primary" { "Read Featured Post" } } } } @@ -246,10 +246,9 @@ fn about_modal(entries: Vec) -> Markup { } } -pub fn generate_index(mut entries: Vec) -> Markup { +pub fn generate_index(mut entries: Vec, featured: Entry) -> Markup { let running_in_gitlab = env::var("CI").map(|val| val == "true").unwrap_or(false); - let featured = entries.remove(0); if running_in_gitlab { log::info!("Building for deployment"); entries.truncate(30); @@ -258,6 +257,14 @@ pub fn generate_index(mut entries: Vec) -> Markup { entries.truncate(6); } + let featured_card: maud::PreEscaped; + if (utilities::get_entry_date(&featured)) > (chrono::Utc::now() - chrono::Duration::days(3)) { + featured_card = create_featured_card(&featured); + entries.retain(|entry| entry != &featured); + } else { + featured_card = html! {}; + } + html! { (maud::DOCTYPE) html { @@ -272,7 +279,7 @@ pub fn generate_index(mut entries: Vec) -> Markup { } body { main class="container" { {(generate_header())} - (create_featured_card(&featured)) + (featured_card) div class="grid" { @for column_entries in utilities::group_by_nth(&entries, 3) { div { diff --git a/src/main.rs b/src/main.rs index 5d10ed3..8daacc1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,17 +17,14 @@ fn main() -> Result<(), Box> { simple_logger::init_with_level(log::Level::Info).unwrap(); let featured = read_feed("featured_feeds.txt").first().unwrap().clone(); - let mut entries = read_feed("feeds.txt"); + let entries = read_feed("feeds.txt"); - // Move featured article to the front - entries.retain(|entry| entry != &featured); - entries.insert(0, featured); log::info!( "Featured article: {}", entries[0].links.first().unwrap().href.as_str() ); - let index = index_generator::generate_index(entries); + let index = index_generator::generate_index(entries, featured); let output_path = Path::new("output/index.html"); DirBuilder::new() diff --git a/src/utilities.rs b/src/utilities.rs index cd5a03d..f6a2c6b 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -28,12 +28,15 @@ pub fn read_feed(path: &str) -> Vec { // Remove any entries that don't have a timestamp, and then sort by timestamps entries.retain(|entry| entry.published.is_some() || entry.updated.is_some()); - entries - .sort_by_key(|entry| Reverse(entry.published.unwrap_or(entry.updated.unwrap_or_default()))); + entries.sort_by_key(|entry| Reverse(get_entry_date(entry))); entries } +pub fn get_entry_date(entry: &Entry) -> chrono::DateTime { + entry.published.unwrap_or(entry.updated.unwrap_or_default()) +} + pub fn get_root_url(input_url: &str) -> &str { let mut url = input_url;