feat(route): backlinko (#14164)

* feat(route): backlinko

* Refactor blog.js to destructure nested properties
This commit is contained in:
Tony 2024-01-02 17:37:59 +00:00 committed by GitHub
parent 78c4977275
commit 3bf9dd28c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 0 deletions

44
lib/v2/backlinko/blog.js Normal file
View File

@ -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,
};
};

View File

@ -0,0 +1,3 @@
module.exports = {
'/blog': ['TonyRL'],
};

13
lib/v2/backlinko/radar.js Normal file
View File

@ -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',
},
],
},
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/blog', require('./blog'));
};

View File

@ -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}