Add more demo feeds

This commit is contained in:
Greg Shuflin 2025-02-03 16:08:17 -08:00
parent 3ab595abd2
commit 411cdc5890
2 changed files with 35 additions and 19 deletions

View File

@ -46,7 +46,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
.await
.expect("Failed to create demo user");
let feed = Feed::new(
let bbc_news = Feed::new(
"BBC News".to_string(),
"https://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml"
.parse()
@ -54,6 +54,21 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
demo_id,
);
let xkcd = Feed::new(
"XKCD".to_string(),
"https://xkcd.com/atom.xml".parse().unwrap(),
demo_id,
);
let isidore = Feed::new(
"Isidore & Friends".to_string(),
"https://isidore.webcomic.ws/rss/".parse().unwrap(),
demo_id,
);
let feeds = [bbc_news, xkcd, isidore];
for feed in feeds {
// TODO: This insert logic is substantially the same as Feed::write_to_database.
// Should find a way to unify these two code paths to avoid duplication.
sqlx::query(
@ -70,6 +85,7 @@ pub async fn setup_demo_data(pool: &sqlx::SqlitePool) {
.execute(pool)
.await
.expect("Failed to create demo feed");
}
println!("Successfully set up demo data");
}

View File

@ -12,7 +12,7 @@ mod user;
use rocket::fairing::{self, AdHoc};
use rocket::fs::FileServer;
use rocket::response::Redirect;
use rocket::{Build, Rocket};
use rocket::{Build, Rocket, State};
use rocket_db_pools::{sqlx, Connection, Database};
use rocket_dyn_templates::{context, Template};
use user::AuthenticatedUser;
@ -58,7 +58,7 @@ async fn index_redirect(mut db: Connection<Db>) -> Redirect {
#[get("/login")]
fn login(demo_mode: &State<bool>) -> Template {
Template::render("login", context! { demo_mode: *demo_mode })
Template::render("login", context! { demo_mode: **demo_mode })
}
// Run migrations and setup demo data if needed