mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-08 14:07:54 +08:00
feat: add Jandan articles (#6774)
* jandan: new route article * jandan: add docs * [CodeFactor] Apply fixes [ci skip] [skip ci] * jandan: fix * jandan: codefactor fix Co-authored-by: duhd1993 <duhd1993@gmail.com> Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
@@ -336,6 +336,10 @@ R18 显示
|
|||||||
| ------ | ---------- | ---------- |
|
| ------ | ---------- | ---------- |
|
||||||
| pic | top | top-4h |
|
| pic | top | top-4h |
|
||||||
|
|
||||||
|
### 首页
|
||||||
|
|
||||||
|
<Route author="lonelykid" example="/jandan/article" path="/jandan/article"/>
|
||||||
|
|
||||||
## 绝对领域
|
## 绝对领域
|
||||||
|
|
||||||
### 图集文章
|
### 图集文章
|
||||||
|
|||||||
@@ -209,6 +209,7 @@ router.get('/douban/celebrity/:id/:sort?', require('./routes/douban/celebrity.js
|
|||||||
router.get('/plainlaw/archives', require('./routes/plainlaw/archives.js'));
|
router.get('/plainlaw/archives', require('./routes/plainlaw/archives.js'));
|
||||||
|
|
||||||
// 煎蛋
|
// 煎蛋
|
||||||
|
router.get('/jandan/article', require('./routes/jandan/article'));
|
||||||
router.get('/jandan/:sub_model', require('./routes/jandan/pic'));
|
router.get('/jandan/:sub_model', require('./routes/jandan/pic'));
|
||||||
|
|
||||||
// 喷嚏
|
// 喷嚏
|
||||||
|
|||||||
61
lib/routes/jandan/article.js
Normal file
61
lib/routes/jandan/article.js
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
const response = await got({
|
||||||
|
method: 'get',
|
||||||
|
url: 'http://jandan.net/',
|
||||||
|
});
|
||||||
|
const $ = cheerio.load(response.data);
|
||||||
|
const list = $('div.list-post').get();
|
||||||
|
|
||||||
|
const items = await Promise.all(
|
||||||
|
list.map(async (li) => {
|
||||||
|
const $ = cheerio.load(li);
|
||||||
|
const link = $('a').first().attr('href');
|
||||||
|
const title = $('a')[1].children[0].data;
|
||||||
|
const summary = $('div.indexs').clone().children().remove().end().text().trim();
|
||||||
|
const author = $('div.time_s > a').first().text();
|
||||||
|
let imgUrl = 'http:' + ($('img').attr('src') || $('img').attr('data-original'));
|
||||||
|
if (imgUrl.slice(-7,) === "!square") {
|
||||||
|
imgUrl = imgUrl.slice(0, -7);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [fullText, time] = await ctx.cache.tryGet(link, async () => {
|
||||||
|
const res = await got.get(link);
|
||||||
|
const $ = cheerio.load(res.data);
|
||||||
|
const [, year, month, day, hour, minute] = $('div.time_s')
|
||||||
|
.text()
|
||||||
|
.match(/.+@\s+(\d+)\.(\d+)\.(\d+)\s,\s(\d+):(\d+)/);
|
||||||
|
const time = new Date(`${year}-${month}-${day}T${hour}:${minute}:00+0800`).toUTCString();
|
||||||
|
|
||||||
|
const content = $('.f.post').first();
|
||||||
|
content.find('h1').prevAll().remove().end().remove();
|
||||||
|
content.find('div').nextAll().remove().end().remove();
|
||||||
|
content.contents().each(function() {
|
||||||
|
if (this.nodeType === 8) {
|
||||||
|
$(this).remove();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const text = content.html().trim();
|
||||||
|
|
||||||
|
return [text, time];
|
||||||
|
});
|
||||||
|
const description = `<blockquote><p>${summary}</p></blockquote><img src="${imgUrl}">${fullText}`;
|
||||||
|
|
||||||
|
const single = {
|
||||||
|
title: title,
|
||||||
|
description: description,
|
||||||
|
link: link,
|
||||||
|
pubDate: time,
|
||||||
|
author: author
|
||||||
|
};
|
||||||
|
return Promise.resolve(single);
|
||||||
|
}));
|
||||||
|
ctx.state.data = {
|
||||||
|
title: `煎蛋 - 首页`,
|
||||||
|
link: `http://jandan.net/`,
|
||||||
|
description: '煎蛋 - 地球上没有新鲜事',
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user