Fixed markdown render with short url.

pull/296/head
ruibaby 2019-08-18 20:38:38 +08:00
parent 912427d159
commit f70f7560ba
3 changed files with 35 additions and 9 deletions

View File

@ -23,6 +23,7 @@ import java.util.Objects;
* Up Yun file handler.
*
* @author johnniang
* @author ryanwang
* @date 3/27/19
*/
@Slf4j
@ -46,6 +47,7 @@ public class UpYunFileHandler implements FileHandler {
String ossOperator = optionService.getByPropertyOfNonNull(UpYunProperties.OSS_OPERATOR).toString();
// style rule can be null
String ossStyleRule = optionService.getByPropertyOrDefault(UpYunProperties.OSS_STYLE_RULE, String.class, "");
String ossThumbnailStyleRule = optionService.getByPropertyOrDefault(UpYunProperties.OSS_THUMBNAIL_STYLE_RULE, String.class, "");
// Create up yun
UpYun upYun = new UpYun(ossBucket, ossOperator, ossPassword);
@ -75,7 +77,7 @@ public class UpYunFileHandler implements FileHandler {
// Build upload result
UploadResult uploadResult = new UploadResult();
uploadResult.setFilename(basename);
uploadResult.setFilePath(filePath);
uploadResult.setFilePath(StringUtils.isBlank(filePath) ? filePath : filePath + ossStyleRule);
uploadResult.setKey(upFilePath);
uploadResult.setMediaType(MediaType.valueOf(Objects.requireNonNull(file.getContentType())));
uploadResult.setSuffix(extension);
@ -86,7 +88,7 @@ public class UpYunFileHandler implements FileHandler {
BufferedImage image = ImageIO.read(file.getInputStream());
uploadResult.setWidth(image.getWidth());
uploadResult.setHeight(image.getHeight());
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossStyleRule);
uploadResult.setThumbPath(StringUtils.isBlank(ossStyleRule) ? filePath : filePath + ossThumbnailStyleRule);
}
return uploadResult;

View File

@ -4,21 +4,45 @@ package run.halo.app.model.properties;
* You pai yun properties.
*
* @author johnniang
* @author ryanwang
* @date 3/27/19
*/
public enum UpYunProperties implements PropertyEnum {
/**
* upyun oss source
*/
OSS_SOURCE("oss_upyun_source", String.class, ""),
/**
* upyun oss password
*/
OSS_PASSWORD("oss_upyun_password", String.class, ""),
/**
* upyun oss bucket
*/
OSS_BUCKET("oss_upyun_bucket", String.class, ""),
/**
* upyun oss domain
*/
OSS_DOMAIN("oss_upyun_domain", String.class, ""),
/**
* upyun oss operator
*/
OSS_OPERATOR("oss_upyun_operator", String.class, ""),
OSS_STYLE_RULE("oss_upyun_style_rule", String.class, "");
/**
* upyun oss style rule
*/
OSS_STYLE_RULE("oss_upyun_style_rule", String.class, ""),
/**
* upyun oss thumbnail style rule
*/
OSS_THUMBNAIL_STYLE_RULE("oss_upyun_thumbnail_style_rule",String.class,"");
private final String defaultValue;
private String value;

View File

@ -73,25 +73,25 @@ public class MarkdownUtils {
if (StringUtils.isBlank(markdown)) {
return "";
}
Node document = PARSER.parse(markdown);
String renderedContent = RENDERER.render(document);
// Render netease music short url.
if (markdown.contains(HaloConst.NETEASE_MUSIC_PREFIX)) {
renderedContent = markdown.replaceAll(HaloConst.NETEASE_MUSIC_REG_PATTERN, HaloConst.NETEASE_MUSIC_IFRAME);
markdown = markdown.replaceAll(HaloConst.NETEASE_MUSIC_REG_PATTERN, HaloConst.NETEASE_MUSIC_IFRAME);
}
// Render bilibili video short url.
if (markdown.contains(HaloConst.BILIBILI_VIDEO_PREFIX)) {
renderedContent = markdown.replaceAll(HaloConst.BILIBILI_VIDEO_REG_PATTERN, HaloConst.BILIBILI_VIDEO_IFRAME);
markdown = markdown.replaceAll(HaloConst.BILIBILI_VIDEO_REG_PATTERN, HaloConst.BILIBILI_VIDEO_IFRAME);
}
// Render youtube video short url.
if (markdown.contains(HaloConst.YOUTUBE_VIDEO_PREFIX)) {
renderedContent = markdown.replaceAll(HaloConst.YOUTUBE_VIDEO_REG_PATTERN, HaloConst.YOUTUBE_VIDEO_IFRAME);
markdown = markdown.replaceAll(HaloConst.YOUTUBE_VIDEO_REG_PATTERN, HaloConst.YOUTUBE_VIDEO_IFRAME);
}
return renderedContent;
Node document = PARSER.parse(markdown);
return RENDERER.render(document);
}
/**