Skip to content

Commit

Permalink
fix yuque update utc time judge
Browse files Browse the repository at this point in the history
  • Loading branch information
KaimingWan committed Nov 15, 2022
1 parent f43488b commit f550e3e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
## yuque-image-sync

### 基本说明
支持自动下载语雀文章,将文章中所有图片上传图床(例如阿里云OSS)后替换文
章中图片地址为图床地址,将处理好的markdown源文件保存到指定位置。理论上可兼容多种博客系统,例如Docusaurus、Hexo等。我自己个人网站用的hexo暂时就只测试了hexo.

Expand All @@ -15,3 +17,7 @@
|parallel| 并行度,一般设置成和你核心数一样就可以 |
|local.post.home| 处理后的markdown源文件需要保存的位置 |
|sync.timeout.sec| 每个线程获取异步处理结果的超时时间 |

### 使用教程
可以参考我个人网站的使用说明[语雀文章自动同步Hexo](https://kaimingwan.com)

Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public FetchPostResp fetchPost() {
}

public FetchPostDetailResp fetchPostDetail(String docSlug){
String url = YUQUE_DOMAIN + "/repos/" + namespace + "/docs/"+docSlug;
String url = YUQUE_DOMAIN + "/repos/" + namespace + "/docs/"+docSlug+"?raw=1";
String respJson = ConsoleHttpClient.getWithString(url, headers);
return (FetchPostDetailResp) JacksonUtil.toObj(respJson, FetchPostDetailResp.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,24 @@ public void sync() {
if (newDocIntervalSec > 0) {
String pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
for (YuqueDoc publicDoc : publishedDocs) {
LocalDateTime localDateTime = LocalDateTime.parse(publicDoc.getUpdated_at(), DateTimeFormatter.ofPattern(pattern));
boolean isNewDoc = localDateTime.isAfter(TimeUtil.getLocalDateTimeByMillis(
//update time is UTC
LocalDateTime updateTime = LocalDateTime.parse(publicDoc.getUpdated_at(),
DateTimeFormatter.ofPattern(pattern));
updateTime = updateTime.plusHours(8);
boolean isNewDoc = updateTime.isAfter(TimeUtil.getLocalDateTimeByMillis(
System.currentTimeMillis() - newDocIntervalSec * 1000));
if (isNewDoc) {
latestDocs.add(publicDoc);
}
}
}else{
} else {
latestDocs = publishedDocs;
}

if (CollectionUtil.isEmpty(latestDocs)) {
log.warn("There is no new doc need to process, will exit....");
}

int subListSize = latestDocs.size() / paralle + 1;

List<List<YuqueDoc>> splitList = Lists.partition(latestDocs, subListSize);
Expand Down

0 comments on commit f550e3e

Please sign in to comment.