From 231f2370cea286b9bc32c8faaa4aa3cc81d1c6c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=A2=A6=E5=A4=9C=E9=9B=A8?= <107797432+beimengyeyu@users.noreply.github.com> Date: Sun, 24 Jul 2022 23:17:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(=E6=96=87=E7=AB=A0=E7=94=9F=E6=88=90):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E5=9B=A0=E4=B8=BA=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84=E5=88=A0=E9=99=A4=E7=9A=84=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E8=BF=98=E4=BC=9A=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Downloader.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Downloader.js b/lib/Downloader.js index bf242bb..ceb20d7 100644 --- a/lib/Downloader.js +++ b/lib/Downloader.js @@ -81,7 +81,7 @@ class Downloader { * @return {Promise} queue */ async fetchArticles() { - const { client, config, _cachedArticles } = this; + const { client, config } = this; const articles = await client.getArticles(); if (!Array.isArray(articles.data)) { throw new Error( @@ -95,6 +95,9 @@ class Downloader { ) .filter(article => (config.onlyPublic ? !!article.public : true)) .map(article => lodash.pick(article, PICK_PROPERTY)); + + this._cachedArticles = this._cachedArticles.filter(cache => realArticles.findIndex((item)=>item.slug === cache.slug) != -1); + const queue = new Queue({ concurrency: config.concurrency }); let article; @@ -105,6 +108,8 @@ class Downloader { const findIndexFn = function(item) { return item.slug === article.slug; }; + + const { _cachedArticles } = this; for (let i = 0; i < realArticles.length; i++) { article = realArticles[i]; From e5ff85da04661b1997168edeb725625f99e36379 Mon Sep 17 00:00:00 2001 From: liuyang Date: Thu, 27 Oct 2022 15:36:57 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(=E6=96=87=E7=AB=A0=E5=88=A0=E9=99=A4):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=B2=A1=E6=9C=89=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=96=87=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/Downloader.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Downloader.js b/lib/Downloader.js index ceb20d7..cc8c14e 100644 --- a/lib/Downloader.js +++ b/lib/Downloader.js @@ -9,6 +9,7 @@ const filenamify = require('filenamify'); const YuqueClient = require('./yuque'); const { isPost } = require('../util'); const out = require('./out'); +const rimraf = require('rimraf'); const cwd = process.cwd(); @@ -81,7 +82,7 @@ class Downloader { * @return {Promise} queue */ async fetchArticles() { - const { client, config } = this; + const { client, config, postBasicPath } = this; const articles = await client.getArticles(); if (!Array.isArray(articles.data)) { throw new Error( @@ -95,9 +96,18 @@ class Downloader { ) .filter(article => (config.onlyPublic ? !!article.public : true)) .map(article => lodash.pick(article, PICK_PROPERTY)); - - this._cachedArticles = this._cachedArticles.filter(cache => realArticles.findIndex((item)=>item.slug === cache.slug) != -1); - + + const deletedArticles = this._cachedArticles.filter(cache => realArticles.findIndex(item => item.slug === cache.slug) === -1); + + // 删除本地已存在的但是语雀上面被删除的文章 + for (const article of deletedArticles) { + const fileName = filenamify(article[config.mdNameFormat]); + const postPath = path.join(postBasicPath, `${fileName}.md`); + rimraf.sync(postPath); + } + + this._cachedArticles = this._cachedArticles.filter(cache => realArticles.findIndex(item => item.slug === cache.slug) !== -1); + const queue = new Queue({ concurrency: config.concurrency }); let article; @@ -108,7 +118,7 @@ class Downloader { const findIndexFn = function(item) { return item.slug === article.slug; }; - + const { _cachedArticles } = this; for (let i = 0; i < realArticles.length; i++) {