Skip to content

Commit

Permalink
fix(route/twreporter): Change to ofetch and other fix (DIYgod#15770)
Browse files Browse the repository at this point in the history
* twreporter - fix & ofetch

* remove comment
  • Loading branch information
emdoe committed May 30, 2024
1 parent db0ae9d commit c2d5491
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/routes/twreporter/category.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions lib/routes/twreporter/fetch-article.ts
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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 });

Expand Down Expand Up @@ -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>`;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/twreporter/newest.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit c2d5491

Please sign in to comment.