mirror of https://github.com/halo-dev/halo
feat: support markdown for journal.
parent
f60938ec87
commit
6941cd4c32
|
@ -62,7 +62,8 @@ public class JournalController {
|
|||
@RequestBody @Valid JournalParam journalParam) {
|
||||
Journal journal = journalService.getById(id);
|
||||
journalParam.update(journal);
|
||||
return new JournalDTO().convertFrom(journalService.update(journal));
|
||||
Journal updatedJournal = journalService.updateBy(journal);
|
||||
return journalService.convertTo(updatedJournal);
|
||||
}
|
||||
|
||||
@DeleteMapping("{journalId:\\d+}")
|
||||
|
|
|
@ -11,13 +11,16 @@ import java.util.Date;
|
|||
* Journal dto.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-24
|
||||
* @author ryanwang
|
||||
* @date 2019-04-24
|
||||
*/
|
||||
@Data
|
||||
public class JournalDTO implements OutputConverter<JournalDTO, Journal> {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String sourceContent;
|
||||
|
||||
private String content;
|
||||
|
||||
private Long likes;
|
||||
|
|
|
@ -12,7 +12,7 @@ import javax.persistence.*;
|
|||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 3/22/19
|
||||
* @date 2019-03-22
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
|
@ -25,7 +25,10 @@ public class Journal extends BaseEntity {
|
|||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "content", columnDefinition = "varchar(1023) not null")
|
||||
@Column(name = "source_content", columnDefinition = "varchar(1023) not null default ''")
|
||||
private String sourceContent;
|
||||
|
||||
@Column(name = "content", columnDefinition = "text not null")
|
||||
private String content;
|
||||
|
||||
@Column(name = "likes", columnDefinition = "bigint default 0")
|
||||
|
@ -44,7 +47,6 @@ public class Journal extends BaseEntity {
|
|||
likes = 0L;
|
||||
}
|
||||
|
||||
|
||||
if (type == null) {
|
||||
type = JournalType.PUBLIC;
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ import javax.validation.constraints.Size;
|
|||
*
|
||||
* @author johnniang
|
||||
* @author ryanwang
|
||||
* @date 19-4-25
|
||||
* @date 2019-4-25
|
||||
*/
|
||||
@Data
|
||||
public class JournalParam implements InputConverter<Journal> {
|
||||
|
||||
@NotBlank(message = "内容不能为空")
|
||||
@Size(max = 511, message = "内容的字符长度不能超过 {max}")
|
||||
private String content;
|
||||
private String sourceContent;
|
||||
|
||||
private JournalType type = JournalType.PUBLIC;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,14 @@ public interface JournalService extends CrudService<Journal, Integer> {
|
|||
@NonNull
|
||||
Journal createBy(@NonNull JournalParam journalParam);
|
||||
|
||||
/**
|
||||
* Updates a journal.
|
||||
*
|
||||
* @param journal journal must not be null
|
||||
* @return updated journal
|
||||
*/
|
||||
Journal updateBy(@NonNull Journal journal);
|
||||
|
||||
/**
|
||||
* Gets latest journals.
|
||||
*
|
||||
|
|
|
@ -21,6 +21,7 @@ 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;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
|
@ -53,7 +54,19 @@ public class JournalServiceImpl extends AbstractCrudService<Journal, Integer> im
|
|||
public Journal createBy(JournalParam journalParam) {
|
||||
Assert.notNull(journalParam, "Journal param must not be null");
|
||||
|
||||
return create(journalParam.convertTo());
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -253,9 +253,6 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
|||
public PostDetailVO importMarkdown(String markdown, String filename) {
|
||||
Assert.notNull(markdown, "Markdown document must not be null");
|
||||
|
||||
// Render markdown to html document.
|
||||
String content = MarkdownUtils.renderHtml(markdown);
|
||||
|
||||
// Gets frontMatter
|
||||
Map<String, List<String>> frontMatter = MarkdownUtils.getFrontMatter(markdown);
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
-- Migrate 1.2.0-beta.1 to 1.2.0-beta.2
|
||||
|
||||
-- Migrate journals Table
|
||||
alter table journals modify content text not null;
|
||||
|
||||
update journals set `source_content`=`content`
|
Loading…
Reference in New Issue