Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Journal supports receiving front-end rendering results #1739

Merged
merged 1 commit into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/main/java/run/halo/app/model/params/JournalParam.java
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -19,5 +21,34 @@ public class JournalParam implements InputConverter<Journal> {
@NotBlank(message = "内容不能为空")
private String sourceContent;

private String content;
JohnNiang marked this conversation as resolved.
Show resolved Hide resolved

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -62,17 +60,13 @@ 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);
}

@Override
public Journal updateBy(Journal journal) {
Assert.notNull(journal, "Journal must not be null");

journal.setContent(MarkdownUtils.renderHtml(journal.getSourceContent()));

return update(journal);
}

Expand Down