diff options
author | metamuffin <metamuffin@disroot.org> | 2022-08-30 00:03:37 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-08-30 00:03:37 +0200 |
commit | 525baabe876c047a7367dae1f954148a52f190bc (patch) | |
tree | 005981e4773197075a17cfc1729c08284492f0a2 | |
parent | 9fba4dc45d7319d03584fe10ead95d0ff7974234 (diff) | |
download | metamuffin-blog-525baabe876c047a7367dae1f954148a52f190bc.tar metamuffin-blog-525baabe876c047a7367dae1f954148a52f190bc.tar.bz2 metamuffin-blog-525baabe876c047a7367dae1f954148a52f190bc.tar.zst |
code block formatting
-rw-r--r-- | code/src/html.rs | 15 | ||||
-rw-r--r-- | code/src/main.rs | 15 | ||||
-rw-r--r-- | code/src/markdown.rs | 2 |
3 files changed, 24 insertions, 8 deletions
diff --git a/code/src/html.rs b/code/src/html.rs index 64b4c6d..e53502f 100644 --- a/code/src/html.rs +++ b/code/src/html.rs @@ -1,5 +1,5 @@ -use crate::{article_metadata, get_articles, markdown::blocks_to_html, ArticleMeta}; -use laby::{html, iter, li, ul, Render}; +use crate::{article_metadata, file_history, get_articles, markdown::blocks_to_html, ArticleMeta}; +use laby::{frag, html, iter, li, ul, Render}; use std::fs::read_to_string; pub fn scaffold(title: String, body: impl Render) -> impl Render { @@ -24,9 +24,14 @@ pub fn scaffold(title: String, body: impl Render) -> impl Render { pub fn article(path: String) -> impl Render { scaffold( article_metadata(path.clone().into()).title, - laby::raw!(blocks_to_html(markdown::tokenize( - &read_to_string(path).unwrap() - ))), + frag!( + laby::raw!(blocks_to_html(markdown::tokenize( + &read_to_string(&path).unwrap() + ))), + hr!(), + p!("changes to this article (as recorded with git; visible on the git repo, that i will create soon)"), + pre!(file_history(&path)) + ), ) } diff --git a/code/src/main.rs b/code/src/main.rs index 83bcefe..0bd0169 100644 --- a/code/src/main.rs +++ b/code/src/main.rs @@ -10,6 +10,7 @@ use std::{ fs::File, io::{BufRead, BufReader, Write}, path::PathBuf, + process::{Command, Stdio}, }; pub const BLOG_BASE: &'static str = "s.metamuffin.org/temp/blog-preview"; @@ -72,11 +73,22 @@ pub fn get_articles(root: &str) -> Vec<ArticleMeta> { a } +pub fn file_history(filename: &str) -> String { + String::from_utf8( + Command::new("/usr/bin/git") + .args(&["log", "--follow", "--pretty=tformat:%as %h %s", filename]) + .stdout(Stdio::piped()) + .output() + .unwrap() + .stdout, + ) + .unwrap() +} + pub struct ArticleMeta { title: String, canonical_name: String, date: iso8601::Date, - path: PathBuf, } fn article_metadata(path: PathBuf) -> ArticleMeta { let f = File::open(&path).unwrap(); @@ -87,6 +99,5 @@ fn article_metadata(path: PathBuf) -> ArticleMeta { title: String::from(buf[2..].trim()), canonical_name: path.file_stem().unwrap().to_str().unwrap().to_string(), date: iso8601::date(&path.file_name().unwrap().to_str().unwrap()[0..10]).unwrap(), - path, } } diff --git a/code/src/markdown.rs b/code/src/markdown.rs index c194a07..5d98f83 100644 --- a/code/src/markdown.rs +++ b/code/src/markdown.rs @@ -29,7 +29,7 @@ pub fn blocks_to_html(blocks: Vec<Block>) -> String { Block::Paragraph(p) => format!("<p>{}</p>", span_to_html(p)), Block::Blockquote(q) => format!("<quote>{}</quote>", blocks_to_html(q)), Block::CodeBlock(_syntax, content) => { - format!("<code><pre>{}</pre></code>", escape(&content)) // TODO syntax highlighting + format!("<pre>{}</pre>", escape(&content)) // TODO syntax highlighting } Block::OrderedList(els, _) => format!( "<ol>{}</ol>", |