From 1758f5a1251aa86a04b11fd04e1e8e096a804b23 Mon Sep 17 00:00:00 2001 From: LetTTGACO <1225751694@qq.com> Date: Sat, 15 Jun 2024 23:02:37 +0800 Subject: [PATCH] feat: elog flow --- packages/elog/src/Graph.ts | 25 +++++++++++-------- packages/elog/src/types/common.ts | 2 +- .../src/FeiShuClient.ts | 2 +- .../src/FeiShuClient.ts | 2 +- .../plugin-from-flowus/src/FlowUsClient.ts | 2 +- .../plugin-from-notion/src/NotionClient.ts | 2 +- .../plugin-from-wolai/src/WolaiClient.ts | 2 +- .../plugin-from-yuque-pwd/src/YuqueClient.ts | 4 +-- .../src/YuqueClient.ts | 4 +-- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/packages/elog/src/Graph.ts b/packages/elog/src/Graph.ts index ecca3d2d..ff7799d3 100644 --- a/packages/elog/src/Graph.ts +++ b/packages/elog/src/Graph.ts @@ -14,6 +14,7 @@ export default class Graph { private readonly cachedDocList: DocDetail[] = []; constructor(options: ElogConfig) { this.elogConfig = options; + this.elogConfig.cacheFilePath = this.elogConfig.cacheFilePath || 'elog.cache.json'; this.cachedDocList = this.initCache(options); this.pluginDriver = new PluginDriver(options, this.cachedDocList); } @@ -27,8 +28,8 @@ export default class Graph { return []; } else { try { - const cacheJson = require(path.join(process.cwd(), baseConfig.cacheFilePath)); - const { cachedDocList } = cacheJson; + const cacheJson = require(path.join(process.cwd(), baseConfig.cacheFilePath!)); + const { cachedDocList = [] } = cacheJson; // 获取缓存文章 return cachedDocList as (DocDetail & DocExt)[]; } catch (error) { @@ -46,17 +47,17 @@ export default class Graph { writeCache(sortedDocList: SortedDoc[] = []) { try { const { cacheFilePath } = this.elogConfig; - // 判断cachedDocList列表中对象是否有 body 属性 - const hasBody = this.cachedDocList?.some((doc) => !!doc.body); - if (hasBody) { - out.debug( - '警告', - '缓存信息存在 body(文档内容)信息,可能会导致缓存文件过大,如无必要用途建议删除 body 属性', - ); - } + // // 判断cachedDocList列表中对象是否有 body 属性 + // const hasBody = this.cachedDocList?.some((doc) => !!doc.body); + // if (hasBody) { + // out.debug( + // '警告', + // '缓存信息存在 body(文档内容)信息,可能会导致缓存文件过大,如无必要用途建议删除 body 属性', + // ); + // } // 写入缓存 const cacheJson = { - cachedDocList: this.cachedDocList, + cachedDocList: this.cachedDocList.map((item) => ({ ...item, body: undefined })), sortedDocList: sortedDocList, }; fs.writeFileSync(cacheFilePath!, JSON.stringify(cacheJson, null, 2), { @@ -73,7 +74,9 @@ export default class Graph { * @param docStatusMap */ updateCache(docList: DocDetail[], docStatusMap: any) { + console.log('docStatusMap', docStatusMap); for (const doc of docList) { + console.log('doc.id', doc.id); const { _updateIndex, _status } = docStatusMap[doc.id]; if (_status === DocStatus.NEW) { // 新增文档 diff --git a/packages/elog/src/types/common.ts b/packages/elog/src/types/common.ts index eafb63a4..16f5c2aa 100644 --- a/packages/elog/src/types/common.ts +++ b/packages/elog/src/types/common.ts @@ -9,7 +9,7 @@ export interface ElogCacheConfig { /** 是否禁用缓存 */ disableCache?: boolean; /** 缓存文件目录 */ - cacheFilePath: string; + cacheFilePath?: string; } /** * elog.config.ts 配置文件 diff --git a/playground/plugin-from-feishu-space/src/FeiShuClient.ts b/playground/plugin-from-feishu-space/src/FeiShuClient.ts index b3c74ef1..542d746a 100644 --- a/playground/plugin-from-feishu-space/src/FeiShuClient.ts +++ b/playground/plugin-from-feishu-space/src/FeiShuClient.ts @@ -16,7 +16,7 @@ export default class FeiShuClient extends ElogFromContext { * 获取文章列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取已排序的文档 const sortedDocList = await this.api.getSortedDocList(); const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList); diff --git a/playground/plugin-from-feishu-wiki/src/FeiShuClient.ts b/playground/plugin-from-feishu-wiki/src/FeiShuClient.ts index 9da00513..b3195576 100644 --- a/playground/plugin-from-feishu-wiki/src/FeiShuClient.ts +++ b/playground/plugin-from-feishu-wiki/src/FeiShuClient.ts @@ -16,7 +16,7 @@ export default class FeiShuClient extends ElogFromContext { * 获取文章列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取已排序的文档 const sortedDocList = await this.api.getSortedDocList(); // 过滤不需要更新的文档 diff --git a/playground/plugin-from-flowus/src/FlowUsClient.ts b/playground/plugin-from-flowus/src/FlowUsClient.ts index 4d1eb7c1..d95e2dd7 100644 --- a/playground/plugin-from-flowus/src/FlowUsClient.ts +++ b/playground/plugin-from-flowus/src/FlowUsClient.ts @@ -16,7 +16,7 @@ export default class FlowUsClient extends ElogFromContext { * 获取文章列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取已排序的文档 const sortedDocList = await this.api.getSortedDocList(); const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList); diff --git a/playground/plugin-from-notion/src/NotionClient.ts b/playground/plugin-from-notion/src/NotionClient.ts index 0d0e262f..a2a6bfae 100644 --- a/playground/plugin-from-notion/src/NotionClient.ts +++ b/playground/plugin-from-notion/src/NotionClient.ts @@ -42,7 +42,7 @@ export default class NotionClient extends ElogFromContext { * 获取文章列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取待发布的文章 const sortedDocList = await this.api.getSortedDocList(); // 过滤不需要更新的文档 diff --git a/playground/plugin-from-wolai/src/WolaiClient.ts b/playground/plugin-from-wolai/src/WolaiClient.ts index 8a526a85..e13dcb5c 100644 --- a/playground/plugin-from-wolai/src/WolaiClient.ts +++ b/playground/plugin-from-wolai/src/WolaiClient.ts @@ -16,7 +16,7 @@ export default class WolaiClient extends ElogFromContext { * 获取文章列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取已排序的文档 const sortedDocList = await this.api.getSortedDocList(); const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList); diff --git a/playground/plugin-from-yuque-pwd/src/YuqueClient.ts b/playground/plugin-from-yuque-pwd/src/YuqueClient.ts index d2c28609..c4b641e7 100644 --- a/playground/plugin-from-yuque-pwd/src/YuqueClient.ts +++ b/playground/plugin-from-yuque-pwd/src/YuqueClient.ts @@ -26,7 +26,7 @@ export default class YuqueClient extends ElogFromContext { async getDocDetailList() { // 登录 await this.api.login(); - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取已排序目录信息 const tocList = await this.api.getToc(); // 获取文档列表 @@ -83,7 +83,7 @@ export default class YuqueClient extends ElogFromContext { // 处理语雀字符串 let newBody = processMarkdownRaw(body); const docDetail: DocDetail = { - id: doc.slug, + id: doc.id as unknown as string, title: doc.title, body: newBody, properties, diff --git a/playground/plugin-from-yuque-token/src/YuqueClient.ts b/playground/plugin-from-yuque-token/src/YuqueClient.ts index 9853e846..aee16cc8 100644 --- a/playground/plugin-from-yuque-token/src/YuqueClient.ts +++ b/playground/plugin-from-yuque-token/src/YuqueClient.ts @@ -24,7 +24,7 @@ export default class YuqueClient extends ElogFromContext { * 获取文章详情列表 */ async getDocDetailList() { - this.ctx.info('正在获取文档列表,请稍等...'); + this.ctx.info('正在获取待更新文档,请稍等...'); // 获取目录 const sortedDocList = await this.api.getSortedDocList(); // 获取文档列表 @@ -81,7 +81,7 @@ export default class YuqueClient extends ElogFromContext { // 处理语雀字符串 let newBody = processMarkdownRaw(body); const docDetail: DocDetail = { - id: doc.slug, + id: doc.id as unknown as string, title: doc.title, body: newBody, properties,