diff options
| author | Fuwn <[email protected]> | 2026-02-14 22:15:38 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-14 22:15:38 -0800 |
| commit | aa77f71d194e37978e51dacf21c9ab36e315dec9 (patch) | |
| tree | 15190625104fadb34badce493480a17c9c57c7bb /src/modules | |
| parent | build(container): Force linux/amd64 image build in publish-images recipe (diff) | |
| download | locus-aa77f71d194e37978e51dacf21c9ab36e315dec9.tar.xz locus-aa77f71d194e37978e51dacf21c9ab36e315dec9.zip | |
feat(blog): Add hidden query flag to trigger manual Notion sync
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/blog/module.rs | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/modules/blog/module.rs b/src/modules/blog/module.rs index bcb61da..b1ca8c6 100644 --- a/src/modules/blog/module.rs +++ b/src/modules/blog/module.rs @@ -26,6 +26,10 @@ pub fn module(router: &mut windmark::router::Router) { .join() .expect("initial Notion fetch failed"); track_mount(router, "/blog", "Fuwn's blogs", |context| { + if should_trigger_manual_refresh(context.url.query()) { + trigger_manual_refresh(); + } + let categories = BLOG_CATEGORIES.read().unwrap(); let listing = categories .iter() @@ -113,6 +117,22 @@ pub fn module(router: &mut windmark::router::Router) { ); } +fn should_trigger_manual_refresh(query: Option<&str>) -> bool { + query.is_some_and(|query_string| { + query_string.split('&').any(|query_part| { + query_part.split_once('=').map_or(query_part, |(key, _)| key) + == "__refresh" + }) + }) +} + +fn trigger_manual_refresh() { + match std::panic::catch_unwind(fetch_from_notion) { + Ok(()) => info!("manually refreshed blog data from Notion"), + Err(_) => warn!("manual Notion refresh failed"), + } +} + fn construct_header(post: &BlogPost) -> String { let title_line = format!("# {}", post.title); let has_metadata = post.author.is_some() @@ -444,8 +464,8 @@ pub fn refresh_loop() { mod tests { use super::{ build_global_posts, build_rss_feed, find_visible_post_by_slug, - render_blog_page, slugify, visible_posts_for_blog, BLOG_CATEGORIES, - BLOG_POSTS, + render_blog_page, should_trigger_manual_refresh, slugify, + visible_posts_for_blog, BLOG_CATEGORIES, BLOG_POSTS, }; use crate::modules::blog::config::{BlogCategory, BlogPost}; @@ -721,4 +741,14 @@ mod tests { "# The Daily (1)\n\ndesc\n\n=> /blog/the_daily/entry_one Entry One" )); } + + #[test] + fn should_trigger_manual_refresh_when_hidden_query_is_present() { + assert!(should_trigger_manual_refresh(Some("__refresh=1"))); + assert!(should_trigger_manual_refresh(Some("foo=bar&__refresh=1"))); + assert!(should_trigger_manual_refresh(Some("__refresh&foo=bar"))); + assert!(!should_trigger_manual_refresh(Some("refresh=1"))); + assert!(!should_trigger_manual_refresh(Some("foo=bar"))); + assert!(!should_trigger_manual_refresh(None)); + } } |