1use super::data::{format_tag, get_all_tags, get_article_by_slug};
4use crate::ui::components::footer::Footer;
5use crate::ui::components::main_nav::{ActivePage, MainNav};
6use crate::ui::inline_markup::inline_markup_html;
7use crate::ui::markdown_blocks::{blocks, Block};
8use crate::ui::router::Route;
9use crate::ui::seo::{
10 article_schema, breadcrumb_schema, organization_schema, BreadcrumbItem, JsonLdMultiple,
11 PageHead,
12};
13use dioxus::prelude::*;
14#[cfg(all(feature = "split", target_arch = "wasm32"))]
15use dioxus::wasm_split;
16
17const ARTICLE_STYLES: &str = r#"
18.article-page {
19 min-height: 100vh;
20 background: var(--bg-dark, #060814);
21 display: flex;
22 flex-direction: column;
23}
24
25.article-content {
26 flex: 1;
27 max-width: 720px;
28 margin: 0 auto;
29 padding: 48px 24px;
30 width: 100%;
31}
32
33.article-back {
34 display: inline-flex;
35 align-items: center;
36 gap: 8px;
37 color: var(--text-secondary, #b0b0b0);
38 text-decoration: none;
39 font-size: var(--font-body-sm, 14px);
40 margin-bottom: 32px;
41 transition: color 0.2s ease;
42}
43
44.article-back:hover {
45 color: var(--text-primary, #f0f0f0);
46}
47
48.article-header {
49 margin-bottom: 40px;
50}
51
52.article-meta {
53 display: flex;
54 align-items: center;
55 gap: 16px;
56 margin-bottom: 16px;
57 flex-wrap: wrap;
58}
59
60.article-date {
61 font-size: var(--font-caption-md, 12px);
62 color: var(--text-tertiary, #909090);
63 text-transform: uppercase;
64 letter-spacing: 0.5px;
65}
66
67.article-tags {
68 display: flex;
69 flex-wrap: wrap;
70 gap: 8px;
71}
72
73.article-tag {
74 white-space: nowrap;
75 font-size: 11px;
76 padding: 4px 10px;
77 border-radius: var(--radius-full, 9999px);
78 background: rgba(102, 126, 234, 0.15);
79 color: var(--color-accent-blue, #60a5fa);
80 letter-spacing: 0.3px;
81 font-weight: 600;
82}
83
84.article-title {
85 font-size: var(--font-display-md, 36px);
86 font-weight: 800;
87 background: linear-gradient(180deg, #ffffff 0%, rgba(229,231,235,0.85) 100%);
88 -webkit-background-clip: text;
89 -webkit-text-fill-color: transparent;
90 background-clip: text;
91 margin: 0 0 16px;
92 line-height: 1.2;
93}
94
95.article-author {
96 font-size: var(--font-body-md, 16px);
97 color: var(--text-secondary, #b0b0b0);
98}
99
100.article-body {
101 color: var(--text-primary, #f0f0f0);
102 font-size: var(--font-body-lg, 18px);
103 line-height: 1.8;
104}
105
106.article-body h2 {
107 font-size: var(--font-heading-lg, 26px);
108 font-weight: 700;
109 margin: 48px 0 24px;
110 color: var(--text-primary, #f0f0f0);
111}
112
113.article-body h3 {
114 font-size: var(--font-heading-md, 22px);
115 font-weight: 600;
116 margin: 32px 0 16px;
117 color: var(--text-primary, #f0f0f0);
118}
119
120.article-body p {
121 margin: 0 0 24px;
122}
123
124.article-body ul, .article-body ol {
125 margin: 0 0 24px;
126 padding-left: 24px;
127}
128
129.article-body li {
130 margin-bottom: 8px;
131}
132
133.article-body blockquote {
134 margin: 24px 0;
135 padding: 16px 24px;
136 background: rgba(255, 255, 255, 0.03);
137 border-left: 3px solid var(--color-accent-blue, #60a5fa);
138 border-radius: 0 var(--radius-md, 8px) var(--radius-md, 8px) 0;
139 font-style: italic;
140 color: var(--text-secondary, #b0b0b0);
141}
142
143.article-body code {
144 font-family: var(--font-mono, 'SF Mono', monospace);
145 font-size: 0.9em;
146 padding: 2px 6px;
147 background: rgba(255, 255, 255, 0.08);
148 border-radius: 4px;
149 color: var(--color-accent-purple, #a78bfa);
150}
151
152.article-body pre {
153 margin: 24px 0;
154 padding: 20px;
155 background: rgba(0, 0, 0, 0.3);
156 border-radius: var(--radius-lg, 12px);
157 overflow-x: auto;
158}
159
160.article-body pre code {
161 padding: 0;
162 background: none;
163 font-size: var(--font-body-sm, 14px);
164 color: var(--text-primary, #f0f0f0);
165}
166
167.article-body a {
168 color: var(--color-accent-blue, #60a5fa);
169 text-decoration: none;
170 border-bottom: 1px solid transparent;
171 transition: border-color 0.2s ease;
172}
173
174.article-body a:hover {
175 border-color: var(--color-accent-blue, #60a5fa);
176}
177
178.article-body strong {
179 font-weight: 600;
180 color: var(--text-primary, #f0f0f0);
181}
182
183.article-body hr {
184 border: 0;
185 border-top: 1px solid rgba(255, 255, 255, 0.08);
186 margin: 40px 0;
187}
188
189.article-body .article-table {
190 margin: 0 0 24px;
191 overflow-x: auto;
192}
193
194.article-body table {
195 width: 100%;
196 border-collapse: collapse;
197 font-size: var(--font-body-md, 16px);
198 line-height: 1.5;
199}
200
201.article-body th,
202.article-body td {
203 padding: 10px 14px;
204 border-bottom: 1px solid rgba(255, 255, 255, 0.08);
205 text-align: left;
206 vertical-align: top;
207}
208
209.article-body th {
210 font-weight: 600;
211 color: var(--text-primary, #f0f0f0);
212 border-bottom-color: rgba(255, 255, 255, 0.16);
213}
214
215.article-not-found {
216 text-align: center;
217 padding: 80px 24px;
218}
219
220.article-not-found h1 {
221 font-size: var(--font-display-md, 36px);
222 margin-bottom: 16px;
223 color: var(--text-primary, #f0f0f0);
224}
225
226.article-not-found p {
227 color: var(--text-secondary, #b0b0b0);
228 margin-bottom: 32px;
229}
230
231.article-not-found a {
232 display: inline-block;
233 padding: 12px 24px;
234 background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
235 color: white;
236 text-decoration: none;
237 border-radius: var(--radius-lg, 12px);
238 font-weight: 600;
239}
240
241/* Article footer with tags */
242.article-footer {
243 margin-top: 64px;
244 padding-top: 32px;
245 border-top: 1px solid rgba(255, 255, 255, 0.08);
246}
247
248.article-footer-section {
249 margin-bottom: 24px;
250}
251
252.article-footer-title {
253 font-size: var(--font-caption-md, 12px);
254 font-weight: 600;
255 color: var(--text-tertiary, #909090);
256 text-transform: uppercase;
257 letter-spacing: 1px;
258 margin: 0 0 16px;
259}
260
261.article-browse-tags {
262 display: flex;
263 gap: 8px;
264 flex-wrap: wrap;
265}
266
267.article-browse-tag {
268 padding: 8px 16px;
269 background: rgba(255, 255, 255, 0.05);
270 border: 1px solid rgba(255, 255, 255, 0.1);
271 border-radius: var(--radius-full, 9999px);
272 color: var(--text-secondary, #b0b0b0);
273 font-size: var(--font-body-sm, 14px);
274 text-decoration: none;
275 transition: all 0.2s ease;
276 letter-spacing: 0.3px;
277 font-weight: 600;
278}
279
280.article-browse-tag:hover {
281 background: rgba(102, 126, 234, 0.15);
282 border-color: rgba(102, 126, 234, 0.3);
283 color: var(--color-accent-blue, #60a5fa);
284}
285
286.article-browse-tag.current {
287 background: rgba(102, 126, 234, 0.2);
288 border-color: rgba(102, 126, 234, 0.4);
289 color: var(--color-accent-blue, #60a5fa);
290}
291
292/* Mobile */
293@media (max-width: 768px) {
294 .article-content {
295 padding: 32px 16px;
296 }
297
298 .article-title {
299 font-size: var(--font-heading-lg, 28px);
300 }
301
302 .article-body {
303 font-size: var(--font-body-md, 16px);
304 }
305
306 .article-body h2 {
307 font-size: var(--font-heading-md, 22px);
308 }
309
310 .article-body h3 {
311 font-size: var(--font-heading-sm, 18px);
312 }
313
314 .article-footer {
315 margin-top: 48px;
316 }
317}
318"#;
319
320#[component(lazy)]
321pub fn NewsArticle(slug: String) -> Element {
322 let article = get_article_by_slug(&slug);
323 let (page_title, page_desc) = match article {
324 Some(a) => (format!("{} - LOGICAFFEINE", a.title), a.summary.to_string()),
325 None => (
326 "Article Not Found - LOGICAFFEINE".to_string(),
327 "Latest news and updates from LOGICAFFEINE.".to_string(),
328 ),
329 };
330 let page_path = format!("/news/{}", slug);
331
332 rsx! {
333 PageHead {
334 title: page_title,
335 description: page_desc,
336 canonical_path: page_path,
337 }
338 style { "{ARTICLE_STYLES}" }
339
340 div { class: "article-page",
341 MainNav { active: ActivePage::News, subtitle: Some("Latest updates") }
342
343 if let Some(article) = article {
344 {
345 let breadcrumbs = vec![
346 BreadcrumbItem { name: "Home", path: "/" },
347 BreadcrumbItem { name: "News", path: "/news" },
348 ];
349
350 let schemas = vec![
351 organization_schema(),
352 breadcrumb_schema(&breadcrumbs),
353 article_schema(article.title, article.summary, article.date, article.slug),
354 ];
355
356 {
357 let all_tags = get_all_tags();
358 let current_tags: Vec<&str> = article.tags.iter().copied().collect();
359 rsx! {
360 JsonLdMultiple { schemas }
361
362 main { class: "article-content",
363 Link { to: Route::News { tag: None }, class: "article-back",
364 "← Back to News"
365 }
366
367 article {
368 header { class: "article-header",
369 div { class: "article-meta",
370 span { class: "article-date", "{article.date}" }
371 div { class: "article-tags",
372 for tag in article.tags.iter() {
373 {
374 let tag_display = format_tag(tag);
375 rsx! { span { class: "article-tag", "{tag_display}" } }
376 }
377 }
378 }
379 }
380 h1 { class: "article-title", "{article.title}" }
381 p { class: "article-author", "By {article.author}" }
382 }
383
384 div {
385 class: "article-body",
386 dangerous_inner_html: markdown_to_html(article.content)
387 }
388
389 footer { class: "article-footer",
391 div { class: "article-footer-section",
392 h3 { class: "article-footer-title", "Browse by Topic" }
393 div { class: "article-browse-tags",
394 for tag in all_tags.iter() {
395 {
396 let tag_str = *tag;
397 let tag_display = format_tag(tag_str);
398 let is_current = current_tags.contains(&tag_str);
399 rsx! {
400 Link {
401 to: Route::News { tag: Some(tag_str.to_string()) },
402 class: if is_current { "article-browse-tag current" } else { "article-browse-tag" },
403 "{tag_display}"
404 }
405 }
406 }
407 }
408 }
409 }
410 }
411 }
412 }
413 }
414 }
415 }
416 } else {
417 main { class: "article-content",
418 div { class: "article-not-found",
419 h1 { "Article Not Found" }
420 p { "The article you're looking for doesn't exist." }
421 Link { to: Route::News { tag: None }, "Back to News" }
422 }
423 }
424 }
425
426 Footer {}
427 }
428 }
429}
430
431fn markdown_to_html(markdown: &str) -> String {
434 blocks(markdown).iter().map(block_html).collect()
435}
436
437fn block_html(block: &Block) -> String {
438 match block {
439 Block::Heading { level, text } => {
440 format!("<h{level}>{}</h{level}>\n", inline_markup_html(text))
441 }
442 Block::Paragraph(text) => format!("<p>{}</p>\n", inline_markup_html(text)),
443 Block::List { ordered, items } => {
444 let tag = if *ordered { "ol" } else { "ul" };
445 let items: String = items
446 .iter()
447 .map(|item| format!("<li>{}</li>\n", inline_markup_html(item)))
448 .collect();
449 format!("<{tag}>\n{items}</{tag}>\n")
450 }
451 Block::Quote(paragraphs) => {
452 let body: Vec<String> = paragraphs.iter().map(|p| inline_markup_html(p)).collect();
453 format!("<blockquote>{}</blockquote>\n", body.join("<br/><br/>"))
454 }
455 Block::Table { header, rows } => {
456 let row = |cells: &[String], tag: &str| -> String {
457 let cells: String = cells
458 .iter()
459 .map(|cell| format!("<{tag}>{}</{tag}>", inline_markup_html(cell)))
460 .collect();
461 format!("<tr>{cells}</tr>")
462 };
463 let head = header.as_ref().map_or(String::new(), |h| {
464 format!("<thead>{}</thead>", row(h, "th"))
465 });
466 let body: String = rows.iter().map(|r| row(r, "td")).collect();
467 format!(
468 "<div class=\"article-table\"><table>{head}<tbody>{body}</tbody></table></div>\n"
469 )
470 }
471 Block::Fence { code, .. } => format!("<pre><code>{}</code></pre>\n", html_escape(code)),
472 Block::Rule => "<hr/>\n".to_string(),
473 }
474}
475
476fn html_escape(text: &str) -> String {
478 text.replace('&', "&")
479 .replace('<', "<")
480 .replace('>', ">")
481}
482
483#[cfg(test)]
484#[path = "../../../../../../crates/logicaffeine_tests/unit/logicaffeine_web/ui/pages/news/article/tests.rs"]
485mod tests;