Commit c7078528 authored by Liang Ding's avatar Liang Ding

🎨 七牛图片样式处理

parent f71b94c0
......@@ -41,6 +41,32 @@ public final class Images {
*/
private static final Logger LOGGER = Logger.getLogger(Images.class);
/**
* Qiniu image processing.
*
* @param html the specified content HTML
* @return processed content
*/
public static String qiniuImgProcessing(final String html) {
String ret = html;
final String qiniuDomain = "https://img.hacpai.com";
final String[] imgSrcs = StringUtils.substringsBetween(html, "<img src=\"", "\"");
if (null == imgSrcs) {
return ret;
}
for (final String imgSrc : imgSrcs) {
if (!StringUtils.startsWith(imgSrc, qiniuDomain) || StringUtils.contains(imgSrc, ".gif")
|| StringUtils.containsIgnoreCase(imgSrc, "?imageView2")) {
continue;
}
ret = StringUtils.replace(ret, imgSrc, imgSrc + "?imageView2/2/w/768/format/webp/interlace/1");
}
return ret;
}
/**
* Returns image URL of Qiniu image processing style with the specified width and height.
*
......
......@@ -197,6 +197,7 @@ public final class Markdowns {
String ret = doc.select("body").html();
ret = StringUtils.trim(ret);
ret = Images.qiniuImgProcessing(ret);
// cache it
putHTML(markdownText, ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment