generated from Astrial.org/template
Compare commits
No commits in common. "7241a1e8cd44744bbdb3b669d39e27b81d7c2ae2" and "b74c71f39b789322a80a4ced157f9c93205e6c52" have entirely different histories.
7241a1e8cd
...
b74c71f39b
4 changed files with 0 additions and 83 deletions
|
@ -12,7 +12,6 @@ diaryrs
|
||||||
deserialised
|
deserialised
|
||||||
indoc
|
indoc
|
||||||
mgmt
|
mgmt
|
||||||
serde
|
|
||||||
|
|
||||||
# Diary Entries
|
# Diary Entries
|
||||||
Shunde
|
Shunde
|
||||||
|
|
32
Cargo.lock
generated
32
Cargo.lock
generated
|
@ -200,7 +200,6 @@ dependencies = [
|
||||||
"indoc",
|
"indoc",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_yaml",
|
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -267,12 +266,6 @@ version = "1.70.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itoa"
|
|
||||||
version = "1.0.14"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.76"
|
version = "0.3.76"
|
||||||
|
@ -425,12 +418,6 @@ version = "0.8.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ryu"
|
|
||||||
version = "1.0.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.216"
|
version = "1.0.216"
|
||||||
|
@ -460,19 +447,6 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "serde_yaml"
|
|
||||||
version = "0.9.34+deprecated"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
|
|
||||||
dependencies = [
|
|
||||||
"indexmap",
|
|
||||||
"itoa",
|
|
||||||
"ryu",
|
|
||||||
"serde",
|
|
||||||
"unsafe-libyaml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "1.3.0"
|
version = "1.3.0"
|
||||||
|
@ -542,12 +516,6 @@ version = "1.0.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unsafe-libyaml"
|
|
||||||
version = "0.2.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
|
|
|
@ -11,5 +11,4 @@ iana-time-zone = "0.1.61"
|
||||||
indoc = "2.0.5"
|
indoc = "2.0.5"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
serde = { version = "1.0.216", features = ["derive"] }
|
serde = { version = "1.0.216", features = ["derive"] }
|
||||||
serde_yaml = { version = "0.9.34" }
|
|
||||||
toml = "0.8.19"
|
toml = "0.8.19"
|
||||||
|
|
49
src/mgmt.rs
49
src/mgmt.rs
|
@ -1,4 +1,3 @@
|
||||||
use chrono::TimeZone;
|
|
||||||
use diaryrs::macros::UnwrapOrFatalAble;
|
use diaryrs::macros::UnwrapOrFatalAble;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
|
@ -25,31 +24,6 @@ pub struct Inventory {
|
||||||
pub avg_word_count: f64,
|
pub avg_word_count: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a single diary entry (markdown file) and its associated stats/metadata
|
|
||||||
///
|
|
||||||
/// Does not include the actual contents of the entry, only stats
|
|
||||||
///
|
|
||||||
/// The timezone of the entry is determined by the `Tz` type parameter
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct Entry<Tz: TimeZone> {
|
|
||||||
pub path: path::PathBuf,
|
|
||||||
|
|
||||||
pub word_count: u64,
|
|
||||||
pub timestamp: chrono::DateTime<Tz>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<Tz: TimeZone> Entry<Tz> {
|
|
||||||
//
|
|
||||||
pub fn read(path: path::PathBuf) -> Result<Self, Box<dyn std::error::Error>> {
|
|
||||||
let contents = fs::read_to_string(&path)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
|
||||||
path,
|
|
||||||
word_count: count_words(&contents),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Inventory {
|
impl Inventory {
|
||||||
/// Take inventory of the diary entries
|
/// Take inventory of the diary entries
|
||||||
///
|
///
|
||||||
|
@ -139,26 +113,3 @@ fn word_count_mds(paths: &Vec<path::PathBuf>) -> Result<u64, Box<dyn std::error:
|
||||||
|
|
||||||
Ok(word_count as u64)
|
Ok(word_count as u64)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn count_words(contents: &str) -> u64 {
|
|
||||||
let re_titles = Regex::new(r"(?m)^#{1,6} .+")
|
|
||||||
.unwrap_or_fatal("Failed to compile title regex. Something is very wrong!");
|
|
||||||
let re_comments = Regex::new(r"(?s-m)<!---?.+-->")
|
|
||||||
.unwrap_or_fatal("Failed to compile comment regex. Something is very wrong!");
|
|
||||||
let re_images = Regex::new(r"!\[.*\]\(.+\)")
|
|
||||||
.unwrap_or_fatal("Failed to compile image regex. Something is very wrong!");
|
|
||||||
|
|
||||||
// Cut YAML header, comments and images
|
|
||||||
let contents = &re_titles.replace_all(
|
|
||||||
contents
|
|
||||||
.split("---")
|
|
||||||
.collect::<Vec<&str>>()
|
|
||||||
.pop()
|
|
||||||
.ok_or("No content found")?,
|
|
||||||
"",
|
|
||||||
);
|
|
||||||
let contents = &re_comments.replace_all(contents, "");
|
|
||||||
let contents = &re_images.replace_all(contents, "");
|
|
||||||
|
|
||||||
contents.split_whitespace().count() as u64
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue