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

@@ -1,7 +1,10 @@
const parser = require('@/utils/rss-parser');
const config = require('@/config').value;
module.exports = async (ctx) => {
const scheme = ctx.params.https || 'https';
const cdn = config.wordpress.cdnUrl;
const domain = `${scheme}://${ctx.params.domain}`;
const feed = await parser.parseURL(`${domain}/feed/`);
const items = await Promise.all(
@@ -10,9 +13,21 @@ module.exports = async (ctx) => {
if (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 = {
title: item.title,
description: item['content:encoded'],
description: description,
pubDate: item.pubDate,
link: item.link,
author: item.creator,