feat: add wordpress config for http images (#6790)

* wordpress: add cdn for images

* wordpress: use envars to define cdn url

* wordpress: fix english doc

* wordpress: update route

* wordpress: update docs

Co-authored-by: duhd1993 <duhd1993@gmail.com>
This commit is contained in:
Haodong DU
2021-01-26 19:52:26 -05:00
committed by GitHub
parent 23d04743c1
commit fdfbc0658f
5 changed files with 48 additions and 1 deletions

View File

@@ -37,3 +37,8 @@ pageClass: routes
### Article ### Article
<RouteEn author="CitrusIce" example="/phrack" path="/phrack" /> <RouteEn author="CitrusIce" example="/phrack" path="/phrack" />
## WordPress
<Route author="Lonor" example="/blogs/wordpress/lawrence.code.blog" path="/blogs/wordpress/:domain/:https?" :paramsDesc="['WordPress blog domain', 'use https by default. options: `http` or `https`']"/>

View File

@@ -522,3 +522,15 @@ See docs of specified route and `lib/config.js` for detail information.
- Sci-hub for scientific journal routes: - Sci-hub for scientific journal routes:
- `SCIHUB_HOST`: The Sci-hub mirror address that is accssible from your location, default to `https://sci-hub.se`. - `SCIHUB_HOST`: The Sci-hub mirror address that is accssible from your location, default to `https://sci-hub.se`.
- Wordpress:
- `WORDPRESS_CDN`: Proxy http image link with https link. Consider using:
| url | backbone |
| ---------------------------------------- | ------------ |
| https://imageproxy.pimg.tw/resize?url= | akamai |
| https://images.weserv.nl/?url= | cloudflare |
| https://pic1.xuehuaimg.com/proxy/ | cloudflare |
| https://cors.netnr.workers.dev/ | cloudflare |
| https://netnr-proxy.openode.io/ | digitalocean |

View File

@@ -654,3 +654,15 @@ RSSHub 支持使用访问密钥 / 码,白名单和黑名单三种方式进行
- `ZHIHU_COOKIES`: 知乎登录后的 cookie 值. - `ZHIHU_COOKIES`: 知乎登录后的 cookie 值.
1. 可以在知乎网页版的一些请求的请求头中找到,如 `GET /moments` 请求头中的 `cookie` 值. 1. 可以在知乎网页版的一些请求的请求头中找到,如 `GET /moments` 请求头中的 `cookie` 值.
- Wordpress
- `WORDPRESS_CDN`: 用于中转 http 图片链接。可供考虑的服务见下表:
| url | backbone |
| ---------------------------------------- | ------------ |
| <https://imageproxy.pimg.tw/resize?url=> | akamai |
| <https://images.weserv.nl/?url=> | cloudflare |
| <https://pic1.xuehuaimg.com/proxy/> | cloudflare |
| <https://cors.netnr.workers.dev/> | cloudflare |
| <https://netnr-proxy.openode.io/> | digitalocean |

View File

@@ -188,6 +188,9 @@ const calculateValue = () => {
scboy: { scboy: {
token: envs.SCBOY_BBS_TOKEN, token: envs.SCBOY_BBS_TOKEN,
}, },
wordpress: {
cdnUrl: envs.WORDPRESS_CDN,
},
}; };
}; };
calculateValue(); calculateValue();

View File

@@ -1,7 +1,10 @@
const parser = require('@/utils/rss-parser'); const parser = require('@/utils/rss-parser');
const config = require('@/config').value;
module.exports = async (ctx) => { module.exports = async (ctx) => {
const scheme = ctx.params.https || 'https'; const scheme = ctx.params.https || 'https';
const cdn = config.wordpress.cdnUrl;
const domain = `${scheme}://${ctx.params.domain}`; const domain = `${scheme}://${ctx.params.domain}`;
const feed = await parser.parseURL(`${domain}/feed/`); const feed = await parser.parseURL(`${domain}/feed/`);
const items = await Promise.all( const items = await Promise.all(
@@ -10,9 +13,21 @@ module.exports = async (ctx) => {
if (cache) { if (cache) {
return Promise.resolve(JSON.parse(cache)); return Promise.resolve(JSON.parse(cache));
} }
const description =
scheme === 'https' || !cdn
? item['content:encoded']
: item['content:encoded'].replace(/(?<=<img.*src=")(.*)(?=".*\/>)/g, function (match, p) {
if (p[0] === '/') {
return cdn + feed.link + p;
} else if (p.slice(0, 5) === 'http:') {
return cdn + p;
} else {
return p;
}
});
const article = { const article = {
title: item.title, title: item.title,
description: item['content:encoded'], description: description,
pubDate: item.pubDate, pubDate: item.pubDate,
link: item.link, link: item.link,
author: item.creator, author: item.creator,