UNPKG

csdnsynchexo

Version:

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

50 lines (49 loc) 2.19 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 { catchCount } from '../../decorator/index.js'; import { Sitdown } from 'sitdown'; const sitdown = new Sitdown({ keepFilter: ['style'], codeBlockStyle: 'fenced', bulletListMarker: '-', hr: '---', }); export class JuejinBook extends Base { headers = { // 'user-agent': // 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36', // cookie: this.config.cookie, // 'content-type': 'application/json' }; bookTitle = ''; async getMain() { const { data, config } = await this.axios.post('https://api.juejin.cn/booklet_api/v1/booklet/get', { booklet_id: `${this.config.userId}`, }); this.bookTitle = data?.data?.booklet?.base_info?.title; return data?.data?.sections.map((x) => x.section_id); } async getDetail(id) { const { data } = await this.axios.post('https://api.juejin.cn/booklet_api/v1/section/get', { section_id: id, }); return { title: data?.data?.section?.title, tags: this.bookTitle ? [this.bookTitle] : [], content: data?.data?.section?.markdown_show || sitdown.HTMLToMD(data?.data?.section?.content ?? ''), categories: this.bookTitle ? [this.bookTitle] : [], date: new Date(Number(data?.data?.section?.ctime) * 1000).toLocaleString('en-US', { timeZone: 'Asia/Shanghai', }), }; } } __decorate([ catchCount() ], JuejinBook.prototype, "getDetail", null);