mirror of https://github.com/halo-dev/halo
Fixed #196
parent
755e53be7a
commit
d42e4c2599
|
@ -7,7 +7,6 @@ import org.springframework.data.domain.PageRequest;
|
|||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import run.halo.app.exception.AlreadyExistsException;
|
||||
|
@ -24,6 +23,7 @@ import run.halo.app.service.OptionService;
|
|||
import run.halo.app.service.base.AbstractCrudService;
|
||||
import run.halo.app.service.base.BasePostService;
|
||||
import run.halo.app.utils.DateUtils;
|
||||
import run.halo.app.utils.HaloUtils;
|
||||
import run.halo.app.utils.MarkdownUtils;
|
||||
import run.halo.app.utils.ServiceUtils;
|
||||
|
||||
|
@ -40,6 +40,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* Base post service implementation.
|
||||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -275,7 +276,7 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
|
||||
// Set summary
|
||||
if (StringUtils.isBlank(basePostSimpleDTO.getSummary())) {
|
||||
// TODO build post summary
|
||||
basePostSimpleDTO.setSummary(generateSummary(post.getFormatContent()));
|
||||
}
|
||||
|
||||
return basePostSimpleDTO;
|
||||
|
@ -347,12 +348,14 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
}
|
||||
|
||||
@NonNull
|
||||
protected String convertToSummary(@Nullable String markdownContent) {
|
||||
protected String generateSummary(@NonNull String htmlContent) {
|
||||
Assert.notNull(htmlContent, "html content must not be null");
|
||||
|
||||
String text = HaloUtils.cleanHtmlTag(htmlContent);
|
||||
|
||||
// Get summary length
|
||||
Integer summaryLength = optionService.getByPropertyOrDefault(PostProperties.SUMMARY_LENGTH, Integer.class, 150);
|
||||
|
||||
// TODO build summary.
|
||||
return "";
|
||||
return StringUtils.substring(text, 0, summaryLength);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -463,7 +463,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
PostListVO postListVO = new PostListVO().convertFrom(post);
|
||||
|
||||
if (StringUtils.isBlank(postListVO.getSummary())) {
|
||||
// TODO Set summary
|
||||
postListVO.setSummary(generateSummary(post.getFormatContent()));
|
||||
}
|
||||
|
||||
Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new);
|
||||
|
|
|
@ -8,7 +8,6 @@ import org.springframework.util.Assert;
|
|||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.UUID;
|
||||
|
||||
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
||||
|
@ -17,11 +16,14 @@ import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR;
|
|||
* Common utils
|
||||
*
|
||||
* @author ryanwang
|
||||
* @author johnniang
|
||||
* @date : 2017/12/22
|
||||
*/
|
||||
@Slf4j
|
||||
public class HaloUtils {
|
||||
|
||||
private static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
|
||||
|
||||
/**
|
||||
* Desensitizes the plain text.
|
||||
*
|
||||
|
@ -192,4 +194,14 @@ public class HaloUtils {
|
|||
}
|
||||
return machineAddress.getHostAddress();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean all html tag
|
||||
*
|
||||
* @param content html document
|
||||
* @return text before cleaned
|
||||
*/
|
||||
public static String cleanHtmlTag(String content) {
|
||||
return content.replaceAll(RE_HTML_MARK, "");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue