working betterer
Some checks failed
/ clippy (push) Failing after 1m54s
/ test (push) Failing after 1m55s

This commit is contained in:
Chris Cochrun 2026-03-31 10:54:46 -05:00
parent 9c3f35dda0
commit 38767b0f16
5 changed files with 93 additions and 64 deletions

22
Cargo.lock generated
View file

@ -840,9 +840,9 @@ checksum = "47f142fe24a9c9944451e8349de0a56af5f3e7226dc46f3ed4d4ecc0b85af75e"
[[package]]
name = "js-sys"
version = "0.3.92"
version = "0.3.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4c90f45aa2e6eacbe8645f77fdea542ac97a494bcd117a67df9ff4d611f995"
checksum = "797146bb2677299a1eb6b7b50a890f4c361b29ef967addf5b2fa45dae1bb6d7d"
dependencies = [
"once_cell",
"wasm-bindgen",
@ -1176,7 +1176,7 @@ dependencies = [
[[package]]
name = "orgize"
version = "0.10.0-alpha.10"
source = "git+https://github.com/PoiScript/orgize.git?branch=v0.10#5f26c94dcec2a33b37b1c880ace053b29b5d021e"
source = "git+https://git.tfcconnection.org/chris/orgize?branch=v0.11#8f6969ea1ee4e7c66dcb09a9ce89935832c3b68f"
dependencies = [
"bytecount",
"cfg-if",
@ -2002,9 +2002,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.115"
version = "0.2.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6523d69017b7633e396a89c5efab138161ed5aafcbc8d3e5c5a42ae38f50495a"
checksum = "7dc0882f7b5bb01ae8c5215a1230832694481c1a4be062fd410e12ea3da5b631"
dependencies = [
"cfg-if",
"once_cell",
@ -2015,9 +2015,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.115"
version = "0.2.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e3a6c758eb2f701ed3d052ff5737f5bfe6614326ea7f3bbac7156192dc32e67"
checksum = "75973d3066e01d035dbedaad2864c398df42f8dd7b1ea057c35b8407c015b537"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2025,9 +2025,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.115"
version = "0.2.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "921de2737904886b52bcbb237301552d05969a6f9c40d261eb0533c8b055fedf"
checksum = "91af5e4be765819e0bcfee7322c14374dc821e35e72fa663a830bbc7dc199eac"
dependencies = [
"bumpalo",
"proc-macro2",
@ -2038,9 +2038,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.115"
version = "0.2.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a93e946af942b58934c604527337bad9ae33ba1d5c6900bbb41c2c07c2364a93"
checksum = "c9bf0406a78f02f336bf1e451799cca198e8acde4ffa278f0fb20487b150a633"
dependencies = [
"unicode-ident",
]

View file

@ -11,7 +11,7 @@ serde = { version = "1.0.213", features = ["derive"] }
tracing = "0.1.40"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "std", "chrono", "time", "local-time", "env-filter"] }
orgize = { git="https://github.com/PoiScript/orgize.git", branch = "v0.10", features = ["chrono", "indexmap", "tracing"] }
orgize = { git="https://git.tfcconnection.org/chris/orgize", branch = "v0.11", features = ["chrono", "indexmap", "tracing"] }
steel-core = { git="https://github.com/mattwparas/steel.git", branch = "master" }
chrono = "0.4.44"
notify = "8.2.0"

View file

@ -1,5 +1,3 @@
use orgize::ast::Token;
use rowan::NodeOrToken;
use slugify::slugify;
use std::cmp::min;
use std::fmt;
@ -94,8 +92,8 @@ impl OrgHtmlExporter {
impl Traverser for OrgHtmlExporter {
fn event(&mut self, event: Event, ctx: &mut TraversalContext) {
match event {
Event::Enter(Container::Document(_)) => self.output += "<main>",
Event::Leave(Container::Document(_)) => self.output += "</main>",
Event::Enter(Container::Document(_)) => self.output += "<main>\n",
Event::Leave(Container::Document(_)) => self.output += "</main>\n",
Event::Enter(Container::Headline(headline)) => {
let level = min(headline.level() + 1, 6);
@ -114,11 +112,11 @@ impl Traverser for OrgHtmlExporter {
}
Event::Leave(Container::Headline(_)) => {}
Event::Enter(Container::Paragraph(_)) => self.output += "<p>",
Event::Leave(Container::Paragraph(_)) => self.output += "</p>",
Event::Enter(Container::Paragraph(_)) => self.output += "<p>\n",
Event::Leave(Container::Paragraph(_)) => self.output += "</p>\n",
Event::Enter(Container::Section(_)) => self.output += "<section>",
Event::Leave(Container::Section(_)) => self.output += "</section>",
Event::Enter(Container::Section(_)) => self.output += "<section>\n",
Event::Leave(Container::Section(_)) => self.output += "</section>\n",
Event::Enter(Container::Italic(_)) => self.output += "<i>",
Event::Leave(Container::Italic(_)) => self.output += "</i>",
@ -151,8 +149,8 @@ impl Traverser for OrgHtmlExporter {
}
Event::Leave(Container::SourceBlock(_)) => self.output += "</code></pre>",
Event::Enter(Container::QuoteBlock(_)) => self.output += "<blockquote>",
Event::Leave(Container::QuoteBlock(_)) => self.output += "</blockquote>",
Event::Enter(Container::QuoteBlock(_)) => self.output += "<blockquote>\n",
Event::Leave(Container::QuoteBlock(_)) => self.output += "</blockquote>\n",
Event::Enter(Container::VerseBlock(_)) => self.output += "<p class=\"verse\">",
Event::Leave(Container::VerseBlock(_)) => self.output += "</p>",
@ -178,41 +176,41 @@ impl Traverser for OrgHtmlExporter {
Event::Enter(Container::List(list)) => {
self.output += if list.is_ordered() {
self.in_descriptive_list.push(false);
"<ol>"
"<ol>\n"
} else if list.is_descriptive() {
self.in_descriptive_list.push(true);
"<dl>"
"<dl>\n"
} else {
self.in_descriptive_list.push(false);
"<ul>"
"<ul>\n"
};
}
Event::Leave(Container::List(list)) => {
self.output += if list.is_ordered() {
"</ol>"
"</ol>\n"
} else if let Some(true) = self.in_descriptive_list.last() {
"</dl>"
"</dl>\n"
} else {
"</ul>"
"</ul>\n"
};
self.in_descriptive_list.pop();
}
Event::Enter(Container::ListItem(list_item)) => {
if let Some(&true) = self.in_descriptive_list.last() {
self.output += "<dt>";
self.output += "<dt>\n";
for elem in list_item.tag() {
self.element(elem, ctx);
}
self.output += "</dt><dd>";
self.output += "</dt><dd>\n";
} else {
self.output += "<li>";
self.output += "<li>\n";
}
}
Event::Leave(Container::ListItem(_)) => {
if let Some(&true) = self.in_descriptive_list.last() {
self.output += "</dd>";
self.output += "</dd>\n";
} else {
self.output += "</li>";
self.output += "</li>\n";
}
}
@ -285,6 +283,13 @@ impl Traverser for OrgHtmlExporter {
Event::Enter(Container::Link(link)) => {
let path = link.path();
let path = path.trim_start_matches("file:");
let path = if let Some(path) = path.strip_suffix("org") {
let mut path = path.to_string();
path.push_str("html");
path
} else {
path.to_string()
};
if link.is_image() {
let _ = write!(&mut self.output, r#"<img src="{}">"#, HtmlEscape(&path));
@ -301,7 +306,23 @@ impl Traverser for OrgHtmlExporter {
Event::Leave(Container::Link(_)) => self.output += "</a>",
Event::Text(text) => {
let _ = write!(&mut self.output, "{}", HtmlEscape(text));
if text
.syntax()
.parent()
.is_some_and(|parent| match parent.kind() {
SyntaxKind::KEYWORD
| SyntaxKind::DYN_BLOCK
| SyntaxKind::DRAWER
| SyntaxKind::DRAWER_END
| SyntaxKind::BLOCK_END
| SyntaxKind::DYN_BLOCK_END => true,
_ => false,
})
{
()
} else {
let _ = write!(&mut self.output, "{}", HtmlEscape(text));
}
}
Event::LineBreak(_) => self.output += "<br/>",
@ -315,19 +336,11 @@ impl Traverser for OrgHtmlExporter {
Event::Rule(_) => self.output += "<hr/>",
Event::Timestamp(timestamp) => {
self.output += r#"<span class="timestamp-wrapper"><span class="timestamp">"#;
// for e in timestamp.syntax.children_with_tokens() {
// match e {
// NodeOrToken::Token(t) if t.kind() == SyntaxKind::MINUS2 => {
// self.output += "&#x2013;";
// }
// NodeOrToken::Token(t) => {
// self.output += t.text();
// }
// _ => {}
// }
// }
self.output += r#"</span></span>"#;
if let Some(datetime) = timestamp.start_to_chrono() {
self.output += r#"<span class="timestamp-wrapper"><span class="timestamp">"#;
self.output += &datetime.to_string();
self.output += r#"</span></span>"#;
}
}
Event::LatexFragment(latex) => {
@ -340,12 +353,18 @@ impl Traverser for OrgHtmlExporter {
Event::Enter(Container::Keyword(keyword)) => {
if keyword.key().to_uppercase() == "TITLE" {
self.output += r#"<h1 class="title">"#;
self.output += &keyword.value();
self.output += &keyword.value().trim();
self.output += r#"</h1>"#;
}
}
Event::Entity(entity) => self.output += entity.html(),
Event::Leave(Container::Keyword(keyword)) => {
// idk
}
Event::Entity(entity) => {
self.output += entity.html();
}
_ => {}
}

View file

@ -126,27 +126,35 @@ fn build_html(inner_html: String, keywords: HashMap<String, String>) -> String {
.to_string();
let time_comment = format!("<!-- {} -->", build_time);
let doctype_html = "<!DOCTYPE html>
<html lang=\"en\">";
<html lang=\"en\">\n";
let charset = r#"<meta charset="utf-8" />"#;
let style = r#"<link rel="stylesheet" href="./static/pico.snazzy.css" type="text/css"/>"#;
let style = r#"<link rel="stylesheet" href="/static/pico.snazzy.css" type="text/css"/>"#;
let viewport = r#"<meta name="viewport" content="width=device-width, initial-scale=1" />"#;
let generator = r#"<meta name="generator" content="Organic" />"#;
let mut head = format!("{}\n<head>", doctype_html);
let mut head = format!("{}<head>\n", doctype_html);
head.push_str(&time_comment);
head.push_str("\n");
head.push_str(&charset);
head.push_str("\n");
head.push_str(&viewport);
head.push_str("\n");
head.push_str(&title);
head.push_str("\n");
head.push_str(&description);
head.push_str("\n");
head.push_str(&generator);
head.push_str("\n");
head.push_str(&author);
head.push_str("\n");
head.push_str(&style);
head.push_str("</head>");
head.push_str("\n");
head.push_str("</head>\n");
let other_style = r#"<style>
li:nth-child(n+7) {
display: none;
}
</style>"#;
format!("{}\n<body>\n{}\n</body></html>", head, inner_html)
format!("{head}<body>\n{inner_html}\n</body></html>")
}
fn extract_keywords<I>(keywords: &mut I) -> HashMap<String, String>

View file

@ -6,22 +6,24 @@ use tracing::{debug, info};
use crate::publish::publish::{Error, build_site};
pub fn watch(event: Event, path: impl AsRef<Path>) -> Result<(), Error> {
if event
if !event
.paths
.clone()
.into_iter()
.filter(|e| {
if let Some(base_name) = e.file_name() {
let name = base_name.to_os_string().into_string().unwrap_or("".into());
// Let's filter out emacs changes and lockfiles
!(name.starts_with(".#") | name.ends_with("~"))
} else {
false
}
e.strip_prefix(&path).is_ok_and(|inner_path| {
if inner_path.starts_with("public") {
false
} else {
e.file_name().is_some_and(|base_name| {
let name = base_name.to_os_string().into_string().unwrap_or("".into());
!(name.starts_with(".#") | name.ends_with("~"))
})
}
})
})
.collect::<Vec<PathBuf>>()
.len()
> 0
.is_empty()
{
match event.kind {
EventKind::Create(_) | EventKind::Modify(_) | EventKind::Remove(_) => {