pull/235/head
ruibaby 2019-06-30 12:52:34 +08:00
parent 755e53be7a
commit d42e4c2599
3 changed files with 23 additions and 8 deletions

View File

@ -7,7 +7,6 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.exception.AlreadyExistsException; 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.AbstractCrudService;
import run.halo.app.service.base.BasePostService; import run.halo.app.service.base.BasePostService;
import run.halo.app.utils.DateUtils; import run.halo.app.utils.DateUtils;
import run.halo.app.utils.HaloUtils;
import run.halo.app.utils.MarkdownUtils; import run.halo.app.utils.MarkdownUtils;
import run.halo.app.utils.ServiceUtils; import run.halo.app.utils.ServiceUtils;
@ -40,6 +40,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
* Base post service implementation. * Base post service implementation.
* *
* @author johnniang * @author johnniang
* @author ryanwang
* @date 2019-04-24 * @date 2019-04-24
*/ */
@Slf4j @Slf4j
@ -275,7 +276,7 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
// Set summary // Set summary
if (StringUtils.isBlank(basePostSimpleDTO.getSummary())) { if (StringUtils.isBlank(basePostSimpleDTO.getSummary())) {
// TODO build post summary basePostSimpleDTO.setSummary(generateSummary(post.getFormatContent()));
} }
return basePostSimpleDTO; return basePostSimpleDTO;
@ -347,12 +348,14 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
} }
@NonNull @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 // Get summary length
Integer summaryLength = optionService.getByPropertyOrDefault(PostProperties.SUMMARY_LENGTH, Integer.class, 150); Integer summaryLength = optionService.getByPropertyOrDefault(PostProperties.SUMMARY_LENGTH, Integer.class, 150);
// TODO build summary. return StringUtils.substring(text, 0, summaryLength);
return "";
} }
} }

View File

@ -463,7 +463,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
PostListVO postListVO = new PostListVO().convertFrom(post); PostListVO postListVO = new PostListVO().convertFrom(post);
if (StringUtils.isBlank(postListVO.getSummary())) { if (StringUtils.isBlank(postListVO.getSummary())) {
// TODO Set summary postListVO.setSummary(generateSummary(post.getFormatContent()));
} }
Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new); Optional.ofNullable(tagListMap.get(post.getId())).orElseGet(LinkedList::new);

View File

@ -8,7 +8,6 @@ import org.springframework.util.Assert;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.file.Path;
import java.util.UUID; import java.util.UUID;
import static run.halo.app.model.support.HaloConst.FILE_SEPARATOR; 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 * Common utils
* *
* @author ryanwang * @author ryanwang
* @author johnniang
* @date : 2017/12/22 * @date : 2017/12/22
*/ */
@Slf4j @Slf4j
public class HaloUtils { public class HaloUtils {
private static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
/** /**
* Desensitizes the plain text. * Desensitizes the plain text.
* *
@ -192,4 +194,14 @@ public class HaloUtils {
} }
return machineAddress.getHostAddress(); 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, "");
}
} }