Remove duplicate code
This commit is contained in:
parent
9ab1bf2e4e
commit
c14b1fa746
|
@ -13,6 +13,7 @@ also specify classes on headers now
|
||||||
- Make `ignored_content` work with nested paths and directories
|
- Make `ignored_content` work with nested paths and directories
|
||||||
- `zola serve/build` can now run from anywhere in a zola directory
|
- `zola serve/build` can now run from anywhere in a zola directory
|
||||||
- Add XML support to `load_data`
|
- Add XML support to `load_data`
|
||||||
|
- `skip_prefixes` is now checked before parsing external link URLs
|
||||||
|
|
||||||
## 0.15.3 (2022-01-23)
|
## 0.15.3 (2022-01-23)
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,3 @@ pub use pagination::Paginator;
|
||||||
pub use section::Section;
|
pub use section::Section;
|
||||||
pub use taxonomies::{Taxonomy, TaxonomyItem};
|
pub use taxonomies::{Taxonomy, TaxonomyItem};
|
||||||
pub use types::*;
|
pub use types::*;
|
||||||
|
|
||||||
// TODO
|
|
||||||
// 3. add more tests
|
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
use libs::percent_encoding::percent_decode;
|
use libs::percent_encoding::percent_decode;
|
||||||
use libs::unicode_segmentation::UnicodeSegmentation;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::hash::BuildHasher;
|
use std::hash::BuildHasher;
|
||||||
|
|
||||||
use errors::{anyhow, Result};
|
use errors::{anyhow, Result};
|
||||||
|
|
||||||
// TODO: move to content
|
|
||||||
/// Get word count and estimated reading time
|
|
||||||
pub fn get_reading_analytics(content: &str) -> (usize, usize) {
|
|
||||||
let word_count: usize = content.unicode_words().count();
|
|
||||||
|
|
||||||
// https://help.medium.com/hc/en-us/articles/214991667-Read-time
|
|
||||||
// 275 seems a bit too high though
|
|
||||||
(word_count, ((word_count + 199) / 200))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Result of a successful resolution of an internal link.
|
/// Result of a successful resolution of an internal link.
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
|
@ -58,7 +48,7 @@ pub fn resolve_internal_link<S: BuildHasher>(
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use super::{get_reading_analytics, resolve_internal_link};
|
use super::{resolve_internal_link};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_resolve_valid_internal_link() {
|
fn can_resolve_valid_internal_link() {
|
||||||
|
@ -104,29 +94,4 @@ mod tests {
|
||||||
let res = resolve_internal_link("@/pages/about.md#hello", &HashMap::new());
|
let res = resolve_internal_link("@/pages/about.md#hello", &HashMap::new());
|
||||||
assert!(res.is_err());
|
assert!(res.is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reading_analytics_empty_text() {
|
|
||||||
let (word_count, reading_time) = get_reading_analytics(" ");
|
|
||||||
assert_eq!(word_count, 0);
|
|
||||||
assert_eq!(reading_time, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reading_analytics_short_text() {
|
|
||||||
let (word_count, reading_time) = get_reading_analytics("Hello World");
|
|
||||||
assert_eq!(word_count, 2);
|
|
||||||
assert_eq!(reading_time, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn reading_analytics_long_text() {
|
|
||||||
let mut content = String::new();
|
|
||||||
for _ in 0..1000 {
|
|
||||||
content.push_str(" Hello world");
|
|
||||||
}
|
|
||||||
let (word_count, reading_time) = get_reading_analytics(&content);
|
|
||||||
assert_eq!(word_count, 2000);
|
|
||||||
assert_eq!(reading_time, 10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue