mirror of https://github.com/halo-dev/halo
feat: remove spaces and newlines in post summary.
parent
281d49b51c
commit
32701ab7bd
|
@ -33,6 +33,8 @@ import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.ASC;
|
import static org.springframework.data.domain.Sort.Direction.ASC;
|
||||||
|
@ -52,6 +54,8 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
|
|
||||||
private final OptionService optionService;
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
private final Pattern SUMMARY_PATTERN = Pattern.compile("\\s*|\t|\r|\n");
|
||||||
|
|
||||||
public BasePostServiceImpl(BasePostRepository<POST> basePostRepository,
|
public BasePostServiceImpl(BasePostRepository<POST> basePostRepository,
|
||||||
OptionService optionService) {
|
OptionService optionService) {
|
||||||
super(basePostRepository);
|
super(basePostRepository);
|
||||||
|
@ -437,6 +441,9 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
|
|
||||||
String text = HaloUtils.cleanHtmlTag(htmlContent);
|
String text = HaloUtils.cleanHtmlTag(htmlContent);
|
||||||
|
|
||||||
|
Matcher matcher = SUMMARY_PATTERN.matcher(text);
|
||||||
|
text = matcher.replaceAll("");
|
||||||
|
|
||||||
// Get summary length
|
// Get summary length
|
||||||
Integer summaryLength = optionService.getByPropertyOrDefault(PostProperties.SUMMARY_LENGTH, Integer.class, 150);
|
Integer summaryLength = optionService.getByPropertyOrDefault(PostProperties.SUMMARY_LENGTH, Integer.class, 150);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue