From c2d5491e1930532c77beff8025d9d9d039ecfb30 Mon Sep 17 00:00:00 2001 From: Enoch Ma Date: Thu, 30 May 2024 21:02:26 +0200 Subject: [PATCH] fix(route/twreporter): Change to ofetch and other fix (#15770) * twreporter - fix & ofetch * remove comment --- lib/routes/twreporter/category.ts | 4 ++-- lib/routes/twreporter/fetch-article.ts | 16 +++++++++++----- lib/routes/twreporter/newest.ts | 4 ++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/routes/twreporter/category.ts b/lib/routes/twreporter/category.ts index 5bf0534576d15..8619344a2d1e3 100644 --- a/lib/routes/twreporter/category.ts +++ b/lib/routes/twreporter/category.ts @@ -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; diff --git a/lib/routes/twreporter/fetch-article.ts b/lib/routes/twreporter/fetch-article.ts index 035fbbf85effc..28713322fe70f 100644 --- a/lib/routes/twreporter/fetch-article.ts +++ b/lib/routes/twreporter/fetch-article.ts @@ -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 = `
${quote.quote}

${quote.quoteBy}

`; + + break; + } default: block = `${content}
`; } diff --git a/lib/routes/twreporter/newest.ts b/lib/routes/twreporter/newest.ts index a71354ba8de6f..017ed06054d9b 100644 --- a/lib/routes/twreporter/newest.ts +++ b/lib/routes/twreporter/newest.ts @@ -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) => {