csdnsynchexo
Version:
支持csdn/博客园/掘金/segmentfault/腾讯云加社区等平台一键迁移hexo
40 lines (39 loc) • 1.25 kB
JavaScript
import { Base } from '../base.js';
import { info } from '../../log/index.js';
export class Github extends Base {
headers = {};
articleMap = {};
async getMain() {
const { config } = this;
const ids = [];
let index = 1;
while (true) {
const { data } = await this.axios.get(`https://api.github.com/repos/${config.userId}/${config.repo}/issues?per_page=100&page=${index}`);
if (!data.length) {
break;
}
index++;
for (const item of data) {
if (item.user.login !== config.userId) {
continue;
}
ids.push(item.id);
this.articleMap[item.id] = item;
}
}
info('获取github数据完成');
return ids;
}
async getDetail(id) {
const item = this.articleMap[id];
return {
title: item.title,
date: new Date(item.created_at).toLocaleString('en-US', {
timeZone: 'Asia/Shanghai',
}),
tags: item.labels?.map((x) => x.name) ?? [],
content: item.body,
categories: item.labels?.map((x) => x.name) ?? [],
};
}
}