Skip to content

Commit

Permalink
feat: elog flow
Browse files Browse the repository at this point in the history
  • Loading branch information
LetTTGACO committed Jun 15, 2024
1 parent 5a6e9c9 commit 1758f5a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
25 changes: 14 additions & 11 deletions packages/elog/src/Graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand All @@ -46,17 +47,17 @@ export default class Graph {
writeCache<T>(sortedDocList: SortedDoc<T>[] = []) {
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), {
Expand All @@ -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) {
// 新增文档
Expand Down
2 changes: 1 addition & 1 deletion packages/elog/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ElogCacheConfig {
/** 是否禁用缓存 */
disableCache?: boolean;
/** 缓存文件目录 */
cacheFilePath: string;
cacheFilePath?: string;
}
/**
* elog.config.ts 配置文件
Expand Down
2 changes: 1 addition & 1 deletion playground/plugin-from-feishu-space/src/FeiShuClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion playground/plugin-from-feishu-wiki/src/FeiShuClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class FeiShuClient extends ElogFromContext {
* 获取文章列表
*/
async getDocDetailList() {
this.ctx.info('正在获取文档列表,请稍等...');
this.ctx.info('正在获取待更新文档,请稍等...');
// 获取已排序的文档
const sortedDocList = await this.api.getSortedDocList();
// 过滤不需要更新的文档
Expand Down
2 changes: 1 addition & 1 deletion playground/plugin-from-flowus/src/FlowUsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion playground/plugin-from-notion/src/NotionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default class NotionClient extends ElogFromContext {
* 获取文章列表
*/
async getDocDetailList() {
this.ctx.info('正在获取文档列表,请稍等...');
this.ctx.info('正在获取待更新文档,请稍等...');
// 获取待发布的文章
const sortedDocList = await this.api.getSortedDocList();
// 过滤不需要更新的文档
Expand Down
2 changes: 1 addition & 1 deletion playground/plugin-from-wolai/src/WolaiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions playground/plugin-from-yuque-pwd/src/YuqueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// 获取文档列表
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions playground/plugin-from-yuque-token/src/YuqueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class YuqueClient extends ElogFromContext {
* 获取文章详情列表
*/
async getDocDetailList() {
this.ctx.info('正在获取文档列表,请稍等...');
this.ctx.info('正在获取待更新文档,请稍等...');
// 获取目录
const sortedDocList = await this.api.getSortedDocList();
// 获取文档列表
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 1758f5a

Please sign in to comment.