csdnsynchexo
Version:
支持csdn/博客园/掘金/segmentfault/腾讯云加社区等平台一键迁移hexo
65 lines (64 loc) • 2.52 kB
JavaScript
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { catchCount } from '../../decorator/index.js';
import { Base } from '../base.js';
import { load } from 'cheerio';
import { Sitdown } from 'sitdown';
const sitdown = new Sitdown({
keepFilter: ['style'],
codeBlockStyle: 'fenced',
bulletListMarker: '-',
hr: '---',
});
export class Tengxunyun extends Base {
headers = {};
articleMap = new Map();
async getMain() {
let page = 1;
let ids = [];
while (true) {
const { data: res } = await this.axios.post('https://cloud.tencent.com/developer/services/ajax/user-center?action=FetchUserArticles', {
action: 'FetchUserArticles',
payload: {
pageNumber: page++,
pageSize: 20,
uid: this.config.userId,
},
});
if (res.code === 0 && res.data?.list.length > 0) {
res.data.list.forEach((x) => {
ids.push(x.articleId);
this.articleMap.set(x.articleId, {
tags: x.tags.map((xx) => xx.name),
title: x.title,
date: new Date(x.writeTime * 1000).toLocaleDateString(),
categories: [x.column?.name],
});
});
}
else if (res.data.list.length === 0) {
break;
}
}
return ids;
}
async getDetail(id) {
const { data: html } = await this.axios.get(` https://cloud.tencent.com/developer/article/${id} `);
const $ = load(html, {
// decodeEntities: true,
});
const content = sitdown.HTMLToMD($('.com-markdown-collpase').html());
const item = this.articleMap.get(id);
return {
content,
...item,
};
}
}
__decorate([
catchCount()
], Tengxunyun.prototype, "getDetail", null);