Skip to content
Snippets Groups Projects
Commit d458f3b9 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

Slugify in a clean way

parent 466a083f
No related branches found
No related tags found
No related merge requests found
......@@ -142,6 +142,11 @@
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.github.slugify</groupId>
<artifactId>slugify</artifactId>
<version>2.1.4</version>
</dependency>
</dependencies>
<build>
......
......@@ -5,6 +5,7 @@
package org.hbp.mip.controllers;
import com.github.slugify.Slugify;
import io.swagger.annotations.*;
import org.hbp.mip.MIPApplication;
import org.hbp.mip.model.Article;
......@@ -17,6 +18,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
......@@ -102,7 +104,16 @@ public class ArticlesApi {
if (article.getStatus().equals("published")) {
article.setPublishedAt(new Date());
}
article.setSlug(article.getTitle().toLowerCase().replaceAll(" ","_"));
Slugify slg = null;
try {
slg = new Slugify();
} catch (IOException e) {
e.printStackTrace();
}
String slug = slg.slugify(article.getTitle());
article.setSlug(slug);
article.setCreatedBy(user);
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
......
......@@ -4,6 +4,7 @@
package org.hbp.mip.controllers;
import com.github.slugify.Slugify;
import io.swagger.annotations.*;
import org.hbp.mip.MIPApplication;
import org.hbp.mip.model.*;
......@@ -16,6 +17,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
......@@ -101,7 +103,15 @@ public class ModelsApi {
User user = mipApplication.getUser();
model.setSlug(model.getConfig().getTitle().get("text").toLowerCase());
Slugify slg = null;
try {
slg = new Slugify();
} catch (IOException e) {
e.printStackTrace();
}
String slug = slg.slugify(model.getConfig().getTitle().get("text"));
model.setSlug(slug);
model.setTitle(model.getConfig().getTitle().get("text"));
model.setValid(true);
model.setCreatedBy(user);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment