Support receiving rendering results for journal(#1739)

pull/1747/head
guqing 2022-03-11 17:37:34 +08:00 committed by GitHub
parent e692cb3186
commit 1713be8daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -1,10 +1,12 @@
package run.halo.app.model.params;
import java.util.Objects;
import javax.validation.constraints.NotBlank;
import lombok.Data;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Journal;
import run.halo.app.model.enums.JournalType;
import run.halo.app.utils.MarkdownUtils;
/**
* Journal param.
@ -19,5 +21,34 @@ public class JournalParam implements InputConverter<Journal> {
@NotBlank(message = "内容不能为空")
private String sourceContent;
private String content;
private JournalType type = JournalType.PUBLIC;
/**
* if {@code true}, it means is that do not let the back-end render the original content
* because the content has been rendered, and you only need to store the original content.
*/
private Boolean keepRaw = false;
@Override
public Journal convertTo() {
Journal journal = InputConverter.super.convertTo();
populateContent(journal);
return journal;
}
@Override
public void update(Journal domain) {
InputConverter.super.update(domain);
populateContent(domain);
}
private void populateContent(Journal journal) {
if (Objects.equals(keepRaw, false)) {
journal.setContent(MarkdownUtils.renderHtml(sourceContent));
} else {
journal.setContent(content);
}
}
}

View File

@ -19,7 +19,6 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import run.halo.app.exception.BadRequestException;
import run.halo.app.model.dto.JournalDTO;
import run.halo.app.model.dto.JournalWithCmtCountDTO;
import run.halo.app.model.entity.Journal;
import run.halo.app.model.entity.JournalComment;
@ -31,7 +30,6 @@ import run.halo.app.repository.JournalRepository;
import run.halo.app.service.JournalCommentService;
import run.halo.app.service.JournalService;
import run.halo.app.service.base.AbstractCrudService;
import run.halo.app.utils.MarkdownUtils;
import run.halo.app.utils.ServiceUtils;
/**
@ -62,7 +60,6 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
Assert.notNull(journalParam, "Journal param must not be null");
Journal journal = journalParam.convertTo();
journal.setContent(MarkdownUtils.renderHtml(journal.getSourceContent()));
return create(journal);
}
@ -70,9 +67,6 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer>
@Override
public Journal updateBy(Journal journal) {
Assert.notNull(journal, "Journal must not be null");
journal.setContent(MarkdownUtils.renderHtml(journal.getSourceContent()));
return update(journal);
}