add phrack magazine route

This commit is contained in:
user 2021-01-12 15:28:16 +08:00
parent 070da5f153
commit 35cf4e3a22
3 changed files with 47 additions and 0 deletions

View File

@ -80,6 +80,11 @@ pageClass: routes
<Route author="Maecenas" example="/blogs/paulgraham" path="/blogs/paulgraham"/>
## Phrack Magazine
### 文章
<Route author="CitrusIce" example="/phrack" path="/phrack" />
## WordPress
<Route author="Lonor" example="/blogs/wordpress/lawrence.code.blog" path="/blogs/wordpress/:domain/:https?" :paramsDesc="['WordPress 博客域名', '默认 https 协议。填写 `http`或`https`']"/>

View File

@ -3861,4 +3861,7 @@ router.get('/booth.pm/shop/:subdomain', require('./routes/booth-pm/shop'));
// Minecraft feed the beast
router.get('/feed-the-beast/modpack/:modpackEntry', require('./routes/feed-the-beast/modpack'));
// Phrack Magazine
router.get('/phrack', require('./routes/phrack/index'));
module.exports = router;

View File

@ -0,0 +1,39 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
module.exports = async (ctx) => {
const response = await got({
method: 'get',
url: 'http://www.phrack.org/',
});
const data = response.data;
let $ = cheerio.load(data);
const a = $('a[title="Paper Feed"]');
const url = 'http://www.phrack.org/' + a.attr('href');
const feed_data = await ctx.cache.tryGet(url, async () => {
const result = await got.get(url);
return result.data;
});
$ = cheerio.load(feed_data); // 使用 cheerio 加载返回的 HTML
ctx.state.data = {
title: 'phrack', // 项目的标题
link: 'http://www.phrack.org/', // 指向项目的链接
description: 'phrack magazine', // 描述项目
allowEmpty: false, // 默认 false设为 true 可以允许 item 为空
item: [
// 其中一篇文章或一项内容
{
title: $('div[id="article"]').text(), // 文章标题
author: '', // 文章作者
category: '', // 文章分类
// category: [''], // 多个分类
description: $('div[class="around"]').children().first().next().children('pre').text(), // 文章摘要或全文
pubDate: '', // 文章发布时间
link: url, // 指向文章的链接
},
],
};
};