From 6b232f993d60a6d45da20d7138a025e07b9286d0 Mon Sep 17 00:00:00 2001 From: zeekling Date: Tue, 28 Jul 2020 00:11:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=94=AF=E6=8C=81=E8=B7=9F?= =?UTF-8?q?=E6=96=B0github?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zeekling/blog/BlogUpdateServiceImpl.java | 22 ++++++++++++++----- .../com/zeekling/util/FeedXmlUtilTest.java | 3 +++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/zeekling/blog/BlogUpdateServiceImpl.java b/src/main/java/com/zeekling/blog/BlogUpdateServiceImpl.java index 34f29c3..3928dee 100644 --- a/src/main/java/com/zeekling/blog/BlogUpdateServiceImpl.java +++ b/src/main/java/com/zeekling/blog/BlogUpdateServiceImpl.java @@ -14,6 +14,8 @@ import org.json.JSONObject; import java.io.IOException; import java.net.MalformedURLException; import java.nio.charset.StandardCharsets; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -30,6 +32,8 @@ public class BlogUpdateServiceImpl implements BlogUpdateService { private BlogConfigure blogConfigure = null; + private static String HTML_REGEX="<[^>]+>"; + public BlogUpdateServiceImpl(String confPath) { // init blogConfigure try { @@ -70,14 +74,24 @@ public class BlogUpdateServiceImpl implements BlogUpdateService { try { List entries = FeedXmlUtil.parseXml(blogConfigure.getRss()); for (SyndEntry syndEntry: entries){ - bodyBuilder.append("\n* [").append(syndEntry.getTitle()).append("](").append(syndEntry.getLink()).append(")"); + String des = syndEntry.getDescription().getValue(); + des = des.replaceAll("\n", "\n > "); + bodyBuilder.append("\n* \uD83D\uDCDD [").append(syndEntry.getTitle()).append("](").append(syndEntry.getLink()) + .append(") \n > ").append(des); } } catch (FeedException | MalformedURLException e) { e.printStackTrace(); } + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String currentDate = format.format(new Date()); bodyBuilder.append("\n\n"); - String ret = "

\"${title}\"

\n" + + String ret = "### Hey \uD83D\uDC4B, I'm [Zeek Ling](https://www/zeekling.cn)! \n" + + "![Github Stats](https://github-readme-stats.vercel.app/api?username=zeekling&show_icons=true) \n" + + "### 我在[小令童鞋](https://www/zeekling.cn)的近期动态\n" + + "\n" + + "⭐️ Star [个人主页](https://github.com/zeekling/zeekling) 后会自动更新,最近更新时间:`" + currentDate + "`\n" + + "\n

\"${title}\"

" + "${title}\n" + "

\n" + "\n" + @@ -89,9 +103,7 @@ public class BlogUpdateServiceImpl implements BlogUpdateService { "

\n" + "\n" + "${body}\n\n" + - "---\n" + - "\n" + - "本仓库通过 [github_zeekling](https://git.zeekling.cn/zeekling/github_zeekling) 自动进行同步更新 ❤️ "; + "\n" ; ret = ret.replace("${title}", blogConfigure.getClientTitle()). replace("${subtitle}", blogConfigure.getClientSubtitle()). replace("${favicon}", blogConfigure.getFavicon()). diff --git a/src/test/java/com/zeekling/util/FeedXmlUtilTest.java b/src/test/java/com/zeekling/util/FeedXmlUtilTest.java index daece49..aa3ed08 100644 --- a/src/test/java/com/zeekling/util/FeedXmlUtilTest.java +++ b/src/test/java/com/zeekling/util/FeedXmlUtilTest.java @@ -23,6 +23,9 @@ public class FeedXmlUtilTest { try { url = new URL("https://www.zeekling.cn/rss.xml"); List entries = FeedXmlUtil.parseXml(url); + for (SyndEntry syndEntry: entries){ + System.out.println(syndEntry.getTitle() + "\n\t" + syndEntry.getDescription().getValue()); + } } catch (MalformedURLException | FeedException e) { e.printStackTrace(); }