Skip to content

Commit

Permalink
feat(yuque): yuque optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
LetTTGACO committed May 19, 2024
1 parent adf194c commit 64cf4c6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion playground/plugin-from-yuque-pwd/src/YuqueApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class YuqueApi extends ElogBaseContext {
/**
* 获取目录信息(已排序)
*/
async getSortedInfoList() {
async getSortedDocList() {
try {
const res = await this.requestInternal(
`${this.config.login}/${this.config.repo}`,
Expand Down
13 changes: 6 additions & 7 deletions playground/plugin-from-yuque-pwd/src/YuqueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export default class YuqueClient extends ElogFromContext {
await this.api.login();
this.ctx.info('正在获取文档列表,请稍等...');
// 获取已排序目录信息
const sortedInfoList = await this.api.getSortedInfoList();
const sortedDocList = await this.api.getSortedDocList();
// 获取文档列表
let yuqueBaseDocList = await this.api.getDocList();
// 根据目录排序文档顺序,处理文档目录
yuqueBaseDocList = sortedInfoList
yuqueBaseDocList = sortedDocList
.filter((item) => {
return item.type === 'DOC';
})
Expand All @@ -35,7 +35,7 @@ export default class YuqueClient extends ElogFromContext {
let catalogPath: DocStructure[] = [];
let parentId = item.parent_uuid;
for (let i = 0; i < item.level; i++) {
const current = sortedInfoList.find((item) => item.uuid === parentId)!;
const current = sortedDocList.find((item) => item.uuid === parentId)!;
parentId = current.parent_uuid;
catalogPath.push({
id: item.url,
Expand Down Expand Up @@ -72,7 +72,6 @@ export default class YuqueClient extends ElogFromContext {
process.exit();
}
this.ctx.info('待下载数', String(needUpdateDocList.length));
let updatedDocList: DocDetail[];
const promise = async (doc: YuqueDoc) => {
this.ctx.info(`下载文档 ${doc._index}/${needUpdateDocList.length} `, doc.title);
let articleStr = await this.api.getDocString(doc.slug);
Expand All @@ -90,9 +89,9 @@ export default class YuqueClient extends ElogFromContext {
};
return docDetail;
};
updatedDocList = await this.asyncPool(this.config.limit || 3, needUpdateDocList, promise);
const docDetailList = await this.asyncPool(this.config.limit || 3, needUpdateDocList, promise);
// 更新缓存里的文章
this.updateCache(updatedDocList, idMap);
this.updateCache(docDetailList, idMap);
this.ctx.info('已下载数', String(needUpdateDocList.length));
// 写入缓存
this.writeCache({
Expand All @@ -101,6 +100,6 @@ export default class YuqueClient extends ElogFromContext {
title: item.title,
})),
});
return updatedDocList;
return docDetailList;
}
}
2 changes: 1 addition & 1 deletion playground/plugin-from-yuque-token/src/YuqueApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class YuqueApi extends ElogBaseContext {
/**
* 获取目录
*/
async getToc() {
async getSortedDocList() {
return this.requestInternal<YuqueCatalog[]>(
`repos/${this.config.login}/${this.config.repo}/toc`,
{
Expand Down
9 changes: 4 additions & 5 deletions playground/plugin-from-yuque-token/src/YuqueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export default class YuqueClient extends ElogFromContext {
async getDocDetailList() {
this.ctx.info('正在获取文档列表,请稍等...');
// 获取目录
const catalogList = await this.api.getToc();
const sortedDocList = await this.api.getSortedDocList();
// 获取文档列表
let yuqueBaseDocList = await this.api.getDocList();
// 根据目录排序文档顺序,处理文档目录
yuqueBaseDocList = catalogList
yuqueBaseDocList = sortedDocList
.filter((item) => {
return item.type === 'DOC';
})
Expand All @@ -33,7 +33,7 @@ export default class YuqueClient extends ElogFromContext {
let catalogPath: DocStructure[] = [];
let parentId = item.parent_uuid;
for (let i = 0; i < item.level; i++) {
const current = catalogList.find((item) => item.uuid === parentId)!;
const current = sortedDocList.find((item) => item.uuid === parentId)!;
parentId = current.parent_uuid;
catalogPath.push({
id: item.slug,
Expand Down Expand Up @@ -70,7 +70,6 @@ export default class YuqueClient extends ElogFromContext {
process.exit();
}
this.ctx.info('待下载数', String(needUpdateDocList.length));
let docDetailList: DocDetail[];
const promise = async (doc: YuqueDoc) => {
this.ctx.info(`下载文档 ${doc._index}/${needUpdateDocList.length} `, doc.title);
let article = await this.api.getDocDetail(doc.slug);
Expand All @@ -88,7 +87,7 @@ export default class YuqueClient extends ElogFromContext {
};
return docDetail;
};
docDetailList = await this.asyncPool(this.config.limit || 3, needUpdateDocList, promise);
const docDetailList = await this.asyncPool(this.config.limit || 3, needUpdateDocList, promise);
// 更新缓存里的文章
this.updateCache(docDetailList, idMap);
this.ctx.info('已下载数', String(needUpdateDocList.length));
Expand Down

0 comments on commit 64cf4c6

Please sign in to comment.