| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use makeover_layout as layout; |
| 23 |
use quasi_declare::declare; |
| 24 |
use quasi_router::{Document, Feed, FeedKind, Screen as Described}; |
| 25 |
use quasi_webview::Webview; |
| 26 |
|
| 27 |
use crate::types::BlogPostSummary; |
| 28 |
|
| 29 |
|
| 30 |
pub const PAGE_REGION: &str = "project-blog"; |
| 31 |
|
| 32 |
|
| 33 |
const MEASURE: layout::Measure = layout::Measure::Wide; |
| 34 |
|
| 35 |
|
| 36 |
#[must_use] |
| 37 |
pub fn feed_path(project_slug: &str) -> String { |
| 38 |
format!("/p/{project_slug}/blog/feed.xml") |
| 39 |
} |
| 40 |
|
| 41 |
declare! { |
| 42 |
|
| 43 |
#[must_use] |
| 44 |
pub shape screen( |
| 45 |
project_title: &str, |
| 46 |
project_slug: &str, |
| 47 |
creator_username: &str, |
| 48 |
posts: &[BlogPostSummary], |
| 49 |
) -> Screen; |
| 50 |
|
| 51 |
let feed = feed_path(project_slug); |
| 52 |
|
| 53 |
screen single "Blog - {project_title}" { |
| 54 |
measured MEASURE; |
| 55 |
documented Document::default() |
| 56 |
.classed(crate::shell::body_class(MEASURE, &["project-blog-page"])); |
| 57 |
summarised "Posts from {project_title}, by {creator_username}."; |
| 58 |
about quasi_router::SocialKind::Article; |
| 59 |
syndicating Feed::new(FeedKind::Rss, "{project_title} - Blog RSS", feed); |
| 60 |
|
| 61 |
region PAGE_REGION as Pane { |
| 62 |
page "{project_title} Blog"; |
| 63 |
link creator_username to get "/u/{creator_username}" navigating; |
| 64 |
link "View project" to get "/p/{project_slug}" navigating; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
act "RSS Feed" to get feed.clone() navigating; |
| 70 |
|
| 71 |
given posts.is_empty() { |
| 72 |
true -> empty "No blog posts yet."; |
| 73 |
otherwise -> list { |
| 74 |
for post in posts.iter() { |
| 75 |
row post.title.clone() { |
| 76 |
meta post.published_at.clone(); |
| 77 |
activate to get "/p/{project_slug}/blog/{post.slug}" navigating; |
| 78 |
} |
| 79 |
} |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
link "Powered by Makenot.work" to get "/" navigating; |
| 87 |
} |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
#[must_use] |
| 93 |
pub fn renderer(user: Option<&crate::auth::SessionUser>, csrf: Option<&str>) -> Webview { |
| 94 |
let csrf = csrf.unwrap_or_default(); |
| 95 |
Webview::new().with_shell( |
| 96 |
crate::shell::described() |
| 97 |
.sending("X-CSRF-Token", csrf) |
| 98 |
.with_body_last(crate::shell::body_last()) |
| 99 |
.with_body_first(format!( |
| 100 |
"{}{}", |
| 101 |
crate::shell::skip_link(PAGE_REGION), |
| 102 |
crate::shell::site_header(user) |
| 103 |
)) |
| 104 |
.with_head(format!( |
| 105 |
"<meta name=\"csrf-token\" content=\"{}\">", |
| 106 |
crate::helpers::escape_html(csrf) |
| 107 |
)), |
| 108 |
) |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
#[must_use] |
| 113 |
pub fn document( |
| 114 |
user: Option<&crate::auth::SessionUser>, |
| 115 |
csrf: Option<&str>, |
| 116 |
screen: &Described, |
| 117 |
) -> String { |
| 118 |
use quasi_axum::Serves as _; |
| 119 |
|
| 120 |
renderer(user, csrf).screen(screen) |
| 121 |
} |
| 122 |
|
| 123 |
#[cfg(test)] |
| 124 |
mod tests { |
| 125 |
use super::*; |
| 126 |
|
| 127 |
fn posts() -> Vec<BlogPostSummary> { |
| 128 |
vec![BlogPostSummary { |
| 129 |
title: "First light".to_owned(), |
| 130 |
slug: "first-light".to_owned(), |
| 131 |
published_at: "2026-08-01".to_owned(), |
| 132 |
}] |
| 133 |
} |
| 134 |
|
| 135 |
fn html(screen: &Described) -> String { |
| 136 |
document(None, Some("t"), screen) |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
#[test] |
| 143 |
fn the_feed_is_declared_once_and_spelled_by_the_vocabulary() { |
| 144 |
let screen = screen("Blue Hour", "blue-hour", "maxj", &posts()); |
| 145 |
let feed = screen.discovery.feed.as_ref().expect("declared"); |
| 146 |
assert_eq!(feed.href, "/p/blue-hour/blog/feed.xml"); |
| 147 |
assert_eq!(feed.title, "Blue Hour - Blog RSS"); |
| 148 |
|
| 149 |
let rendered = html(&screen); |
| 150 |
assert!( |
| 151 |
rendered.contains( |
| 152 |
"<link rel=\"alternate\" type=\"application/rss+xml\" \ |
| 153 |
title=\"Blue Hour - Blog RSS\" href=\"/p/blue-hour/blog/feed.xml\">" |
| 154 |
), |
| 155 |
"{rendered}" |
| 156 |
); |
| 157 |
|
| 158 |
assert_eq!( |
| 159 |
rendered.matches("rel=\"alternate\"").count(), |
| 160 |
1, |
| 161 |
"{rendered}" |
| 162 |
); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
#[test] |
| 168 |
fn the_feed_is_offered_to_a_reader_as_well_as_to_their_app() { |
| 169 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &posts())); |
| 170 |
assert!(rendered.contains(">RSS Feed<"), "{rendered}"); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
#[test] |
| 175 |
fn every_post_keeps_its_row_and_its_address() { |
| 176 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &posts())); |
| 177 |
assert!(rendered.contains("First light"), "{rendered}"); |
| 178 |
assert!( |
| 179 |
rendered.contains("/p/blue-hour/blog/first-light"), |
| 180 |
"{rendered}" |
| 181 |
); |
| 182 |
assert!(rendered.contains("2026-08-01"), "{rendered}"); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
#[test] |
| 188 |
fn a_blog_with_no_posts_says_so() { |
| 189 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &[])); |
| 190 |
assert!(rendered.contains("No blog posts yet."), "{rendered}"); |
| 191 |
} |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
#[test] |
| 197 |
fn the_creator_and_the_project_are_both_still_reachable() { |
| 198 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &posts())); |
| 199 |
|
| 200 |
assert!(rendered.contains("href=\"/u/maxj\""), "{rendered}"); |
| 201 |
assert!(rendered.contains("href=\"/p/blue-hour\""), "{rendered}"); |
| 202 |
assert!(rendered.contains(">maxj<"), "{rendered}"); |
| 203 |
assert!(rendered.contains(">View project<"), "{rendered}"); |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
#[test] |
| 209 |
fn a_blog_index_says_it_is_an_article() { |
| 210 |
let screen = screen("Blue Hour", "blue-hour", "maxj", &posts()); |
| 211 |
|
| 212 |
assert_eq!(screen.discovery.kind, quasi_router::SocialKind::Article); |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
#[test] |
| 218 |
fn the_document_carries_the_classes_the_template_carried() { |
| 219 |
let screen = screen("Blue Hour", "blue-hour", "maxj", &posts()); |
| 220 |
assert_eq!( |
| 221 |
screen.document.body_class.as_deref(), |
| 222 |
Some("padded-page project-blog-page") |
| 223 |
); |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
#[test] |
| 229 |
fn the_page_still_says_whose_platform_it_is() { |
| 230 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &posts())); |
| 231 |
assert!(rendered.contains("Powered by Makenot.work"), "{rendered}"); |
| 232 |
} |
| 233 |
|
| 234 |
|
| 235 |
#[test] |
| 236 |
fn the_page_spells_no_spinner() { |
| 237 |
let rendered = html(&screen("Blue Hour", "blue-hour", "maxj", &posts())); |
| 238 |
for spelling in ["htmx-indicator", "spinner", "loading-text", "loading-state"] { |
| 239 |
assert!(!rendered.contains(spelling), "{spelling} survives"); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|