Tag support color options (#1566)

* feat: tag support color options

* refactor: change the color of tag

* feat: add api model property

* refactor: change color field length

* refactor: color field length in tag param
pull/1571/head
guqing 2021-12-06 12:38:06 +08:00 committed by GitHub
parent ab82fadd6e
commit 448739cddd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import java.util.Date;
import lombok.Data;
import run.halo.app.model.dto.base.OutputConverter;
import run.halo.app.model.entity.Tag;
import run.halo.app.model.support.HaloConst;
/**
* Tag output dto.
@ -21,6 +22,8 @@ public class TagDTO implements OutputConverter<TagDTO, Tag> {
private String slug;
private String color = HaloConst.DEFAULT_TAG_COLOR;
private String thumbnail;
private Date createTime;

View File

@ -16,6 +16,7 @@ import org.hibernate.annotations.GenericGenerator;
* Tag entity
*
* @author ryanwang
* @author guqing
* @date 2019-03-12
*/
@Data
@ -50,6 +51,12 @@ public class Tag extends BaseEntity {
@Column(name = "slug", unique = true)
private String slug;
/**
* Tag color.
*/
@Column(name = "color", length = 25)
private String color;
/**
* Cover thumbnail of the tag.
*/

View File

@ -1,11 +1,13 @@
package run.halo.app.model.params;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Tag;
import run.halo.app.model.support.HaloConst;
import run.halo.app.utils.SlugUtils;
/**
@ -13,6 +15,7 @@ import run.halo.app.utils.SlugUtils;
*
* @author johnniang
* @author ryanwang
* @author guqing
* @date 2019-03-20
*/
@Data
@ -25,6 +28,13 @@ public class TagParam implements InputConverter<Tag> {
@Size(max = 255, message = "标签别名的字符长度不能超过 {max}")
private String slug;
@Size(max = 24, message = "颜色值字符长度不能超过 {max}")
@ApiModelProperty(value = "标签颜色,支持多种颜色模式,"
+ "例如 Hex: #cfd3d7颜色名称LightGreyRGB: rgb(207, 211, 215)"
+ "RGBA: rgb(207, 211, 215, 0.5)等", name = "color",
example = "#e23d66")
private String color;
@Size(max = 1023, message = "封面图链接的字符长度不能超过 {max}")
private String thumbnail;
@ -37,6 +47,10 @@ public class TagParam implements InputConverter<Tag> {
thumbnail = "";
}
if (StringUtils.isBlank(color)) {
this.color = HaloConst.DEFAULT_TAG_COLOR;
}
return InputConverter.super.convertTo();
}
@ -49,6 +63,10 @@ public class TagParam implements InputConverter<Tag> {
thumbnail = "";
}
if (StringUtils.isBlank(color)) {
this.color = HaloConst.DEFAULT_TAG_COLOR;
}
InputConverter.super.update(tag);
}
}

View File

@ -8,6 +8,7 @@ import org.springframework.http.HttpHeaders;
* Halo constants.
*
* @author ryanwang
* @author guqing
* @date 2017/12/29
*/
public class HaloConst {
@ -58,6 +59,11 @@ public class HaloConst {
*/
public static final String DEFAULT_ERROR_PATH = "common/error/error";
/**
* Default tag color.
*/
public static final String DEFAULT_TAG_COLOR = "#cfd3d7";
/**
* Path separator.
*/
@ -67,6 +73,7 @@ public class HaloConst {
* Post password template name.
*/
public static final String POST_PASSWORD_TEMPLATE = "post_password";
/**
* Suffix of freemarker template file.
*/