Skip to content

Commit

Permalink
fix(slug): Dont ignore non-ascii in slug
Browse files Browse the repository at this point in the history
Fixes #383
  • Loading branch information
epage committed Mar 16, 2018
1 parent 8c5199f commit 08f0621
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -23,6 +23,7 @@ doc = false
[dependencies]
clap = "2.24"
liquid = {version = "0.14.1", features=["serde"]}
unidecode = "0.3.0"
walkdir = "2.0"
chrono = "0.4"
log = "0.4"
Expand Down
10 changes: 9 additions & 1 deletion src/cobalt_model/slug.rs
@@ -1,5 +1,6 @@
use itertools::Itertools;
use regex::Regex;
use unidecode;

lazy_static!{
static ref SLUG_INVALID_CHARS: Regex = Regex::new(r"([^a-zA-Z0-9]+)").unwrap();
Expand All @@ -11,7 +12,8 @@ pub fn slugify<S: AsRef<str>>(name: S) -> String {
}

fn slugify_str(name: &str) -> String {
let slug = SLUG_INVALID_CHARS.replace_all(name, "-");
let name = unidecode::unidecode(name);
let slug = SLUG_INVALID_CHARS.replace_all(&name, "-");
slug.trim_matches('-').to_lowercase()
}

Expand Down Expand Up @@ -41,6 +43,12 @@ fn test_slugify() {
assert_eq!(actual, "file-world-09");
}

#[test]
fn test_slugify_unicode() {
let actual = slugify("__Æneid__北亰-worlD-__09___");
assert_eq!(actual, "aeneid-bei-jing-world-09");
}

#[test]
fn test_titleize_slug() {
let actual = titleize_slug("tItLeIzE-sLuG");
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Expand Up @@ -12,6 +12,7 @@ extern crate rss;
extern crate serde_json;
extern crate serde_yaml;
extern crate toml;
extern crate unidecode;
extern crate walkdir;

#[cfg(feature = "sass")]
Expand Down

0 comments on commit 08f0621

Please sign in to comment.