feat(route): add Surfshark Blog (#13367)
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { category } = ctx.params;
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 15;
|
||||
|
||||
const rootUrl = 'https://surfshark.com';
|
||||
const currentUrl = new URL(`blog${category ? `/${category}` : ''}`, rootUrl).href;
|
||||
|
||||
const { data: response } = await got(currentUrl);
|
||||
|
||||
const $ = cheerio.load(response);
|
||||
|
||||
let items = $('div.article-info')
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('a');
|
||||
|
||||
return {
|
||||
title: a.prop('title'),
|
||||
link: a.prop('href'),
|
||||
author: item.find('div.author, div.name').text().split('in')[0].trim(),
|
||||
category: item
|
||||
.find('div.author, div.name')
|
||||
.find('a')
|
||||
.toArray()
|
||||
.map((c) => $(c).text()),
|
||||
pubDate: parseDate(item.find('div.date, div.time').text().split('·')[0].trim(), 'YYYY, MMMM D'),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: detailResponse } = await got(item.link);
|
||||
|
||||
const content = cheerio.load(detailResponse);
|
||||
|
||||
content('div.post-main-img').each(function () {
|
||||
const image = content(this).find('img');
|
||||
|
||||
content(this).replaceWith(
|
||||
art(path.join(__dirname, 'templates/description.art'), {
|
||||
image: {
|
||||
src: image
|
||||
.prop('srcset')
|
||||
.match(/(https?:.*?\.\w+\s)/g)
|
||||
.pop()
|
||||
.trim(),
|
||||
alt: image.prop('alt'),
|
||||
},
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
item.title = content('div.blog-post-title').text();
|
||||
item.description = content('div.post-content').html();
|
||||
item.author = content('meta[name="author"]').prop('content');
|
||||
item.category = content('div.name')
|
||||
.find('a')
|
||||
.toArray()
|
||||
.map((c) => content(c).text());
|
||||
item.pubDate = parseDate(content('meta[property="article:published_time"]').prop('content'));
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const icon = new URL($('link[rel="apple-touch-icon"]').prop('href'), rootUrl).href;
|
||||
|
||||
ctx.state.data = {
|
||||
item: items,
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
description: $('meta[property="og:description"]').prop('content'),
|
||||
language: $('html').prop('lang'),
|
||||
image: $('meta[property="og:image"]').prop('content'),
|
||||
icon,
|
||||
logo: icon,
|
||||
subtitle: $('meta[property="og:title"]').prop('content'),
|
||||
author: $('meta[property="og:site_name"]').prop('content'),
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/blog/:category?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,90 @@
|
||||
module.exports = {
|
||||
'surfshark.com': {
|
||||
_name: 'Surfshark',
|
||||
'.': [
|
||||
{
|
||||
title: 'Blog',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/blog/:category*'],
|
||||
target: (params, url) => {
|
||||
url = new URL(url);
|
||||
const path = params.category ?? url.href.match(/\/blog\/(.*?)/)[1];
|
||||
|
||||
return `/surfshark/blog${path ? `/${path}` : ''}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Blog - Cybersecurity',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/cybersecurity'],
|
||||
target: '/surfshark/blog/cybersecurity',
|
||||
},
|
||||
{
|
||||
title: 'Blog - All things VPN',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/all-things-vpn'],
|
||||
target: '/surfshark/blog/all-things-vpn',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Internet censorship',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/internet-censorship'],
|
||||
target: '/surfshark/blog/internet-censorship',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Entertainment',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/entertainment'],
|
||||
target: '/surfshark/blog/entertainment',
|
||||
},
|
||||
{
|
||||
title: 'Blog - News',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/news'],
|
||||
target: '/surfshark/blog/news',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Internet Security',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/cybersecurity/internet-security', '/blog/cybersecurity'],
|
||||
target: '/surfshark/blog/cybersecurity/internet-security',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Mobile Security',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/cybersecurity/mobile-security', '/blog/cybersecurity'],
|
||||
target: '/surfshark/blog/cybersecurity/mobile-security',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Identity Protection',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/cybersecurity/identity-protection', '/blog/cybersecurity'],
|
||||
target: '/surfshark/blog/cybersecurity/identity-protection',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Phishing',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/cybersecurity/phishing', '/blog/cybersecurity'],
|
||||
target: '/surfshark/blog/cybersecurity/phishing',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Must-knows',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/all-things-vpn/must-knows', '/blog/all-things-vpn'],
|
||||
target: '/surfshark/blog/all-things-vpn/must-knows',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Technology',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/all-things-vpn/technology', '/blog/all-things-vpn'],
|
||||
target: '/surfshark/blog/all-things-vpn/technology',
|
||||
},
|
||||
{
|
||||
title: 'Blog - Tips & Advice',
|
||||
docs: 'https://docs.rsshub.app/routes/blog#surfshark-blog',
|
||||
source: ['/blog/all-things-vpn/tips-and-advice', '/blog/all-things-vpn'],
|
||||
target: '/surfshark/blog/all-things-vpn/tips-and-advice',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/blog/:category*', require('./blog'));
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
{{ if image }}
|
||||
<figure>
|
||||
<img src="{{ image.src }}" alt="{{ image.alt }}">
|
||||
</figure>
|
||||
{{ /if }}
|
||||
@@ -264,6 +264,30 @@ Limit the number of entries to be retrieved by adding `?limit=x` to the end of t
|
||||
|
||||
<Route author="chazeon" example="/stratechery" path="/stratechery" />
|
||||
|
||||
## Surfshark {#surfshark}
|
||||
|
||||
### Blog {#surfshark-blog}
|
||||
|
||||
<Route author="nczitzk" example="/surfshark/blog" path="/surfshark/blog/:category?" paramsDesc={['Category, can be found in URL ,see below, All by default']} radar="1" rssbud="1">
|
||||
|
||||
| Home | Cybersecurity | All things VPN | Internet censorship | Entertainment | News |
|
||||
| ---- | ------------- | -------------- | ------------------- | ------------- | ---- |
|
||||
| | cybersecurity | all-things-vpn | internet-censorship | entertainment | news |
|
||||
|
||||
#### Cybersecurity {#surfshark-blog-cybersecurity}
|
||||
|
||||
| Internet Security | Mobile Security | Identity Protection | Phishing |
|
||||
| ------------------------------- | ----------------------------- | --------------------------------- | ---------------------- |
|
||||
| cybersecurity/internet-security | cybersecurity/mobile-security | cybersecurity/identity-protection | cybersecurity/phishing |
|
||||
|
||||
#### All things VPN {#surfshark-blog-all-things-vpn}
|
||||
|
||||
| Must-knows | Technology | Tips & Advice |
|
||||
| -------------- | -------------- | ------------------- |
|
||||
| vpn/must-knows | vpn/technology | vpn/tips-and-advice |
|
||||
|
||||
</Route>
|
||||
|
||||
## Uber 优步 {#uber-you-bu}
|
||||
|
||||
### Engineering {#uber-you-bu-engineering}
|
||||
|
||||
Reference in New Issue
Block a user