fear: add dev.to top posts route (#5930)

Co-authored-by: dwemerx <dwemerx>
This commit is contained in:
Dwemer
2020-10-18 16:34:03 +01:00
committed by GitHub
co-authored by dwemerx
parent cf8054103e
commit b9e01258a5
4 changed files with 83 additions and 4 deletions
+16 -4
View File
@@ -10,6 +10,18 @@ pageClass: routes
<RouteEn author="lucasew" path="/curiouscat/user/:name" example="/curiouscat/user/username" :paramsDesc="['name, username that is in the URL']" />
## Dev.to
### Top Posts
<RouteEn author="dwemerx" example="/dev.to/top/month" path="/dev.to/top/:period" :paramsDesc="['period']">
| dev.to weekly top | dev.to monthly top | dev.to yearly top | dev.to top posts of all time |
| ----------------- | ------------------ | ----------------- | ---------------------------- |
| week | month | year | infinity |
</RouteEn>
## Disqus
### Comment
@@ -36,9 +48,10 @@ pageClass: routes
::: tip
Official user RSS:
- RSS: `https://**:instance**/users/**:username**.rss` ([Example](https://pawoo.net/users/pawoo_support.rss))
- Atom: ~~`https://**:instance**/users/**:username**.atom`~~ (Only for pawoo.net, [example](https://pawoo.net/users/pawoo_support.atom))
Official user RSS:
- RSS: `https://**:instance**/users/**:username**.rss` ([Example](https://pawoo.net/users/pawoo_support.rss))
- Atom: ~~`https://**:instance**/users/**:username**.atom`~~ (Only for pawoo.net, [example](https://pawoo.net/users/pawoo_support.atom))
These feed do not include boosts (a.k.a. reblogs). RSSHub provides a feed for user timeline based on the Mastodon API, but to use that, you will need to create application on a Mastodon instance, and configure your RSSHub instance. Check the [Deploy Guide](/en/install/#route-specific-configurations) for route-specific configurations.
@@ -60,7 +73,6 @@ These feed do not include boosts (a.k.a. reblogs). RSSHub provides a feed for us
<RouteEn author="notofoe" example="/mastodon/account_id/mastodon.social/23634/statuses/only_media" path="/mastodon/account/:site/:account_id/statuses/:only_media?" :paramsDesc="['instance address, only domain, no `http://` or `https://` protocol header', 'account id. login your instance, then search for the user profile; the account id is in the url', 'whether only display media content, default to false, any value to true']"/>
## piapro
### User latest works
+12
View File
@@ -286,6 +286,18 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
<Route author="hoilc" example="/bilibili/manga/update/26009" path="/bilibili/manga/update/:comicid" :paramsDesc="['漫画 id, 可在 URL 中找到, 支持带有`mc`前缀']"/>
## Dev.to
### 最高职位
<Route author="dwemerx" example="/dev.to/top/month" path="/dev.to/top/:period" :paramsDesc="['period']">
| 开发到每周最高 | 开发至每月最高 | 开发年度最高 | 开发到有史以来最高职位 |
| -------------- | -------------- | ------------ | ---------------------- |
| week | month | year | infinity |
</Route>
## Disqus
### 评论
+3
View File
@@ -3356,4 +3356,7 @@ router.get('/allnow/column/:id', require('./routes/allnow/column'));
// 证券时报网
router.get('/stcn/news/:id?', require('./routes/stcn/news'));
// dev.to
router.get('/dev.to/top/:period', require('./routes/dev.to/top'));
module.exports = router;
+52
View File
@@ -0,0 +1,52 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const period = ctx.params.period;
const link = `https://dev.to/top/${period}`;
const getHTML = async () => {
const response = await got({
method: 'get',
url: link,
});
return response.data;
};
const html = await ctx.cache.tryGet(link, getHTML);
const posts = [];
const $ = cheerio.load(html);
$('div.crayons-story__body').each(function () {
const post = {};
const author = $('.crayons-story__secondary', this).text().trim().replace(/\s\s+/g, ', ');
const title = $('.crayons-story__title a', this).text().trim();
const link = `https://dev.to${$('.crayons-story__title a', this).attr('href')}`;
const description = $('.crayons-story__tags', this).text().trim().replace(/\s\s+/g, ' ');
const pubDate = new Date($('.time-ago-indicator-initial-placeholder', this).attr('data-seconds') * 1000).toUTCString();
post.author = author;
post.title = title;
post.link = link;
post.description = description;
post.pubDate = pubDate;
posts.push(post);
});
ctx.state.data = {
title: `dev.to top (${period})`,
link,
description: 'Top dev.to posts',
language: 'en-us',
item: posts.map((post) => ({
title: post.title,
description: post.description,
link: post.link,
author: post.author,
pubDate: post.pubDate,
})),
};
};