fix(route/twreporter): Change to ofetch and other fix (#15770)

* twreporter - fix & ofetch

* remove comment
This commit is contained in:
Enoch Ma
2024-05-31 03:02:26 +08:00
committed by GitHub
parent db0ae9d3fa
commit c2d5491e19
3 changed files with 15 additions and 9 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import fetch from './fetch-article';
@@ -31,7 +31,7 @@ export const route: Route = {
async function handler(ctx) {
const category = ctx.req.param('category');
const url = `https://go-api.twreporter.org/v2/index_page`;
const res = await got(url).json();
const res = await ofetch(url);
const list = res.data[category];
let name = list[0].category_set[0].category.name;
+11 -5
View File
@@ -1,15 +1,15 @@
import { getCurrentPath } from '@/utils/helpers';
const __dirname = getCurrentPath(import.meta.url);
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import { parseDate } from '@/utils/parse-date';
import { art } from '@/utils/render';
import path from 'node:path';
export default async function fetch(slug: string) {
const url = `https://go-api.twreporter.org/v2/posts/${slug}?full=true`;
const res = await got(url);
const post = res.data.data;
const res = await ofetch(url);
const post = res.data;
const time = post.published_date;
// For `writers`
@@ -33,9 +33,9 @@ export default async function fetch(slug: string) {
authors += ';' + photographers;
}
const bannerImage = post.og_image.resized_targets.desktop.url;
const bannerImage = post.hero_image.resized_targets.desktop.url;
const caption = post.leading_image_description;
const bannerDescription = post.og_image.description;
const bannerDescription = post.hero_image.description;
const ogDescription = post.og_description;
const banner = art(path.join(__dirname, 'templates/image.art'), { image: bannerImage, description: bannerDescription, caption });
@@ -77,6 +77,12 @@ export default async function fetch(slug: string) {
break;
}
case 'quoteby': {
const quote = content[0];
block = `<blockquote>${quote.quote}</blockquote><p>${quote.quoteBy}</p>`;
break;
}
default:
block = `${content}<br>`;
}
+2 -2
View File
@@ -1,6 +1,6 @@
import { Route } from '@/types';
import cache from '@/utils/cache';
import got from '@/utils/got';
import ofetch from '@/utils/ofetch';
import fetch from './fetch-article';
@@ -31,7 +31,7 @@ export const route: Route = {
async function handler() {
const base = `https://www.twreporter.org`;
const url = `https://go-api.twreporter.org/v2/index_page`;
const res = await got(url).json();
const res = await ofetch(url);
const list = res.data.latest_section;
const out = await Promise.all(
list.map((item) => {