Styling for articles
This commit is contained in:
1 parent
824e6a5d72
commit
1d67f611fc
4 files changed
+105
-18
No files matched your search
@@ -54,12 +54,18 @@ impl CodeBlockRenderer {
|
||||
|
||||
let html_out = html_gen.finalize();
|
||||
|
||||
//TODO: show context & language
|
||||
|
||||
html! {
|
||||
pre .codeblock {
|
||||
code {
|
||||
(PreEscaped(html_out))
|
||||
.codeblock {
|
||||
@if context.is_some() || !lang.is_empty() {
|
||||
.codeblock_banner {
|
||||
span .codeblock_language { (lang) }
|
||||
span .codeblock_context { (context.unwrap_or("")) }
|
||||
}
|
||||
}
|
||||
pre .codeblock_code {
|
||||
code {
|
||||
(PreEscaped(html_out))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
-1
@@ -2,7 +2,7 @@ use std::{borrow, error, fmt, ops};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use libshire::{strings::ShString22, uuid::{Uuid, UuidV5Error}};
|
||||
use maud::{Markup, PreEscaped};
|
||||
use maud::{Markup, PreEscaped, html};
|
||||
|
||||
use crate::codeblock::CodeBlockRenderer;
|
||||
|
||||
@@ -76,6 +76,7 @@ pub struct Post {
|
||||
uuid: Uuid,
|
||||
id: PostId,
|
||||
title: String,
|
||||
subtitle: Option<String>,
|
||||
author: String,
|
||||
html: Markup,
|
||||
tags: Vec<ShString22>,
|
||||
@@ -96,6 +97,10 @@ impl Post {
|
||||
&self.title
|
||||
}
|
||||
|
||||
pub fn subtitle(&self) -> Option<&str> {
|
||||
self.subtitle.as_deref()
|
||||
}
|
||||
|
||||
pub fn author(&self) -> &str {
|
||||
&self.author
|
||||
}
|
||||
@@ -169,6 +174,7 @@ impl Post {
|
||||
uuid,
|
||||
id,
|
||||
title: mdpost.title,
|
||||
subtitle: mdpost.subtitle,
|
||||
author: mdpost.author,
|
||||
html: PreEscaped(html_buf),
|
||||
tags: mdpost.tags,
|
||||
@@ -226,6 +232,12 @@ impl<'e, 'p, I> Iterator for PostMdParser<'p, I> where I: Iterator<Item = pulldo
|
||||
Event::Html(CowStr::Boxed(highlighted.into_string().into_boxed_str()))
|
||||
},
|
||||
|
||||
Event::Code(code) => {
|
||||
Event::Html(CowStr::Boxed(html! {
|
||||
code .inline_code { (code) }
|
||||
}.into_string().into_boxed_str()))
|
||||
},
|
||||
|
||||
event => {
|
||||
match &event {
|
||||
Event::Start(Tag::Link(LinkType::Inline | LinkType::Autolink, destination, _title)) => {
|
||||
@@ -253,6 +265,8 @@ struct HeaderNode {
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
title: String,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
subtitle: Option<String>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
author: String,
|
||||
#[knuffel(children(name="tag"))]
|
||||
tags: Vec<TagNode>,
|
||||
@@ -268,6 +282,7 @@ struct TagNode {
|
||||
struct MdPost {
|
||||
markdown: String,
|
||||
title: String,
|
||||
subtitle: Option<String>,
|
||||
author: String,
|
||||
tags: Vec<ShString22>,
|
||||
}
|
||||
@@ -287,6 +302,7 @@ impl MdPost {
|
||||
Ok(Self {
|
||||
markdown: md.to_owned(),
|
||||
title: header.title,
|
||||
subtitle: header.subtitle,
|
||||
author: header.author,
|
||||
tags: header.tags.into_iter().map(|tag| tag.tag.into()).collect(),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
use axum::extract::{Extension, Path};
|
||||
use maud::html;
|
||||
|
||||
use crate::posts_store::ConcurrentPostsStore;
|
||||
use crate::{
|
||||
posts_store::ConcurrentPostsStore,
|
||||
template,
|
||||
};
|
||||
use super::response::{Error, Html};
|
||||
|
||||
pub async fn handle(
|
||||
@@ -17,13 +20,19 @@ pub async fn handle(
|
||||
.with_crawler_permissive()
|
||||
.with_title_owned(post.title().to_owned())
|
||||
.with_head(html! {
|
||||
link href="/static/styles/main.css" rel="stylesheet";
|
||||
link href="/static/styles/code.css" rel="stylesheet";
|
||||
})
|
||||
.with_body(html! {
|
||||
h1 { (post.title()) }
|
||||
p { "by " (post.author()) }
|
||||
article {
|
||||
.with_body(template::main_page(html! {
|
||||
section .article_header {
|
||||
h1 .article_title { (post.title()) }
|
||||
@if let Some(subtitle) = post.subtitle() {
|
||||
p .article_subtitle { (subtitle) }
|
||||
}
|
||||
p .article_published_date { "Published " (post.created().format("%Y/%m/%d")) }
|
||||
}
|
||||
article .article_content {
|
||||
(post.html())
|
||||
}
|
||||
}))
|
||||
})))
|
||||
}
|
||||
Reference in new issue
Block a user