The (very WIP) home of the next versions of my web presences

build: include approx. length in social info

Use count-md, because I can!

+120 -15
+60 -2
lx/Cargo.lock
··· 451 451 checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" 452 452 453 453 [[package]] 454 + name = "count-md" 455 + version = "0.1.0" 456 + source = "registry+https://github.com/rust-lang/crates.io-index" 457 + checksum = "a83ca1be73e50a49521ae1c1f1a7c588b1a03c499649d01846b3bc2631f8418e" 458 + dependencies = [ 459 + "bitflags 2.6.0", 460 + "clap", 461 + "clap_complete", 462 + "notify 6.1.1", 463 + "pulldown-cmark 0.10.3", 464 + "rayon", 465 + "thiserror 1.0.69", 466 + "unicode-segmentation", 467 + "xmlparser", 468 + ] 469 + 470 + [[package]] 454 471 name = "cpufeatures" 455 472 version = "0.2.14" 456 473 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 868 885 ] 869 886 870 887 [[package]] 888 + name = "getopts" 889 + version = "0.2.21" 890 + source = "registry+https://github.com/rust-lang/crates.io-index" 891 + checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" 892 + dependencies = [ 893 + "unicode-width 0.1.14", 894 + ] 895 + 896 + [[package]] 871 897 name = "getrandom" 872 898 version = "0.2.15" 873 899 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1532 1558 "chrono", 1533 1559 "clap", 1534 1560 "clap_complete", 1561 + "count-md", 1535 1562 "dirs", 1536 1563 "futures", 1537 1564 "glob", ··· 1572 1599 "latex2mathml", 1573 1600 "lazy_static", 1574 1601 "log", 1575 - "pulldown-cmark", 1602 + "pulldown-cmark 0.12.2", 1576 1603 "serde", 1577 1604 "serde_yaml", 1578 1605 "simplelog", ··· 1973 2000 1974 2001 [[package]] 1975 2002 name = "pulldown-cmark" 2003 + version = "0.10.3" 2004 + source = "registry+https://github.com/rust-lang/crates.io-index" 2005 + checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" 2006 + dependencies = [ 2007 + "bitflags 2.6.0", 2008 + "getopts", 2009 + "memchr", 2010 + "pulldown-cmark-escape 0.10.1", 2011 + "unicase", 2012 + ] 2013 + 2014 + [[package]] 2015 + name = "pulldown-cmark" 1976 2016 version = "0.12.2" 1977 2017 source = "registry+https://github.com/rust-lang/crates.io-index" 1978 2018 checksum = "f86ba2052aebccc42cbbb3ed234b8b13ce76f75c3551a303cb2bcffcff12bb14" 1979 2019 dependencies = [ 1980 2020 "bitflags 2.6.0", 1981 2021 "memchr", 1982 - "pulldown-cmark-escape", 2022 + "pulldown-cmark-escape 0.11.0", 1983 2023 "unicase", 1984 2024 ] 2025 + 2026 + [[package]] 2027 + name = "pulldown-cmark-escape" 2028 + version = "0.10.1" 2029 + source = "registry+https://github.com/rust-lang/crates.io-index" 2030 + checksum = "bd348ff538bc9caeda7ee8cad2d1d48236a1f443c1fa3913c6a02fe0043b1dd3" 1985 2031 1986 2032 [[package]] 1987 2033 name = "pulldown-cmark-escape" ··· 2704 2750 ] 2705 2751 2706 2752 [[package]] 2753 + name = "unicode-segmentation" 2754 + version = "1.12.0" 2755 + source = "registry+https://github.com/rust-lang/crates.io-index" 2756 + checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" 2757 + 2758 + [[package]] 2707 2759 name = "unicode-width" 2708 2760 version = "0.1.14" 2709 2761 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 3079 3131 dependencies = [ 3080 3132 "memchr", 3081 3133 ] 3134 + 3135 + [[package]] 3136 + name = "xmlparser" 3137 + version = "0.13.6" 3138 + source = "registry+https://github.com/rust-lang/crates.io-index" 3139 + checksum = "66fee0b777b0f5ac1c69bb06d361268faafa61cd4682ae064a171c16c433e9e4" 3082 3140 3083 3141 [[package]] 3084 3142 name = "yaml-rust"
+9 -7
lx/Cargo.toml
··· 14 14 anyhow = { workspace = true } 15 15 atom_syndication = { version = "0.12", features = ["with-serde"] } 16 16 axum = { version = "0.7.4", default-features = true, features = [ 17 - "http2", 18 - "ws", 17 + "http2", 18 + "ws", 19 19 ] } 20 20 chrono = { version = "0.4", features = ["serde"] } 21 21 clap = { workspace = true } 22 22 clap_complete = { workspace = true } 23 + count-md = { workspace = true } 23 24 dirs = { workspace = true } 24 25 futures = { version = "0.3", default-features = false, features = [ 25 - "alloc", 26 - "std", 27 - "async-await", 26 + "alloc", 27 + "std", 28 + "async-await", 28 29 ] } 29 30 glob = "0.3" 30 31 grass = "0.13.2" ··· 35 36 minijinja = { version = "2", features = ["loader", "macros"] } 36 37 normalize-path = "0.2" 37 38 notify = { version = "7", default-features = false, features = [ 38 - "macos_kqueue", 39 + "macos_kqueue", 39 40 ] } 40 41 notify-debouncer-full = { version = "0.4", default-features = false } 41 42 rayon = { workspace = true } ··· 79 80 anyhow = "1" 80 81 clap = { version = "4", features = ["unicode", "cargo", "derive"] } 81 82 clap_complete = "4" 83 + count-md = "0.1" 82 84 dirs = "5" 83 85 lazy_static = "1.4" 84 86 log = "0.4.20" ··· 88 90 serde_yaml = "0.9" 89 91 simplelog = { version = "0.12", features = ["paris"] } 90 92 syntect = { version = "5", default-features = false, features = [ 91 - "default-fancy", 93 + "default-fancy", 92 94 ] } 93 95 thiserror = "2" 94 96
+2 -2
lx/crates/markdown/Cargo.toml
··· 20 20 latex2mathml = "0.2" 21 21 lazy_static = { workspace = true } 22 22 pulldown-cmark = { version = "0.12", default-features = false, features = [ 23 - "simd", 24 - "html", 23 + "simd", 24 + "html", 25 25 ] } 26 26 simplelog = { workspace = true } 27 27 syntect = { workspace = true }
+1 -1
lx/src/page.rs
··· 72 72 } 73 73 74 74 /// Source data for a file: where it came from, and its original contents. 75 - #[derive(Clone, Debug, Deserialize)] 75 + #[derive(Clone, Debug, Serialize, Deserialize)] 76 76 pub struct Source { 77 77 /// Original source location for the file. 78 78 pub path: PathBuf,
+37
lx/src/templates/functions.rs
··· 9 9 }; 10 10 11 11 pub(crate) fn add_all(env: &mut minijinja::Environment<'_>) { 12 + env.add_function("approximate_length", approximate_length); 12 13 env.add_function("resolved_title", resolved_title); 13 14 env.add_function("resolved_image", resolved_image); 14 15 env.add_function("description", description); ··· 88 89 89 90 format!("{title}<pre><code>{args}</code></pre>") 90 91 } 92 + 93 + fn approximate_length(source: &str) -> String { 94 + let actual = count_md::count(source); 95 + 96 + let rounded = if actual < 100 { 97 + (actual / 10) * 10 98 + } else if actual < 1_000 { 99 + (actual / 50) * 50 100 + } else { 101 + (actual / 100) * 100 102 + }; 103 + 104 + let formatted = { 105 + let formatted_number = rounded.to_string(); 106 + if formatted_number.len() <= 3 { 107 + formatted_number 108 + } else { 109 + formatted_number 110 + .chars() 111 + .rev() 112 + .enumerate() 113 + .fold(String::new(), |mut s, (idx, c)| { 114 + if idx > 0 && idx % 3 == 0 { 115 + s.push(','); 116 + } 117 + s.push(c); 118 + s 119 + }) 120 + .chars() 121 + .rev() 122 + .collect() 123 + } 124 + }; 125 + 126 + format!("About {formatted} words") 127 + }
+3 -1
lx/src/templates/mod.rs
··· 13 13 14 14 use crate::{ 15 15 data::{config::Config, item::Metadata}, 16 - page::{Page, RootedPath}, 16 + page::{Page, RootedPath, Source}, 17 17 }; 18 18 19 19 #[derive(Error, Debug)] ··· 86 86 data: &'a Metadata, 87 87 config: &'a Config, 88 88 path: &'a RootedPath, 89 + source: &'a Source, 89 90 } 90 91 91 92 debug!( ··· 108 109 data: &page.data, 109 110 config: site, 110 111 path: &page.path, 112 + source: &page.source, 111 113 }, 112 114 into, 113 115 )
+7 -1
sites/_shared/_ui/head.jinja
··· 1 - {% macro head(content, data, config) %} 1 + {% macro head(content, data, source, config) %} 2 2 3 3 {% set image = resolved_image(data.image, config.image) %} 4 4 {% set desc = description(data, content) %} ··· 36 36 <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#005fb2" /> 37 37 <meta name="msapplication-TileColor" content="#afc7de" /> 38 38 <meta name="theme-color" content="#314557" /> 39 + 40 + <meta name="twitter:label1" content="Author" /> 41 + <meta name="twitter:data1" content="Chris Krycho" /> 42 + 43 + <meta name="twitter:label2" content="Length" /> 44 + <meta name="twitter:data2" content="{{ approximate_length(source.contents) }}" /> 39 45 40 46 <script defer src="/vendor/lite-yt-embed.js"></script> 41 47 </head>
+1 -1
sites/music/_ui/base.jinja
··· 2 2 3 3 <!doctype html> 4 4 <html lang="en"> 5 - {{ head(content, data, config) }} 5 + {{ head(content, data, source, config) }} 6 6 7 7 <body> 8 8 <div class="container">