From f550e3eb570bc7aaa504e98e3672cb88dbdccf96 Mon Sep 17 00:00:00 2001 From: wanshao <344277934@qq.com> Date: Tue, 15 Nov 2022 22:47:18 +0800 Subject: [PATCH] fix yuque update utc time judge --- README.md | 6 ++++++ .../com/kaimingwan/core/openapi/yuque/YuqueApi.java | 2 +- .../core/service/impl/SyncServiceImpl.java | 13 ++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4343f00..b33afe7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ ## yuque-image-sync + +### 基本说明 支持自动下载语雀文章,将文章中所有图片上传图床(例如阿里云OSS)后替换文 章中图片地址为图床地址,将处理好的markdown源文件保存到指定位置。理论上可兼容多种博客系统,例如Docusaurus、Hexo等。我自己个人网站用的hexo暂时就只测试了hexo. @@ -15,3 +17,7 @@ |parallel| 并行度,一般设置成和你核心数一样就可以 | |local.post.home| 处理后的markdown源文件需要保存的位置 | |sync.timeout.sec| 每个线程获取异步处理结果的超时时间 | + +### 使用教程 +可以参考我个人网站的使用说明[语雀文章自动同步Hexo](https://kaimingwan.com) + diff --git a/src/main/java/com/kaimingwan/core/openapi/yuque/YuqueApi.java b/src/main/java/com/kaimingwan/core/openapi/yuque/YuqueApi.java index cb204cb..1fbdee4 100644 --- a/src/main/java/com/kaimingwan/core/openapi/yuque/YuqueApi.java +++ b/src/main/java/com/kaimingwan/core/openapi/yuque/YuqueApi.java @@ -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); } diff --git a/src/main/java/com/kaimingwan/core/service/impl/SyncServiceImpl.java b/src/main/java/com/kaimingwan/core/service/impl/SyncServiceImpl.java index 4c19c4a..56974cf 100644 --- a/src/main/java/com/kaimingwan/core/service/impl/SyncServiceImpl.java +++ b/src/main/java/com/kaimingwan/core/service/impl/SyncServiceImpl.java @@ -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> splitList = Lists.partition(latestDocs, subListSize);