UNPKG

csdnsynchexo

Version:

支持csdn/博客园/掘金/segmentfault/腾讯云加社区等平台一键迁移hexo

68 lines (67 loc) 2.43 kB
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 { Base } from '../base.js'; import { load } from 'cheerio'; import { Sitdown } from 'sitdown'; import { catchCount } from '../../decorator/index.js'; const sitdown = new Sitdown({ keepFilter: ['style'], codeBlockStyle: 'fenced', bulletListMarker: '-', hr: '---', }); export class Bokeyuan extends Base { headers = {}; async getDetail(url) { const { data: html } = await this.axios.get( // `https://www.cnblogs.com/${this.config.userId}/p/${id}.html` url); const $ = load(html); const content = sitdown.HTMLToMD($('#cnblogs_post_body').html()); const title = $('.postTitle .postTitle2 span').text(); const date = $('#post-date').text(); const categories = []; $('#BlogPostCategory a').each(function () { categories.push($(this).text()); }); const tags = []; $('#EntryTag a').each(function () { tags.push($(this).text()); }); return { title, tags, content, categories, date, }; } async getMain() { let page = 1; const urls = []; while (true) { const { data: html } = await this.axios.get(`https://www.cnblogs.com/${this.config.userId}/default.html?page=${page++}`); const $ = load(html); const list = $('.postTitle .postTitle2'); if (list?.length > 0) { list.each(function () { const url = $(this).attr('href'); if (url) { urls.push(url); } }); } else { break; } } return urls; } } __decorate([ catchCount() ], Bokeyuan.prototype, "getDetail", null);