slug update
This commit is contained in:
parent
6e473f9838
commit
aa4f40ba74
@ -57,6 +57,6 @@ public class Article {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String toSlug(String title) {
|
private String toSlug(String title) {
|
||||||
return title.toLowerCase().replace(' ', '-');
|
return title.toLowerCase().replaceAll("[\\&|[\\uFE30-\\uFFA0]|\\’|\\”|\\s\\?\\,\\.]+", "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
src/test/java/io/spring/core/article/ArticleTest.java
Normal file
39
src/test/java/io/spring/core/article/ArticleTest.java
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package io.spring.core.article;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
public class ArticleTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_get_right_slug() throws Exception {
|
||||||
|
Article article = new Article("a new title", "desc", "body", new String[]{"java"}, "123");
|
||||||
|
assertThat(article.getSlug(), is("a-new-title"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_get_right_slug_with_number_in_title() throws Exception {
|
||||||
|
Article article = new Article("a new title 2", "desc", "body", new String[]{"java"}, "123");
|
||||||
|
assertThat(article.getSlug(), is("a-new-title-2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_get_lower_case_slug() throws Exception {
|
||||||
|
Article article = new Article("A NEW TITLE", "desc", "body", new String[]{"java"}, "123");
|
||||||
|
assertThat(article.getSlug(), is("a-new-title"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_handle_other_language() throws Exception {
|
||||||
|
Article article = new Article("中文:标题", "desc", "body", new String[]{"java"}, "123");
|
||||||
|
assertThat(article.getSlug(), is("中文-标题"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void should_handle_commas() throws Exception {
|
||||||
|
Article article = new Article("what?the.hell,w", "desc", "body", new String[]{"java"}, "123");
|
||||||
|
assertThat(article.getSlug(), is("what-the-hell-w"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user