diff --git a/src/main/java/run/halo/app/model/params/JournalParam.java b/src/main/java/run/halo/app/model/params/JournalParam.java index 9499997214..463b4da435 100644 --- a/src/main/java/run/halo/app/model/params/JournalParam.java +++ b/src/main/java/run/halo/app/model/params/JournalParam.java @@ -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 { @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); + } + } } diff --git a/src/main/java/run/halo/app/service/impl/JournalServiceImpl.java b/src/main/java/run/halo/app/service/impl/JournalServiceImpl.java index 392ba208a1..fbb5072096 100644 --- a/src/main/java/run/halo/app/service/impl/JournalServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/JournalServiceImpl.java @@ -19,7 +19,6 @@ 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.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 Journal createBy(JournalParam journalParam) { 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 Journal createBy(JournalParam journalParam) { @Override public Journal updateBy(Journal journal) { Assert.notNull(journal, "Journal must not be null"); - - journal.setContent(MarkdownUtils.renderHtml(journal.getSourceContent())); - return update(journal); }