Skip to content

Commit 1689d30

Browse files
committed
feat: elog flow
1 parent ed19010 commit 1689d30

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

packages/elog/src/Graph.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default class Graph {
1414
private readonly cachedDocList: DocDetail[] = [];
1515
constructor(options: ElogConfig) {
1616
this.elogConfig = options;
17+
this.elogConfig.cacheFilePath = this.elogConfig.cacheFilePath || 'elog.cache.json';
1718
this.cachedDocList = this.initCache(options);
1819
this.pluginDriver = new PluginDriver(options, this.cachedDocList);
1920
}
@@ -27,8 +28,8 @@ export default class Graph {
2728
return [];
2829
} else {
2930
try {
30-
const cacheJson = require(path.join(process.cwd(), baseConfig.cacheFilePath));
31-
const { cachedDocList } = cacheJson;
31+
const cacheJson = require(path.join(process.cwd(), baseConfig.cacheFilePath!));
32+
const { cachedDocList = [] } = cacheJson;
3233
// 获取缓存文章
3334
return cachedDocList as (DocDetail & DocExt)[];
3435
} catch (error) {
@@ -46,17 +47,17 @@ export default class Graph {
4647
writeCache<T>(sortedDocList: SortedDoc<T>[] = []) {
4748
try {
4849
const { cacheFilePath } = this.elogConfig;
49-
// 判断cachedDocList列表中对象是否有 body 属性
50-
const hasBody = this.cachedDocList?.some((doc) => !!doc.body);
51-
if (hasBody) {
52-
out.debug(
53-
'警告',
54-
'缓存信息存在 body(文档内容)信息,可能会导致缓存文件过大,如无必要用途建议删除 body 属性',
55-
);
56-
}
50+
// // 判断cachedDocList列表中对象是否有 body 属性
51+
// const hasBody = this.cachedDocList?.some((doc) => !!doc.body);
52+
// if (hasBody) {
53+
// out.debug(
54+
// '警告',
55+
// '缓存信息存在 body(文档内容)信息,可能会导致缓存文件过大,如无必要用途建议删除 body 属性',
56+
// );
57+
// }
5758
// 写入缓存
5859
const cacheJson = {
59-
cachedDocList: this.cachedDocList,
60+
cachedDocList: this.cachedDocList.map((item) => ({ ...item, body: undefined })),
6061
sortedDocList: sortedDocList,
6162
};
6263
fs.writeFileSync(cacheFilePath!, JSON.stringify(cacheJson, null, 2), {
@@ -73,7 +74,9 @@ export default class Graph {
7374
* @param docStatusMap
7475
*/
7576
updateCache(docList: DocDetail[], docStatusMap: any) {
77+
console.log('docStatusMap', docStatusMap);
7678
for (const doc of docList) {
79+
console.log('doc.id', doc.id);
7780
const { _updateIndex, _status } = docStatusMap[doc.id];
7881
if (_status === DocStatus.NEW) {
7982
// 新增文档

packages/elog/src/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export interface ElogCacheConfig {
99
/** 是否禁用缓存 */
1010
disableCache?: boolean;
1111
/** 缓存文件目录 */
12-
cacheFilePath: string;
12+
cacheFilePath?: string;
1313
}
1414
/**
1515
* elog.config.ts 配置文件

playground/plugin-from-feishu-space/src/FeiShuClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class FeiShuClient extends ElogFromContext {
1616
* 获取文章列表
1717
*/
1818
async getDocDetailList() {
19-
this.ctx.info('正在获取文档列表,请稍等...');
19+
this.ctx.info('正在获取待更新文档,请稍等...');
2020
// 获取已排序的文档
2121
const sortedDocList = await this.api.getSortedDocList();
2222
const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList);

playground/plugin-from-feishu-wiki/src/FeiShuClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class FeiShuClient extends ElogFromContext {
1616
* 获取文章列表
1717
*/
1818
async getDocDetailList() {
19-
this.ctx.info('正在获取文档列表,请稍等...');
19+
this.ctx.info('正在获取待更新文档,请稍等...');
2020
// 获取已排序的文档
2121
const sortedDocList = await this.api.getSortedDocList();
2222
// 过滤不需要更新的文档

playground/plugin-from-flowus/src/FlowUsClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class FlowUsClient extends ElogFromContext {
1616
* 获取文章列表
1717
*/
1818
async getDocDetailList() {
19-
this.ctx.info('正在获取文档列表,请稍等...');
19+
this.ctx.info('正在获取待更新文档,请稍等...');
2020
// 获取已排序的文档
2121
const sortedDocList = await this.api.getSortedDocList();
2222
const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList);

playground/plugin-from-notion/src/NotionClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class NotionClient extends ElogFromContext {
4242
* 获取文章列表
4343
*/
4444
async getDocDetailList() {
45-
this.ctx.info('正在获取文档列表,请稍等...');
45+
this.ctx.info('正在获取待更新文档,请稍等...');
4646
// 获取待发布的文章
4747
const sortedDocList = await this.api.getSortedDocList();
4848
// 过滤不需要更新的文档

playground/plugin-from-wolai/src/WolaiClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default class WolaiClient extends ElogFromContext {
1616
* 获取文章列表
1717
*/
1818
async getDocDetailList() {
19-
this.ctx.info('正在获取文档列表,请稍等...');
19+
this.ctx.info('正在获取待更新文档,请稍等...');
2020
// 获取已排序的文档
2121
const sortedDocList = await this.api.getSortedDocList();
2222
const { docList: needUpdateDocList, docStatusMap } = this.filterDocs(sortedDocList);

playground/plugin-from-yuque-pwd/src/YuqueClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default class YuqueClient extends ElogFromContext {
2626
async getDocDetailList() {
2727
// 登录
2828
await this.api.login();
29-
this.ctx.info('正在获取文档列表,请稍等...');
29+
this.ctx.info('正在获取待更新文档,请稍等...');
3030
// 获取已排序目录信息
3131
const tocList = await this.api.getToc();
3232
// 获取文档列表
@@ -83,7 +83,7 @@ export default class YuqueClient extends ElogFromContext {
8383
// 处理语雀字符串
8484
let newBody = processMarkdownRaw(body);
8585
const docDetail: DocDetail = {
86-
id: doc.slug,
86+
id: doc.id as unknown as string,
8787
title: doc.title,
8888
body: newBody,
8989
properties,

playground/plugin-from-yuque-token/src/YuqueClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export default class YuqueClient extends ElogFromContext {
2424
* 获取文章详情列表
2525
*/
2626
async getDocDetailList() {
27-
this.ctx.info('正在获取文档列表,请稍等...');
27+
this.ctx.info('正在获取待更新文档,请稍等...');
2828
// 获取目录
2929
const sortedDocList = await this.api.getSortedDocList();
3030
// 获取文档列表
@@ -81,7 +81,7 @@ export default class YuqueClient extends ElogFromContext {
8181
// 处理语雀字符串
8282
let newBody = processMarkdownRaw(body);
8383
const docDetail: DocDetail = {
84-
id: doc.slug,
84+
id: doc.id as unknown as string,
8585
title: doc.title,
8686
body: newBody,
8787
properties,

0 commit comments

Comments
 (0)