feat(route): backlinko (#14164)
* feat(route): backlinko * Refactor blog.js to destructure nested properties
This commit is contained in:
parent
78c4977275
commit
3bf9dd28c1
|
|
@ -0,0 +1,44 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const baseUrl = 'https://backlinko.com';
|
||||
const { data: response, url: link } = await got(`${baseUrl}/blog`);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
const nextData = JSON.parse($('#__NEXT_DATA__').text());
|
||||
const {
|
||||
buildId,
|
||||
props: { pageProps },
|
||||
} = nextData;
|
||||
|
||||
const posts = pageProps.posts.nodes.concat(pageProps.backlinkoLockedPosts.nodes).map((post) => ({
|
||||
title: post.title,
|
||||
link: `${baseUrl}/${post.slug}`,
|
||||
pubDate: parseDate(post.modified),
|
||||
author: post.author.node.name,
|
||||
apiUrl: `${baseUrl}/_next/data/${buildId}/${post.slug}.json`,
|
||||
}));
|
||||
|
||||
const items = await Promise.all(
|
||||
posts.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data } = await got(item.apiUrl);
|
||||
const post = data.pageProps.post || data.pageProps.lockedPost;
|
||||
|
||||
item.description = post.content;
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: pageProps.page.seo.title,
|
||||
description: pageProps.page.seo.metaDesc,
|
||||
link,
|
||||
language: 'en',
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/blog': ['TonyRL'],
|
||||
};
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
module.exports = {
|
||||
'backlinko.com': {
|
||||
_name: 'Backlinko',
|
||||
'.': [
|
||||
{
|
||||
title: 'Blog',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#backlinko',
|
||||
source: ['/blog', '/'],
|
||||
target: '/backlinko/blog',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/blog', require('./blog'));
|
||||
};
|
||||
|
|
@ -22,6 +22,12 @@
|
|||
|
||||
<Route author="kt286" example="/archdaily" path="/archdaily" />
|
||||
|
||||
## Backlinko {#backlinko}
|
||||
|
||||
### Blog {#backlinko-blog}
|
||||
|
||||
<Route author="TonyRL" example="/backlinko/blog" path="/backlinko/blog" radar="1" />
|
||||
|
||||
## Benedict Evans {#benedict-evans}
|
||||
|
||||
### Essays {#benedict-evans-essays}
|
||||
|
|
|
|||
Loading…
Reference in New Issue